Skip to content

Commit

Permalink
Simplify NelloWorld example
Browse files Browse the repository at this point in the history
  • Loading branch information
phannebohm committed Jan 25, 2025
1 parent 8503467 commit 56d9989
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Example/helloWorld.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@
"metadata": {},
"source": [
"Finally we need to copy these parameters into our new Modelica model\n",
"`NeuralNetwork.Examples.Utilities.PolynomNetwork` and set the number of inputs,\n",
"`NeuralNetwork.Examples.Utilities.SimpleNetwork` and set the number of inputs,\n",
"outputs and neurons for the network and each layer.\n",
"Finally we connect:\n",
" - the input to the input layer \n",
Expand All @@ -528,7 +528,7 @@
"metadata": {},
"source": [
"```modelica\n",
"block PolynomNetwork \"Neural Network approximating y = u*u + 0.5*u - 2.0 on interval [-1,1]\"\n",
"block SimpleNetwork \"Neural Network approximating y = u*u + 0.5*u - 2.0 on interval [-1,1]\"\n",
" extends NeuralNetwork.Networks.Interfaces.Network(numInputs = 1, numOutputs = 1);\n",
" Layer.Input inputLayer(\n",
" numInputs = 1,\n",
Expand All @@ -552,7 +552,7 @@
" connect(u, inputLayer.u);\n",
" connect(inputLayer.y, outputLayer.u);\n",
" connect(outputLayer.y, y);\n",
"end PolynomNetwork;\n",
"end SimpleNetwork;\n",
"```"
]
}
Expand Down
10 changes: 5 additions & 5 deletions NeuralNetwork/Examples/HelloWorld.mo
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ model HelloWorld
Placement(transformation(origin = {-60, 0}, extent = {{-20, -20}, {20, 20}})));
Utilities.SimpleEquation eq annotation(
Placement(transformation(origin = {40, 30}, extent = {{-20, -20}, {20, 20}})));
Utilities.PolynomNetwork nn annotation(
Utilities.SimpleNetwork nn annotation(
Placement(transformation(origin = {40, -30}, extent = {{-20, -20}, {20, 20}})));
Real reference = eq.y;
Real prediction = nn.y[1];
Real prediction = nn.y;
equation
connect(sine.y, eq.u) annotation(
Line(points = {{-38, 0}, {-20, 0}, {-20, 30}, {16, 30}}, color = {0, 0, 127}));
connect(sine.y, nn.u[1]) annotation(
connect(sine.y, nn.u) annotation(
Line(points = {{-38, 0}, {-20, 0}, {-20, -30}, {16, -30}}, color = {0, 0, 127}));
annotation(
Documentation(info = "<html><head></head><body>
Expand All @@ -22,10 +22,10 @@ equation
</p>
<p>y = u^2 + 0.5u - 2</p>
<p>with artificial neural network surrogate
<a href=\"modelica://NeuralNetwork.Examples.Utilities.PolynomNetwork\">PolynomNetwork</a>.
<a href=\"modelica://NeuralNetwork.Examples.Utilities.SimpleNetwork\">SimpleNetwork</a>.
</p>
<p>
A two-dimensional polynomial equation is approximmated with a dense feed-forward neural network.
A two-dimensional polynomial equation is approximated with a dense feed-forward neural network.
The network was generated using Python script from Notebook
<a href=\"https://github.com/AMIT-HSBI/NeuralNetwork/blob/main/Example/HelloWorld.ipynb\">HelloWorld.ipynb</a>.
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
within NeuralNetwork.Examples.Utilities;

block PolynomNetwork "Neural Network approximating y = u*u + 0.5*u - 2.0 on interval [-1,1]"
extends NeuralNetwork.Networks.Interfaces.Network(final u = inputLayer.u, final y = outputLayer.y);
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]);
Layer.Dense inputLayer(
weights = layer_1_weights,
bias = layer_1_bias,
Expand Down Expand Up @@ -29,4 +29,4 @@ equation
<a href=\"https://github.com/AMIT-HSBI/NeuralNetwork/blob/main/Example/HelloWorld.ipynb\">HelloWorld.ipynb</a>.
</p><p>Trained with TensorFlow on 8000 data points from interval [-1,1].</p>
</body></html>"));
end PolynomNetwork;
end SimpleNetwork;
2 changes: 1 addition & 1 deletion NeuralNetwork/Examples/Utilities/package.order
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NARX_Network
SamplerMIMO
TimeDelay
PolynomNetwork
SimpleNetwork
SimpleEquation

0 comments on commit 56d9989

Please sign in to comment.