Skip to content

Commit

Permalink
build based on 4cbb2f5
Browse files Browse the repository at this point in the history
  • Loading branch information
Documenter.jl committed Sep 12, 2024
1 parent 3c7c606 commit b19a988
Show file tree
Hide file tree
Showing 11 changed files with 655 additions and 683 deletions.
2 changes: 1 addition & 1 deletion dev/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documenter":{"julia_version":"1.10.5","generation_timestamp":"2024-09-07T15:48:57","documenter_version":"1.7.0"}}
{"documenter":{"julia_version":"1.10.5","generation_timestamp":"2024-09-12T05:46:54","documenter_version":"1.7.0"}}
2 changes: 1 addition & 1 deletion dev/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
rng = Xoshiro(0),
init_params = Lux.initialparameters(rng, chain),
eltype = Float64,
name)</code></pre><p>Create an <code>ODESystem</code> with a neural network inside.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/SciML/ModelingToolkitNeuralNets.jl/blob/25a11e7636cca64ef3be58521dcdf03e5ca45ed2/src/ModelingToolkitNeuralNets.jl#L15-L24">source</a></section></article></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../friction/">« Friction Model</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.7.0 on <span class="colophon-date" title="Saturday 7 September 2024 15:48">Saturday 7 September 2024</span>. Using Julia version 1.10.5.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
name)</code></pre><p>Create an <code>ODESystem</code> with a neural network inside.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/SciML/ModelingToolkitNeuralNets.jl/blob/4cbb2f55f2aa76a01f4eb275253f86fac4afdd1f/src/ModelingToolkitNeuralNets.jl#L15-L24">source</a></section></article></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../friction/">« Friction Model</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.7.0 on <span class="colophon-date" title="Thursday 12 September 2024 05:46">Thursday 12 September 2024</span>. Using Julia version 1.10.5.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
132 changes: 53 additions & 79 deletions dev/assets/Manifest.toml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev/assets/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ModelingToolkitNeuralNets = "f162e290-f571-43a6-83d9-22ecc16da15f"

