braintools.init.param

Contents

braintools.init.param#

braintools.init.param(init, sizes, batch_size=None, allow_none=True, allow_scalar=True, **param_kwargs)#

Initialize parameters.

Parameters:
  • init (Callable | Array | ndarray | bool | number | bool | int | float | complex | Quantity | State | Param) –

    The initialization of the parameter.

    • If it is None, the created parameter will be None.

    • If it is a callable function \(f\), then f(size) will be returned.

    • If it is an instance of Initialization, then init(size) will be returned.

    • If it is a tensor, then this function checks whether tensor.shape is broadcast-compatible with the given size.

  • sizes (int | Sequence[int]) – The shape of the parameter.

  • batch_size (int | None) – If given, a leading batch axis of this length is prepended (arrays are broadcast across it; an array whose leading dimension already equals batch_size is passed through unchanged).

  • allow_none (bool) – Whether to allow the parameter to be None.

  • allow_scalar (bool) – Whether to allow the parameter to be a scalar value.

  • **param_kwargs – Additional keyword arguments passed to the initialization callable.

Returns:

param – The initialized parameter. Scalars (when allow_scalar) and None (when allow_none) are returned as-is; State/Param inputs are returned with their value updated; everything else is returned as an array or brainunit.Quantity.

Return type:

array, brainunit.Quantity, float, int, brainstate.State, brainstate.nn.Param, or None

See also

Initialization