@@ -153,7 +153,7 @@ function generate_diffusion_function(sys::SDESystem, dvs = states(sys),
153
153
return build_function (get_noiseeqs (sys),
154
154
map (x -> time_varying_as_func (value (x), sys), dvs),
155
155
map (x -> time_varying_as_func (value (x), sys), ps),
156
- get_iv (sys); kwargs... )
156
+ get_iv (sys); kwargs... )
157
157
end
158
158
159
159
"""
@@ -210,13 +210,15 @@ end
210
210
$(TYPEDSIGNATURES)
211
211
212
212
Measure transformation method that allows for a reduction in the variance of an estimator `Exp(g(X_t))`.
213
- Input: Original SDE system and symbolic function `u(t,x)` with scalar output that defines the
214
- adjustable parameters `d` in the Girsanov transformation.
215
- Output: Modified SDESystem with additional component `θ_t` and initial value `θ0`,
216
- such that the estimator `Exp(g(X_t)θ_t/θ0)` has a smaller variance.
217
-
218
- Reference:
219
- Kloeden, P. E., Platen, E., & Schurz, H. (2012). Numerical solution of SDE through computer
213
+ Input: Original SDE system and symbolic function `u(t,x)` with scalar output that
214
+ defines the adjustable parameters `d` in the Girsanov transformation. Optional: initial
215
+ condition for `θ0`.
216
+ Output: Modified SDESystem with additional component `θ_t` and initial value `θ0`, as well as
217
+ the weight `θ_t/θ0` as observed equation, such that the estimator `Exp(g(X_t)θ_t/θ0)`
218
+ has a smaller variance.
219
+
220
+ Reference:
221
+ Kloeden, P. E., Platen, E., & Schurz, H. (2012). Numerical solution of SDE through computer
220
222
experiments. Springer Science & Business Media.
221
223
222
224
# Example
@@ -234,22 +236,40 @@ noiseeqs = [β*x]
234
236
@named de = SDESystem(eqs,noiseeqs,t,[x],[α,β])
235
237
236
238
# define u (user choice)
237
- u = x
238
- demod = ModelingToolkit.Girsanov_transform(de, u)
239
+ u = x
240
+ θ0 = 0.1
241
+ g(x) = x[1]^2
242
+ demod = ModelingToolkit.Girsanov_transform(de, u; θ0=0.1)
243
+
244
+ u0modmap = [
245
+ x => x0
246
+ ]
247
+
248
+ parammap = [
249
+ α => 1.5,
250
+ β => 1.0
251
+ ]
252
+
253
+ probmod = SDEProblem(demod,u0modmap,(0.0,1.0),parammap)
254
+ ensemble_probmod = EnsembleProblem(probmod;
255
+ output_func = (sol,i) -> (g(sol[x,end])*sol[weight,end],false),
256
+ )
257
+
258
+ simmod = solve(ensemble_probmod,EM(),dt=dt,trajectories=numtraj)
239
259
```
240
260
241
261
"""
242
- function Girsanov_transform (sys:: SDESystem , u)
262
+ function Girsanov_transform (sys:: SDESystem , u; θ0 = 1.0 )
243
263
name = nameof (sys)
244
264
245
265
# register new varible θ corresponding to 1D correction process θ(t)
246
266
t = get_iv (sys)
247
- @variables θ (t)
248
267
D = Differential (t)
249
-
268
+ @variables θ (t), weight (t)
269
+
250
270
# determine the adjustable parameters `d` given `u`
251
- # gradient of u with respect to states
252
- grad = Symbolics. gradient (u,states (sys))
271
+ # gradient of u with respect to states
272
+ grad = Symbolics. gradient (u,states (sys))
253
273
254
274
noiseeqs = get_noiseeqs (sys)
255
275
if typeof (noiseeqs) <: Vector
@@ -288,7 +308,9 @@ function Girsanov_transform(sys::SDESystem, u)
288
308
state = [states (sys);θ]
289
309
290
310
# return modified SDE System
291
- SDESystem (deqs, noiseeqs, get_iv (sys), state, parameters (sys), name = name, checks = false )
311
+ SDESystem (deqs, noiseeqs, get_iv (sys), state, parameters (sys);
312
+ defaults = Dict (θ => θ0), observed = [weight ~ θ/ θ0],
313
+ name= name, checks= false )
292
314
end
293
315
294
316
"""
0 commit comments