Skip to content

Commit 0c5e6a3

Browse files
Merge pull request #717 from SciML/louiville
add the liouville transformation
2 parents 6cbc8ea + 05f1a54 commit 0c5e6a3

File tree

4 files changed

+92
-1
lines changed

4 files changed

+92
-1
lines changed

docs/src/systems/ODESystem.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ODESystem
1717

1818
```@docs
1919
ode_order_lowering
20+
liouville_transform
2021
```
2122

2223
## Applicable Calculation and Generation Functions

src/ModelingToolkit.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ include("systems/diffeqs/abstractodesystem.jl")
176176
include("systems/diffeqs/first_order_transform.jl")
177177
include("systems/diffeqs/modelingtoolkitize.jl")
178178
include("systems/diffeqs/validation.jl")
179+
include("systems/diffeqs/basic_transformations.jl")
179180

180181
include("systems/jumps/jumpsystem.jl")
181182

@@ -206,7 +207,7 @@ export SteadyStateProblem, SteadyStateProblemExpr
206207
export JumpProblem, DiscreteProblem
207208
export NonlinearSystem, OptimizationSystem
208209
export ControlSystem
209-
export ode_order_lowering
210+
export ode_order_lowering, liouville_transform
210211
export runge_kutta_discretize
211212
export PDESystem
212213
export Reaction, ReactionSystem, ismassaction, oderatelaw, jumpratelaw
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
$(TYPEDSIGNATURES)
3+
4+
Generates the Liouville transformed set of ODEs, which is the original
5+
ODE system with a new variable `trJ` appended, corresponding to the
6+
-tr(Jacobian). This variable is used for properties like uncertainty
7+
propagation from a given initial distribution density.
8+
9+
For example, if ``u'=p*u`` and `p` follows a probability distribution
10+
``f(p)``, then the probability density of a future value with a given
11+
choice of ``p`` is computed by setting the inital `trJ = f(p)`, and
12+
the final value of `trJ` is the probability of ``u(t)``.
13+
14+
Example:
15+
16+
```julia
17+
using ModelingToolkit, OrdinaryDiffEq, Test
18+
19+
@parameters t α β γ δ
20+
@variables x(t) y(t)
21+
@derivatives D'~t
22+
23+
eqs = [D(x) ~ α*x - β*x*y,
24+
D(y) ~ -δ*y + γ*x*y]
25+
26+
sys = ODESystem(eqs)
27+
sys2 = liouville_transform(sys)
28+
@variables trJ
29+
30+
u0 = [x => 1.0,
31+
y => 1.0,
32+
trJ => 1.0]
33+
34+
prob = ODEProblem(sys2,u0,tspan,p)
35+
sol = solve(prob,Tsit5())
36+
```
37+
38+
Where `sol[3,:]` is the evolution of `trJ` over time.
39+
40+
Sources:
41+
42+
Probabilistic Robustness Analysis of F-16 Controller Performance: An
43+
Optimal Transport Approach
44+
45+
Abhishek Halder, Kooktae Lee, and Raktim Bhattacharya
46+
https://abhishekhalder.bitbucket.io/F16ACC2013Final.pdf
47+
"""
48+
function liouville_transform(sys)
49+
t = independent_variable(sys)
50+
@variables trJ
51+
D = ModelingToolkit.Differential(t)
52+
neweq = D(trJ) ~ trJ*-tr(calculate_jacobian(sys))
53+
neweqs = [equations(sys);neweq]
54+
vars = [states(sys);trJ]
55+
ODESystem(neweqs,t,vars,parameters(sys))
56+
end

test/basic_transformations.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using ModelingToolkit, OrdinaryDiffEq, Test
2+
3+
@parameters t α β γ δ
4+
@variables x(t) y(t)
5+
@derivatives D'~t
6+
7+
eqs = [D(x) ~ α*x - β*x*y,
8+
D(y) ~ -δ*y + γ*x*y]
9+
10+
sys = ODESystem(eqs)
11+
12+
u0 = [x => 1.0,
13+
y => 1.0]
14+
15+
p ==> 1.5,
16+
β => 1.0,
17+
δ => 3.0,
18+
γ => 1.0]
19+
20+
tspan = (0.0,10.0)
21+
prob = ODEProblem(sys,u0,tspan,p)
22+
sol = solve(prob,Tsit5())
23+
24+
sys2 = liouville_transform(sys)
25+
@variables trJ
26+
27+
u0 = [x => 1.0,
28+
y => 1.0,
29+
trJ => 1.0]
30+
31+
prob = ODEProblem(sys2,u0,tspan,p,jac=true)
32+
sol = solve(prob,Tsit5())
33+
@test sol[end,end] 1.0742818931017244

0 commit comments

Comments
 (0)