<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mintoc.de/index.php?action=history&amp;feed=atom&amp;title=Lotka_Volterra_fishing_problem_%28Julia_Neural_Network_solve%29</id>
	<title>Lotka Volterra fishing problem (Julia Neural Network solve) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mintoc.de/index.php?action=history&amp;feed=atom&amp;title=Lotka_Volterra_fishing_problem_%28Julia_Neural_Network_solve%29"/>
	<link rel="alternate" type="text/html" href="https://mintoc.de/index.php?title=Lotka_Volterra_fishing_problem_(Julia_Neural_Network_solve)&amp;action=history"/>
	<updated>2026-06-09T10:27:20Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://mintoc.de/index.php?title=Lotka_Volterra_fishing_problem_(Julia_Neural_Network_solve)&amp;diff=2341&amp;oldid=prev</id>
		<title>ClemensZeile at 15:20, 20 September 2021</title>
		<link rel="alternate" type="text/html" href="https://mintoc.de/index.php?title=Lotka_Volterra_fishing_problem_(Julia_Neural_Network_solve)&amp;diff=2341&amp;oldid=prev"/>
		<updated>2021-09-20T15:20:00Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:20, 20 September 2021&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l84&quot;&gt;Line 84:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 84:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;gallery caption=&quot;Reference solution plot&quot; widths=&quot;280px&quot; heights=&quot;240px&quot; perrow=&quot;1&quot;&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Image:Lotka volterra optimal control julia NN.gif| Animated solution process&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/gallery&amp;gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category: Julia/JuMP]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category: Julia/JuMP]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>ClemensZeile</name></author>
	</entry>
	<entry>
		<id>https://mintoc.de/index.php?title=Lotka_Volterra_fishing_problem_(Julia_Neural_Network_solve)&amp;diff=2338&amp;oldid=prev</id>
		<title>ClemensZeile: Created page with &quot;This is an implementation of the Lotka Volterra fishing problem using Julia and a neural network by Julius Martensen, see https://github.com/AlCap23/IMPRS2021  The control...&quot;</title>
		<link rel="alternate" type="text/html" href="https://mintoc.de/index.php?title=Lotka_Volterra_fishing_problem_(Julia_Neural_Network_solve)&amp;diff=2338&amp;oldid=prev"/>
		<updated>2021-09-20T15:12:45Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This is an implementation of the &lt;a href=&quot;/index.php?title=Lotka_Volterra_fishing_problem&quot; title=&quot;Lotka Volterra fishing problem&quot;&gt;Lotka Volterra fishing problem&lt;/a&gt; using Julia and a neural network by Julius Martensen, see https://github.com/AlCap23/IMPRS2021  The control...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This is an implementation of the [[Lotka Volterra fishing problem]] using Julia and a neural network by Julius Martensen, see https://github.com/AlCap23/IMPRS2021&lt;br /&gt;
&lt;br /&gt;
The control function was relaxed, i.e. &amp;lt;math&amp;gt; u(t)  \in [0,1] &amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;AMPL&amp;quot;&amp;gt;&lt;br /&gt;
using LinearAlgebra&lt;br /&gt;
using Plots&lt;br /&gt;
&lt;br /&gt;
using OrdinaryDiffEq&lt;br /&gt;
using Flux&lt;br /&gt;
using DiffEqFlux&lt;br /&gt;
&lt;br /&gt;
# Example for optimal control&lt;br /&gt;
&lt;br /&gt;
controller = Chain(Dense(1, 10, relu), Dense(10,10, relu), Dense(10,10, relu), Dense(10, 1, σ))&lt;br /&gt;
&lt;br /&gt;
pnn, f = Flux.destructure(controller)&lt;br /&gt;
&lt;br /&gt;
function lotka!(du, u, p, t)&lt;br /&gt;
    c = f(p)([t])[1]&lt;br /&gt;
    du[1] = (1-0.4*c)*u[1] - u[1]*u[2]&lt;br /&gt;
    du[2] = u[1]*u[2] - (1+0.2*c)*u[2]&lt;br /&gt;
    du[3] = (u[1] - 1)^2 + (u[2] -1)^2&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
u0 = Float32[0.5; 0.7; 0.0]&lt;br /&gt;
tspan = (0.0f0, 12.0f0)&lt;br /&gt;
Δt = 12.0f0/100&lt;br /&gt;
&lt;br /&gt;
prob = ODEProblem(lotka!, u0, tspan, pnn)&lt;br /&gt;
solution = solve(prob, Tsit5(), saveat = Δt)&lt;br /&gt;
length(solution)&lt;br /&gt;
&lt;br /&gt;
function loss(p)&lt;br /&gt;
    s_ = solve(prob, Tsit5(), p = p)&lt;br /&gt;
    l = sum(abs, s_[end,end])&lt;br /&gt;
    return l, s_&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
loss(pnn)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ps = typeof(solution)[]&lt;br /&gt;
ls = eltype(p_init)[]&lt;br /&gt;
&lt;br /&gt;
callback = function (p, l, pred)&lt;br /&gt;
    display(l)&lt;br /&gt;
    push!(ps, pred)&lt;br /&gt;
    push!(ls, l)&lt;br /&gt;
    l &amp;lt;= 1.35 &amp;amp;&amp;amp; return true&lt;br /&gt;
    return false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
# Steer away from initial position and try to avoid local minima&lt;br /&gt;
res_1 = DiffEqFlux.sciml_train(loss, pnn, cb = callback, maxiters = 100)&lt;br /&gt;
&lt;br /&gt;
anm = @animate for i in 1:1:length(ps)&lt;br /&gt;
    pl_ = plot(ps[i], ylim = (0, 4), title = &amp;quot;Iteration $i : $(ls[i])&amp;quot;)&lt;br /&gt;
    plot!(ps[i].t, 1.34408f0*ones(length(ps[i].t)), color = :black, style = :dash, label = &amp;quot;Optimum&amp;quot;)&lt;br /&gt;
    pl_&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
gif(anm, joinpath(pwd(), &amp;quot;figures&amp;quot;, &amp;quot;lotka_volterra_optimal_control.gif&amp;quot;), fps = 10)&lt;br /&gt;
&lt;br /&gt;
# Plot the control value&lt;br /&gt;
s_ = solve(prob, Tsit5(), p = res_1.u, saveat = Δt)&lt;br /&gt;
us = f(res_1.u)(permutedims(s_.t))&lt;br /&gt;
&lt;br /&gt;
p1 = plot(s_, legend = :bottomright, ylabel = &amp;quot;u(t)&amp;quot;)&lt;br /&gt;
plot!(s_.t, 1.34408f0*ones(length(s_.t)), color = :black, style = :dash, label = &amp;quot;Optimum&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
plot(&lt;br /&gt;
    p1,&lt;br /&gt;
    plot(s_.t, us&amp;#039;, xlabel = &amp;quot;t&amp;quot;, ylabel = &amp;quot;w(t)&amp;quot;, label = nothing, xticks = 0:2:12),&lt;br /&gt;
    layout = (2,1), link = :x&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
savefig(joinpath(pwd(), &amp;quot;figures&amp;quot;, &amp;quot;lotka_volterra_optimal_control_input.png&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
plot(ls, title = &amp;quot;Objective&amp;quot;, xlabel = &amp;quot;Iterations&amp;quot;, label = nothing)&lt;br /&gt;
savefig(joinpath(pwd(), &amp;quot;figures&amp;quot;, &amp;quot;lotka_volterra_optimal_control_objective.png&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: Julia/JuMP]]&lt;/div&gt;</summary>
		<author><name>ClemensZeile</name></author>
	</entry>
</feed>