You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/catalyst_applications/advanced_simulations.md
+24-50Lines changed: 24 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,8 +292,9 @@ plot(sol)
292
292
293
293
## Scaling the noise magnitude in the chemical Langevin equations
294
294
When using the CLE to generate SDEs from a CRN, it can sometimes be desirable to
295
-
scale the magnitude of the noise terms. This can be done by introducing a *noise
296
-
scaling parameter*. First, we simulate a simple two-state CRN model using the
295
+
scale the magnitude of the noise terms. Here, each reaction of the system generates a separate noise term in the CLE. If you require identical scaling for all reaction, the `@default_noise_scaling` option can be used. Else, you can supply a `noise_scaling` metadata for each individual reaction, describing how to scale the noise for that reaction.
296
+
297
+
We begin with considering the first approach. First, we simulate a simple two-state CRN model using the
Here we can see that the `X` concentration fluctuates around a steady state of $X≈10.0$.
313
-
314
-
Next, we wish to introduce a noise scaling parameter ,`η`. This will scale the
315
-
noise magnitude so that for $η=0.0$ the system lacks noise (and its SDE
316
-
simulations are identical to its ODE simulations) and for $η=1.0$ noise is not
317
-
scaled (and SDE simulations are identical to as if no noise scaling was used).
318
-
Setting $η<1.0$ will reduce noise and $η>1.0$ will increase noise. The syntax
319
-
for setting a noise scaling parameter `η` is
313
+
Here we can see that the $X$ concentration fluctuates around a steady state of $X≈10.0$.
314
+
315
+
Next, we wish increase the amount of noise with by a factor 2. To do so, we use the `@default_noise_scaling` option, to which we provide the desired scaling
320
316
```@example ex3
321
317
rn_2 = @reaction_network begin
322
-
@noise_scaling_parameters η
318
+
@default_noise_scaling 2
323
319
(k1,k2), X1 <--> X2
324
320
end
325
321
```
326
-
The `@noise_scaling_parameter` option creates one or more new parameters with additional metadata that allows Catalyst to know they represent a noise scaling. *η* becomes a parameter of the system, and we can now modulate its value to scale simulation noise:
322
+
If we re-simualte the systemwe see that the amount of noise have increased:
327
323
```@example ex3
328
-
u0 = [:X1 => 10.0, :X2 => 10.0]
329
-
tspan = (0.0, 10.0)
330
-
p_2 = [:k1 => 1.0, :k2 => 1.0, :η => 0.1]
331
-
332
-
sprob_2 = SDEProblem(rn_2, u0, tspan, p_2)
333
-
sol_2 = solve(sprob_2, ImplicitEM())
334
-
plot(sol_2; idxs = :X1, ylimit = (0.0, 20.0))
324
+
sprob_1 = SDEProblem(rn_2, u0, tspan, p_1)
325
+
sol_1 = solve(sprob_1, ImplicitEM())
326
+
plot(sol_1; idxs = :X1, ylimit = (0.0, 20.0))
335
327
```
336
328
337
-
It is worth noting that in the CLE, nosie is tied to *reactions* (and not species, which is a common missperception). If only a single noise scaling parameter is given, it will scale the noise for all reactions. However, it is also possible to set several noise scaling parameters, with each scaling the noise of a single reaction. Our model has two reactions (`X1 --> X2`and `X2 --> X1`) so we will use two noise scaling parameters (`η1` and `η2`):
329
+
It is possible to scale the amount of noise using any expression. A common use of this is to set a parameter which determines the amount of noise. Here we create a parameter $η$, and uses its value to scale the noise.
Both the noise scaling parameters and the reaction are ordered (these orders can be seen by calling `reactions(rn_3)` and `noise_scaling_parameters(rn_3)`, respectively). The i'th noise scaling parameter scales the noise of the i'th reaction. Plotting the results, we see that we have less fluctuation than for the first simulation, but more as compared to the second one (which is as expected):
350
-
```@example ex3
351
343
sol_3 = solve(sprob_3, ImplicitEM())
352
344
plot(sol_3; idxs = :X1, ylimit = (0.0, 20.0))
353
345
```
346
+
Here we saw how, by setting a small $η$ value, the amount of noise was reduced.
347
+
348
+
It is possible to use a different noise scaling expression for each reaction. Here, each reaction's noise scaling expression is provided using the `noise_scaling` metadata. In the following example, we use this to turn the noise of for both reactions involving the species $Y$.
354
349
355
-
For systems with many reactions, the `η[1:n]` (where `n` is equal to the number of reactions) notation can be useful (this however, requires `@unpack`'ing the system's parameters):
356
350
```@example ex3
357
351
rn_4 = @reaction_network begin
358
-
@noise_scaling_parameters η[1:6]
359
352
(p, d), 0 <--> X
360
-
(p, d), 0 <--> Y
361
-
(p, d), 0 <--> Z
353
+
(p, d), 0 <--> Y, ([noise_scaling=0.0, noise_scaling=0.0])
which is equivalent to `rn_2`. In this example, calling `@noise_scaling_parameters η` is equivalent to calling `parameters η` with the `noise_scaling_parameter` metadata:
387
-
```@example ex3
388
-
@parameters η [noise_scaling_parameter=true]
389
-
nothing # hide
390
-
```
364
+
Here, we not that there is n fluctuation in the value of $Y$. If the `@default_noise_scaling` option is used, its value is used for all reactions for which the `noise_scaling` metadata is unused. If `@default_noise_scaling` is not used, teh default noise scaling value is `1.0`.
391
365
392
366
## Useful plotting options
393
367
Catalyst, just like DifferentialEquations, uses the Plots package for all
0 commit comments