From d9cad595812217271502cb4f5c90afe83d64198a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoff=20B=C3=BCrger?= Date: Wed, 14 May 2025 11:24:22 +0200 Subject: [PATCH] Fixed warnings are errors when checking with Dymola. Classes extending Layer are blocks; to extend a model in a block is invalid Modelica => changed Layer type from model to block. The example networks connect in- and outputs with layers via component modification. This in invalid Modelica => changed to proper connect equation. The NARX_Network example leverages on propagating sizes via the connector. Again, this is not supported by the Modelica specification. => Sizes are now provided via redeclaration of the in- and outputs with size information. General comment: The current library design breaks with MSL design, where MIMO interfaces must have size parameters that are used to properly set the sizes. This is a rather big design issue. --- NeuralNetwork/Examples/Utilities/NARX_Network.mo | 8 ++++++-- NeuralNetwork/Examples/Utilities/SimpleNetwork.mo | 6 ++++-- NeuralNetwork/Layer/Interfaces/Layer.mo | 3 +-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/NeuralNetwork/Examples/Utilities/NARX_Network.mo b/NeuralNetwork/Examples/Utilities/NARX_Network.mo index be2443e..88b3c82 100644 --- a/NeuralNetwork/Examples/Utilities/NARX_Network.mo +++ b/NeuralNetwork/Examples/Utilities/NARX_Network.mo @@ -1,9 +1,10 @@ within NeuralNetwork.Examples.Utilities; - block NARX_Network // This represents a three layer neural network with a given time delay - extends NeuralNetwork.Networks.Interfaces.Network(u = layer_scale.u, y = layer_3.y); + extends NeuralNetwork.Networks.Interfaces.Network( + redeclare Modelica.Blocks.Interfaces.RealInput u[size(layer_1.u,1)], + redeclare Modelica.Blocks.Interfaces.RealOutput y[size(layer_3.y,1)]); NeuralNetwork.Layer.Preprocessing.Scale layer_scale( min = { @@ -106,6 +107,9 @@ block NARX_Network redeclare function f = NeuralNetwork.ActivationFunctions.Id ) annotation(Placement(transformation(origin = {92, 0}, extent = {{-30, -30}, {30, 30}}))); equation + connect( u, layer_scale.u); + connect( layer_3.y, y); + connect(layer_scale.y, layer_1.u) annotation( Line(points = {{-74, 0}, {-52, 0}}, color = {0, 0, 127}, thickness = 0.5)); connect(layer_1.y, layer_2.u) annotation( diff --git a/NeuralNetwork/Examples/Utilities/SimpleNetwork.mo b/NeuralNetwork/Examples/Utilities/SimpleNetwork.mo index d5c9ff1..cd45c84 100644 --- a/NeuralNetwork/Examples/Utilities/SimpleNetwork.mo +++ b/NeuralNetwork/Examples/Utilities/SimpleNetwork.mo @@ -1,7 +1,6 @@ within NeuralNetwork.Examples.Utilities; - block SimpleNetwork "Neural Network approximating y = u*u + 0.5*u - 2.0 on interval [-1,1]" - extends NeuralNetwork.Networks.Interfaces.SISO(final u = inputLayer.u[1], final y = outputLayer.y[1]); + extends NeuralNetwork.Networks.Interfaces.SISO; Layer.Dense inputLayer( weights = layer_1_weights, bias = layer_1_bias, @@ -20,6 +19,9 @@ block SimpleNetwork "Neural Network approximating y = u*u + 0.5*u - 2.0 on inter parameter Real[1,2] layer_2_weights = {{-4.513856227908402, 2.4932885356708683}}; parameter Real[1] layer_2_bias = {3.897109323824147}; equation + connect( u, inputLayer.u[1]); + connect( outputLayer.y[1], y); + connect(inputLayer.y, outputLayer.u) annotation( Line(points = {{-48, 0}, {30, 0}}, color = {0, 0, 127}, thickness = 0.5)); annotation( diff --git a/NeuralNetwork/Layer/Interfaces/Layer.mo b/NeuralNetwork/Layer/Interfaces/Layer.mo index 23b8060..dcd87eb 100644 --- a/NeuralNetwork/Layer/Interfaces/Layer.mo +++ b/NeuralNetwork/Layer/Interfaces/Layer.mo @@ -1,6 +1,5 @@ within NeuralNetwork.Layer.Interfaces; - -partial model Layer +partial block Layer // Topology of the neural network parameter Integer numInputs "Specification of the inputs of the layer"; parameter Integer numNeurons "Number of neurons in the layer";