[compat]
Documenter = "1.3"
Lux = "0.5.32"
Lux = "1"
ModelingToolkit = "9.9"
ModelingToolkitStandardLibrary = "2.7"
Optimization = "3.24"
Expand Down
270 changes: 135 additions & 135 deletions dev/friction/b0e625ad.svg → dev/friction/2c937b88.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
268 changes: 134 additions & 134 deletions dev/friction/3bb56eb1.svg → dev/friction/a974e118.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
264 changes: 132 additions & 132 deletions dev/friction/6ca1510a.svg → dev/friction/b41f059d.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
264 changes: 132 additions & 132 deletions dev/friction/fb9bdfff.svg → dev/friction/cc41e81e.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 40 additions & 40 deletions dev/friction/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
[8.965808955089017]
[9.04079394249597]
[9.115490076324514]
[9.18990042447709]</code></pre><p>Let&#39;s plot it.</p><pre><code class="language-julia hljs">scatter(sol_ref, label = &quot;velocity&quot;)</code></pre><img src="6ca1510a.svg" alt="Example block output"/><p>That was the velocity. Let&#39;s also plot the friction force acting on the object throughout the simulation.</p><pre><code class="language-julia hljs">scatter(sol_ref.t, friction.(first.(sol_ref.u)), label = &quot;friction force&quot;)</code></pre><img src="fb9bdfff.svg" alt="Example block output"/><h2 id="Model-Setup"><a class="docs-heading-anchor" href="#Model-Setup">Model Setup</a><a id="Model-Setup-1"></a><a class="docs-heading-anchor-permalink" href="#Model-Setup" title="Permalink"></a></h2><p>Now, we will try to learn the same friction model using a neural network. We will use <a href="../api/#ModelingToolkitNeuralNets.NeuralNetworkBlock"><code>NeuralNetworkBlock</code></a> to define neural network as a component. The input of the neural network is the velocity and the output is the friction force. We connect the neural network with the model using <code>RealInputArray</code> and <code>RealOutputArray</code> blocks.</p><pre><code class="language-julia hljs">function friction_ude(Fu)
[9.18990042447709]</code></pre><p>Let&#39;s plot it.</p><pre><code class="language-julia hljs">scatter(sol_ref, label = &quot;velocity&quot;)</code></pre><img src="b41f059d.svg" alt="Example block output"/><p>That was the velocity. Let&#39;s also plot the friction force acting on the object throughout the simulation.</p><pre><code class="language-julia hljs">scatter(sol_ref.t, friction.(first.(sol_ref.u)), label = &quot;friction force&quot;)</code></pre><img src="cc41e81e.svg" alt="Example block output"/><h2 id="Model-Setup"><a class="docs-heading-anchor" href="#Model-Setup">Model Setup</a><a id="Model-Setup-1"></a><a class="docs-heading-anchor-permalink" href="#Model-Setup" title="Permalink"></a></h2><p>Now, we will try to learn the same friction model using a neural network. We will use <a href="../api/#ModelingToolkitNeuralNets.NeuralNetworkBlock"><code>NeuralNetworkBlock</code></a> to define neural network as a component. The input of the neural network is the velocity and the output is the friction force. We connect the neural network with the model using <code>RealInputArray</code> and <code>RealOutputArray</code> blocks.</p><pre><code class="language-julia hljs">function friction_ude(Fu)
@variables y(t) = 0.0
@constants Fu = Fu
@named nn_in = RealInputArray(nin = 1)
Expand Down Expand Up @@ -131,26 +131,26 @@
op = OptimizationProblem(of, x0, (prob, sol_ref, get_vars, get_refs))
res = solve(op, Adam(5e-3); maxiters = 10000, callback = cb)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">retcode: Default
u: 120-element Vector{Float64}:
-2.423965246422264
-2.389870055748775
1.1112592447429877
-1.9431216853164623
0.748581145013487
-2.3634238464622284
0.5181052037803907
-0.17995883919046124
-2.435797492730028
-2.432986756178753
-2.3636356168896393
-2.4192743320056964
2.0553216024376972
-0.299925206928586
0.9657348367786275
-2.4086786498364874
-2.321253697551076
0.5512956241338778
-2.436006830074837
-2.4256518875480806
-1.1097321751448963
0.9360569679386752
0.08533204603874663
-0.3834927673182644
1.5587951594990925
1.3488284090594305
-0.8027046157017986
-1.1330954958932196
0.9593681730647837</code></pre><h2 id="Visualization-of-results"><a class="docs-heading-anchor" href="#Visualization-of-results">Visualization of results</a><a id="Visualization-of-results-1"></a><a class="docs-heading-anchor-permalink" href="#Visualization-of-results" title="Permalink"></a></h2><p>We now have a trained neural network! We can check whether running the simulation of the model embedded with the neural network matches the data or not.</p><pre><code class="language-julia hljs">res_p = SciMLStructures.replace(Tunable(), prob.p, res.u)
-2.1175791469580205
1.231137921763269
-1.0464754889905168
-0.25115604090898497
-1.5963390506010442
1.453488833212753
-2.2825358674620055
-1.411365516380704
-1.5278017288524202</code></pre><h2 id="Visualization-of-results"><a class="docs-heading-anchor" href="#Visualization-of-results">Visualization of results</a><a id="Visualization-of-results-1"></a><a class="docs-heading-anchor-permalink" href="#Visualization-of-results" title="Permalink"></a></h2><p>We now have a trained neural network! We can check whether running the simulation of the model embedded with the neural network matches the data or not.</p><pre><code class="language-julia hljs">res_p = SciMLStructures.replace(Tunable(), prob.p, res.u)
res_prob = remake(prob, p = res_p)
res_sol = solve(res_prob, Rodas4(), saveat = sol_ref.t)</code></pre><p>Also, it would be interesting to check the simulation before the training to get an idea of the starting point of the network.</p><pre><code class="language-julia hljs">initial_sol = solve(prob, Rodas4(), saveat = sol_ref.t)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">retcode: Success
Interpolation: 1st order linear
Expand All @@ -177,26 +177,26 @@
0.1
u: 101-element Vector{Vector{Float64}}:
[0.0, 0.0]
[0.12001081871228214, 0.12001081871228214]
[0.240043440328915, 0.240043440328915]
[0.360098160447955, 0.360098160447955]
[0.480175289667169, 0.48017528966716905]
[0.6002752784412242, 0.6002752784412243]
[0.7203984526777717, 0.7203984526777718]
[0.8405449086275836, 0.8405449086275836]
[0.9607147425414322, 0.9607147425414322]
[1.0809079666986676, 1.0809079666986676]
[0.12001891802081019, 0.12001891802081031]
[0.24007647700874993, 0.2400764770087498]
[0.3601739747963031, 0.3601739747963031]
[0.4803131095522974, 0.4803131095522974]
[0.6004927757805316, 0.6004927757805316]
[0.7207126193354306, 0.7207126193354306]
[0.8409730643006613, 0.8409730643006613]
[0.9612712084093116, 0.9612712084093116]
[1.0816044728150558, 1.0816044728150558]
[11.113594079032303, 11.113594079032303]
[11.234984106232307, 11.234984106232307]
[11.356377742649215, 11.356377742649215]
[11.477782208621669, 11.477782208621669]
[11.5991975277462, 11.5991975277462]
[11.720623723619342, 11.720623723619342]
[11.842060819837624, 11.842060819837624]
[11.963508839997575, 11.963508839997575]
[12.084967807695728, 12.084967807695728]</code></pre><p>Now we plot it.</p><pre><code class="language-julia hljs">scatter(sol_ref, idxs = [model_true.y], label = &quot;ground truth velocity&quot;)
[11.145787875140721, 11.145787875140721]
[11.267953036793134, 11.267953036793134]
[11.39014155188266, 11.39014155188266]
[11.512353442687392, 11.51235344268739]
[11.634588731485419, 11.634588731485419]
[11.756847440554838, 11.756847440554838]
[11.879129592173735, 11.879129592173735]
[12.001435208620208, 12.001435208620206]
[12.123764312172343, 12.123764312172343]</code></pre><p>Now we plot it.</p><pre><code class="language-julia hljs">scatter(sol_ref, idxs = [model_true.y], label = &quot;ground truth velocity&quot;)
plot!(res_sol, idxs = [sys.friction.y], label = &quot;velocity after training&quot;)
plot!(initial_sol, idxs = [sys.friction.y], label = &quot;velocity before training&quot;)</code></pre><img src="b0e625ad.svg" alt="Example block output"/><p>It matches the data well! Let&#39;s also check the predictions for the friction force and whether the network learnt the friction model or not.</p><pre><code class="language-julia hljs">scatter(sol_ref.t, friction.(first.(sol_ref.u)), label = &quot;ground truth friction&quot;)
plot!(initial_sol, idxs = [sys.friction.y], label = &quot;velocity before training&quot;)</code></pre><img src="2c937b88.svg" alt="Example block output"/><p>It matches the data well! Let&#39;s also check the predictions for the friction force and whether the network learnt the friction model or not.</p><pre><code class="language-julia hljs">scatter(sol_ref.t, friction.(first.(sol_ref.u)), label = &quot;ground truth friction&quot;)
plot!(res_sol.t, getindex.(res_sol[sys.nn.output.u], 1),
label = &quot;friction from neural network&quot;)</code></pre><img src="3bb56eb1.svg" alt="Example block output"/><p>It learns the friction model well!</p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« Home</a><a class="docs-footer-nextpage" href="../api/">API »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.7.0 on <span class="colophon-date" title="Saturday 7 September 2024 15:48">Saturday 7 September 2024</span>. Using Julia version 1.10.5.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
label = &quot;friction from neural network&quot;)</code></pre><img src="a974e118.svg" alt="Example block output"/><p>It learns the friction model well!</p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« Home</a><a class="docs-footer-nextpage" href="../api/">API »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.7.0 on <span class="colophon-date" title="Thursday 12 September 2024 05:46">Thursday 12 September 2024</span>. Using Julia version 1.10.5.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
Loading

0 comments on commit b19a988

Please sign in to comment.