121
121
122
122
# ## Noise Scaling ###
123
123
124
- # Tests where a single noise scaling parameter is given directly to the SDEProblem.
125
- let
126
- noise_scaling_network = @reaction_network begin (k1, k2), X1 ↔ X2 end
127
- for repeat in 1 : 5
128
- p = 1.0 .+ rand (rng, 2 )
129
- u0 = 10000 * (1.0 .+ rand (rng, 2 ))
130
- sol001 = solve (SDEProblem (noise_scaling_network, u0, (0.0 , 1000.0 ), vcat (p, 0.01 ),
131
- noise_scaling = (@variables η1)[1 ]), ImplicitEM ())
132
- sol01 = solve (SDEProblem (noise_scaling_network, u0, (0.0 , 1000.0 ), vcat (p, 0.1 ),
133
- noise_scaling = (@variables η1)[1 ]), ImplicitEM ())
134
- sol1 = solve (SDEProblem (noise_scaling_network, u0, (0.0 , 1000.0 ), vcat (p, 1.0 ),
135
- noise_scaling = (@variables η2)[1 ]), ImplicitEM ())
136
- sol10 = solve (SDEProblem (noise_scaling_network, u0, (0.0 , 1000.0 ), vcat (p, 10.0 ),
137
- noise_scaling = (@variables η3)[1 ]), ImplicitEM ())
138
- @test 2 * std (first .(sol001. u)[100 : end ]) < std (first .(sol01. u)[100 : end ])
139
- @test 2 * std (last .(sol001. u)[100 : end ]) < std (last .(sol01. u)[100 : end ])
140
- @test 2 * std (first .(sol01. u)[100 : end ]) < std (first .(sol1. u)[100 : end ])
141
- @test 2 * std (last .(sol01. u)[100 : end ]) < std (last .(sol1. u)[100 : end ])
142
- @test 2 * std (first .(sol1. u)[100 : end ]) < std (first .(sol10. u)[100 : end ])
143
- @test 2 * std (last .(sol1. u)[100 : end ]) < std (last .(sol10. u)[100 : end ])
144
- end
145
- end
146
-
147
124
# Tests with multiple noise scaling parameters directly in the macro.
148
125
let
149
126
noise_scaling_network_1 = @reaction_network begin
@@ -160,10 +137,10 @@ let
160
137
@noise_scaling_parameters η[1 : 2 ]
161
138
(k1, k2), X1 ↔ X2
162
139
end
163
- @unpack η = noise_scaling_network_2
164
- sol_2_1 = solve (SDEProblem (noise_scaling_network_2, u0, (0.0 , 1000.0 ), [: k1 => 2.0 , : k2 => 0.66 , η[1 ] => 2.0 , η[2 ] => 2.0 ]), ImplicitEM (); saveat= 1.0 )
165
- sol_2_2 = solve (SDEProblem (noise_scaling_network_2, u0, (0.0 , 1000.0 ), [: k1 => 2.0 , : k2 => 0.66 , η[1 ] => 2.0 , η[2 ] => 0.2 ]), ImplicitEM (); saveat= 1.0 )
166
- sol_2_3 = solve (SDEProblem (noise_scaling_network_2, u0, (0.0 , 1000.0 ), [: k1 => 2.0 , : k2 => 0.66 , η[1 ] => 0.2 , η[2 ] => 0.2 ]), ImplicitEM (); saveat= 1.0 )
140
+ @unpack k1, k2, η = noise_scaling_network_2
141
+ sol_2_1 = solve (SDEProblem (noise_scaling_network_2, u0, (0.0 , 1000.0 ), [k1 => 2.0 , k2 => 0.66 , η[1 ] => 2.0 , η[2 ] => 2.0 ]), ImplicitEM (); saveat= 1.0 )
142
+ sol_2_2 = solve (SDEProblem (noise_scaling_network_2, u0, (0.0 , 1000.0 ), [k1 => 2.0 , k2 => 0.66 , η[1 ] => 2.0 , η[2 ] => 0.2 ]), ImplicitEM (); saveat= 1.0 )
143
+ sol_2_3 = solve (SDEProblem (noise_scaling_network_2, u0, (0.0 , 1000.0 ), [k1 => 2.0 , k2 => 0.66 , η[1 ] => 0.2 , η[2 ] => 0.2 ]), ImplicitEM (); saveat= 1.0 )
167
144
@test var (sol_2_1[1 ,:]) > var (sol_2_2[1 ,:]) > var (sol_2_3[1 ,:])
168
145
end
169
146
175
152
end
176
153
u0 = [:X1 => 1100.0 , :X2 => 3900.0 ]
177
154
p = [:k1 => 2.0 , :k2 => 0.5 , :η => 0.0 ]
178
- ss = solve (SDEProblem (noise_scaling_network, u0, (0.0 , 1000.0 ), p), ImplicitEM ())[end ]
179
- @test ss ≈ [1000.0 , 4000.0 ]
155
+ @test SDEProblem (noise_scaling_network, u0, (0.0 , 1000.0 ), p)[:η ] == 0.0
180
156
end
181
157
182
158
# Complicated test with many combinations of options.
@@ -187,18 +163,16 @@ let
187
163
(p, d), 0 ↔ X1
188
164
(k1, k2), X1 ↔ X2
189
165
end
190
- @unpack X1, η4, p = noise_scaling_network
191
- u0 = [X1 => 500.0 , :X2 => 500.0 ]
192
- p = [p => 20.0 , :d => 0.1 , :η1 => 0.0 , :η3 => 0.0 , η4 => 0.0 , :k1 => 2.0 , :k2 => 2.0 , :par1 => 1000.0 , :par2 => 1000.0 ]
166
+ u0 = [:X1 => 500.0 , :X2 => 500.0 ]
167
+ p = [:p => 20.0 , :d => 0.1 , :η1 => 0.0 , :η3 => 0.0 , :η4 => 0.0 , :k1 => 2.0 , :k2 => 2.0 , :par1 => 1000.0 , :par2 => 1000.0 ]
193
168
194
169
@test getdescription (parameters (noise_scaling_network)[2 ]) == " Parameter par1"
195
170
@test getdescription (parameters (noise_scaling_network)[8 ]) == " Parameter η2"
196
171
197
- ss = solve ( SDEProblem (noise_scaling_network, u0, (0.0 , 1000.0 ), p), ImplicitEM ())[ end ]
198
- @test ss ≈ [ 200.0 , 200.0 ]
172
+ sprob = SDEProblem (noise_scaling_network, u0, (0.0 , 1000.0 ), p)
173
+ @test sprob[ :η1 ] == sprob[ :η2 ] == sprob[ :η3 ] == sprob[ :η4 ] == 0.0
199
174
end
200
175
201
- # Tests that nosie scaling wor
202
176
203
177
# ## Checks Simulations Don't Error ###
204
178
0 commit comments