Model-level composition
Model-level composition deals with independently defined sub-models and their interactions. Sub-models are logical groups of output streams that can be added, removed, connected, or frozen independently. Use the Composer API to manage these operations and to prepare the whole definition for neuralization.
Key Composer operators:
addModel / removeModel : register and unregister named sub-models. See
addModel()andremoveModel().addConnect / addClosedLoop / removeConnection : connect an output stream of one model to an input of another (or the same) model; create closed-loop feedback between streams and inputs. See
addConnect(),addClosedLoop(), andremoveConnection().neuralizeModel : finalize the model definition and translate it into a trainable neural representation (builds time windows, slices, and internal tensors required for training/inference). See
neuralizeModel().
- nnodely.operators.composer.Composer.addModel(self, name: str, stream_list: list | Output) None
Adds a new model with the given name along with a list of Outputs.
- Parameters:
name (str) – The name of the model.
stream_list (list of Stream) – The list of Outputs stream in the model.
Example
model = Modely() x = Input('x') out = Output('out', Fir(x.last())) model.addModel('example_model', [out])
- nnodely.operators.composer.Composer.removeModel(self, name_list: list | str) None
Removes models with the given list of names.
- Parameters:
name_list (list of str) – The list of model names to remove.
Example
model.removeModel(['sub_model1', 'sub_model2'])
- nnodely.operators.composer.Composer.addConnect(self, stream_out: str | Output | Stream, input_in: str | Input, *, local: bool = False) None
Adds a connection from a relation stream to an input.
- Parameters:
Examples
model = Modely() x = Input('x') y = Input('y') relation = Fir(x.last()) model.addConnect(relation, y)
- nnodely.operators.composer.Composer.addClosedLoop(self, stream_out: str | Output | Stream, input_in: str | Input, *, local: bool = False) None
Adds a closed loop connection from a relation stream to an input.
- Parameters:
Examples
model = Modely() x = Input('x') y = Input('y') relation = Fir(x.last()) model.addClosedLoop(relation, y)
- nnodely.operators.composer.Composer.removeConnection(self, input_in: str | Input) None
Remove a closed loop or connect connection from an input.
- Parameters:
input_in (Input or
nameof the input of inputs) – The Input to disconnect.
Examples
model = Modely() x = Input('x') y = Input('y') relation = Fir(x.last()) model.addConnect(relation, y) model.removeConnection(y)
- nnodely.operators.composer.Composer.neuralizeModel(self, sample_time: float | int | None = None, *, clear_model: bool = False, model_def: dict | None = None) None
Neuralizes the model, preparing it for inference and training. This method creates a neural network model starting from the model definition. It will also create all the time windows and correct slicing for all the inputs defined.
- Parameters:
sample_time (float or None, optional) – The sample time for the model. Default is 1.0
clear_model (bool, optional) – Whether to clear the existing model definition. Default is False.
model_def (dict or None, optional) – A dictionary defining the model. If provided, it overrides the existing model definition. Default is None.
- Raises:
ValueError – If sample_time is not None and model_def is provided. If clear_model is True and model_def is provided.
Example
model = Modely(name='example_model') model.neuralizeModel(sample_time=0.1, clear_model=True)
For further examples please refer to the relative tutorial.