Parameter module

The Parameter module represents the learnable quantities of the model and explicitly indicate which parts of the architecture are estimated from data.

Each parameter:

  • Has a unique name

  • Has a defined dimensionality

  • Can be associated with temporal windows

This ensures unambiguous reference, even in large and structured models.

Parameters can be defined over time to capture dynamic effects. Their initialization is considered an integral part of the modeling process and is handled by the Initializer module.

In addition to standard random initialization, nnodely provides structured initialization methods, such as smooth interpolation or decaying profiles. These methods allow prior physical knowledge to be embedded directly into the learnable representation.

class nnodely.layers.parameter.Constant(name: str, values: list | float | int | ndarray, *, tw: float | int | None = None, sw: int | None = None)[source]

Represents a constant value in the neural network model.

Parameters:
  • name (str) – The name of the constant.

  • values (list, float, int, or np.ndarray) – The values of the constant.

  • tw (float or int, optional) – The time window for the constant. Default is None.

  • sw (int, optional) – The sample window for the constant. Default is None.

name

The name of the constant.

Type:

str

dim

A dictionary containing the dimensions of the constant.

Type:

dict

json

A dictionary containing the configuration of the constant.

Type:

dict

Examples

Passing a custom scalar value -> g.dim = {‘dim’: 1}:

g = Constant('gravity', values=9.81)

Passing a custom vector value -> n.dim = {‘dim’: 4}:

n = Constant('numbers', values=[1, 2, 3, 4])

Passing a custom vector value with single sample window -> n.dim = {‘dim’: 4, ‘sw’: 1}:

n = Constant('numbers', values=[[1, 2, 3, 4]])

Passing a custom vector value with double sample window -> n.dim = {‘dim’: 4, ‘sw’: 2}:

n = Constant('numbers', values=[[2, 3, 4], [1, 2, 3]])

Passing a custom vector value with double sample window -> n.dim = {‘dim’: 4, ‘sw’: 2}. If the value of the sw is different from the dimension of shape[0] an error will be raised.

n = Constant('numbers', sw=2, values=[[2, 3, 4], [1, 2, 3]])

Passing a custom vector value with time window -> n.dim = {‘dim’: 4, ‘tw’: 4}. In this case the sampling time must be 0.5; otherwise, an error will be raised. If the Constant has a time dimension, the input must have len(shape) == 2.

n = Constant('numbers', tw=4, values=[[2, 3, 4], [1, 2, 3]])
class nnodely.layers.parameter.SampleTime[source]

Represents a constant value that is equal to the sample time.

name

The name of the constant.

Type:

str

dim

A dictionary containing the dimensions of the constant.

Type:

dict

json

A dictionary containing the configuration of the constant.

Type:

dict

Example

dt = SampleTime()
class nnodely.layers.parameter.Parameter(name: str, dimensions: int | list | tuple | None = None, *, tw: float | int | None = None, sw: int | None = None, values: list | float | int | ndarray | None = None, init: Callable | str | None = None, init_params: dict | None = None)[source]

Represents a trainable parameter in the neural network model.

Notes

Note

You can find some initialization functions for the ‘init’ and ‘init_params’ parameters inside the initializer module.

Parameters:
  • name (str) – The name of the parameter.

  • dimensions (int, list, tuple, or None, optional) – The dimensions of the parameter. Default is None.

  • tw (float or int, optional) – The time window for the parameter. Default is None.

  • sw (int, optional) – The sample window for the parameter. Default is None.

  • values (list, float, int, np.ndarray, or None, optional) – The values by which initialize the parameter. Default is None.

  • init (Callable, optional) – A callable for initializing the parameter values. Default is None.

  • init_params (dict, optional) – A dictionary of parameters for the initializer. Default is None.

name

The name of the parameter.

Type:

str

dim

A dictionary containing the dimensions of the parameter.

Type:

dict

json

A dictionary containing the configuration of the parameter.

Type:

dict

Examples

Basic usage:

k = Parameter('k', dimensions=3, tw=4)

Initialize a parameter with values:

x = Input('x')
gravity = Parameter('g', dimensions=(4,1), values=[[[1],[2],[3],[4]]])
out = Output('out', Linear(W=gravity)(x.sw(3)))

Initialize a parameter with a function:

x = Input('x').last()
p = Parameter('param', dimensions=1, sw=1, init=init_constant, init_params={'value':1})
relation = Fir(parameter=p)(x)

For more examples of how to use the parameter module, please refer to the relative tutorial.