EquationLearner module
- class nnodely.layers.equationlearner.EquationLearner(functions: list, *, linear_in: Linear | None = None, linear_out: Linear | None = None)[source]
Represents a nnodely implementation of the Task-Parametrized Equation Learner block.
See also
Task-Parametrized Equation Learner official paper: Equation Learner
- Parameters:
functions (list) – A list of callable functions to be used as activation functions.
linear_in (Linear, optional) – A Linear layer to process the input before applying the activation functions. If not provided a random initialized linear layer will be used instead.
linear_out (Linear, optional) – A Linear layer to process the output after applying the activation functions. Can be omitted.
- relation_name
The name of the relation.
- Type:
str
- functions
The list of activation functions.
- Type:
list
- func_parameters
A dictionary mapping function indices to the number of parameters they require.
- Type:
dict
- n_activations
The total number of activation functions.
- Type:
int
Examples
Basic usage:
x = Input('x') equation_learner = EquationLearner(functions=[Tan, Sin, Cos]) out = Output('out', equation_learner(x.last()))
Passing a linear layer:
x = Input('x') linear_layer = Linear( output_dimension=3, W_init=init_constant, W_init_params={'value': 0} ) equation_learner = EquationLearner( functions=[Tan, Sin, Cos], linear_in=linear_layer ) out = Output('out', equation_learner(x.last()))
Passing a custom parametric function and multiple inputs:
x = Input('x') F = Input('F') def myFun(K1, p1): return K1 * p1 K = Parameter('k', dimensions=1, sw=1, values=[[2.0]]) parfun = ParamFun(myFun, parameters=[K]) equation_learner = EquationLearner([parfun]) out = Output('out', equation_learner((x.last(), F.last())))
For more examples of how to use the equation learner module, please refer to the EquationLearner tutorial.