revrand.basis_functions.Basis¶
-
class
revrand.basis_functions.
Basis
(regularizer=None)¶ The base Basis class.
To make other basis classes, make sure they are subclasses of this class to enable concatenation and operation with the machine learning algorithms.
Parameters: regularizer (None, Parameter, optional) – The (initial) value of the regularizer/prior variance to apply to the regression weights of this basis function. The Parameter object must have a scalar value. If it is not set, it will take on a default value of Parameter(gamma(1.), Positive())
.Example
Basis concatentation works as follows if you subclass this class:
>>> base = MyBasis1(properties1) + MyBasis2(properties2)
-
__init__
(regularizer=None)¶ Construct this an instance of this class.
This is also a good place to set non-learnable properties, and bounded Parameter types. An example Basis class with parameters may be
Example
>>> def __init__(self, ... property, ... param=Parameter(1, Bound()), ... regularizer=Parameter(gamma(1.), Positive()) ... ): ... ... self.property = property ... self._params = param_init ... super().__init__(regularizer)
All the
params
property does is inform algorithms of the intitial value and any bounds this basis object has, or it can be used as a default value. This will need to correspond to any parameters input into thetransform
andgrad
methods, where it can be used as the default value. All basis class objects MUST have aparams
property, which is either:- one Parameter object for an optimisable parameter, see btypes.py.
Parameter objects with
None
values are interpreted as having no parameters. - a list of
Parameter
objects, one for each optimisable parameter.
Also, all basis classes can have a way of setting the
self.regularizer
property, since this informs the regression algorithms of the (initial) values of the weights regularizer corresponding to this basis. If it is not set, it will take on a default value ofParameter(gamma(1.), Positive())
.- one Parameter object for an optimisable parameter, see btypes.py.
Parameter objects with
Methods
__init__
([regularizer])Construct this an instance of this class. get_dim
(X)Get the output dimensionality of this basis. grad
(X)Return the gradient of the basis function for each parameter. params_values
()Get a list of the Parameter
values if they have a value.regularizer_diagonal
(X[, regularizer])Get the diagonal of the prior variance on the weights (regularizer). transform
(X)Return the basis function applied to X. Attributes
params
Get this basis’ Parameter types. regularizer
Get the Parameter
value of this basis’ regularizer.-