MappedInitialiser
#
- class hypercoil.init.base.MappedInitialiser(mapper: Type[MappedParameter] | None = None)[source]#
Parameter initialiser base class that also admits an optional parameter map.
This is useful for combining initialisation and re-parameterisation into a single step. The supplied parameter map should not be an instance but a class. If no map is supplied, the initialiser is applied as normal.
This class must be subclassed to be used. Subclasses must implement the
_init
method, which takes a desired output shape (shape
) and a random number generator key (key
) and returns a tensor of the requested shape.Warning
To use an initialiser, do not instantiate it directly, but instead use the
init
method of the module class that uses it. This will apply the initialiser to the model parameter specified bywhere
.Note
The initialiser is first used to initialise the requested parameter, and the mapping function is thereafter applied to the resulting tensor. If the initialisation produces out-of-domain values for the mapping function, the tensor that is ultimately instantiated might not reflect the specifications of the initialiser, as the mapping function will automatically apply any out-of-domain handlers.
Note
Any extra keyword arguments to the
init
method are passed to the mapping function when it is applied.- Attributes:
- mapper
Methods
init
(model, *[, mapper, where])Initialise a parameter using the specified initialiser and mapper.