Localmodel module
- class nnodely.layers.localmodel.LocalModel(input_function: Callable | None = None, output_function: Callable | None = None, *, pass_indexes: bool = False)[source]
Represents a Local Model relation in the neural network model.
- Parameters:
input_function (Callable, optional) – A callable function to process the inputs.
output_function (Callable, optional) – A callable function to process the outputs.
pass_indexes (bool, optional) – A boolean indicating whether to pass indexes to the functions. Default is False.
- relation_name
The name of the relation.
- Type:
str
- pass_indexes
A boolean indicating whether to pass indexes to the functions.
- Type:
bool
- input_function
The function to process the inputs.
- Type:
Callable
- output_function
The function to process the outputs.
- Type:
Callable
Examples
Basic usage:
x = Input('x') activation = Fuzzify(2, [0, 1], functions='Triangular')(x.last()) loc = LocalModel(input_function=Fir()) out = Output('out', loc(x.tw(1), activation))
Passing a custom function:
def myFun(in1, p1, p2): return p1 * in1 + p2 x = Input('x') activation = Fuzzify(2, [0, 1], functions='Triangular')(x.last()) loc = LocalModel( input_function=lambda: ParamFun(myFun), output_function=lambda: Fir )(x.last(), activation) out = Output('out', loc)
Custom function with multiple activations:
def myFun(in1, p1, p2): return p1 * in1 + p2 x = Input('x') F = Input('F') activationA = Fuzzify(2, [0, 1], functions='Triangular')(x.tw(1)) activationB = Fuzzify(2, [0, 1], functions='Triangular')(F.tw(1)) loc = LocalModel( input_function=lambda: ParamFun(myFun), output_function=Fir(3) )(x.tw(1), (activationA, activationB)) out = Output('out', loc)
For more examples of how to use the local model module, please refer to the LocalModel tutorial.