Skip to content

Commit e069526

Browse files
update to seeded RNGs
1 parent 652ff37 commit e069526

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
julia 0.6.0-pre
1+
julia 0.6.0
22
Parameters 0.5.0
3-
DiffEqBase 1.10.0
3+
DiffEqBase 1.13.0
44
RecursiveArrayTools 0.8.0
55
DataStructures 0.4.6
66
Juno 0.2.5

src/StochasticDiffEq.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module StochasticDiffEq
66

77
import Base: start, next, done, eltype
88

9+
import RandomNumbers: Xorshifts
10+
911
using Reexport
1012
@reexport using DiffEqBase
1113

src/integrators/integrator_interface.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ end
9191

9292
@inline function fill_new_noise_caches!(integrator,c,scaling_factor,idxs)
9393
if isinplace(integrator.W)
94-
integrator.W.dist(@view(c[2][idxs]),integrator.W,scaling_factor)
94+
integrator.W.dist(@view(c[2][idxs]),integrator.W,scaling_factor,integrator.W.rng)
9595
if alg_needs_extra_process(integrator.alg)
96-
integrator.W.dist(@view(c[3][idxs]),integrator.W,scaling_factor)
96+
integrator.W.dist(@view(c[3][idxs]),integrator.W,scaling_factor,integrator.W.rng)
9797
end
9898
else
9999
c[2][idxs] .= integrator.noise(length(idxs),integrator,scaling_factor)

src/solve.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,26 +271,32 @@ function init{uType,tType,isinplace,algType<:Union{AbstractRODEAlgorithm,Abstrac
271271
randType = typeof(rand_prototype) # Strip units and type info
272272
end
273273

274+
prob.seed == 0 ? seed = rand(UInt64) : seed = prob.seed
275+
274276
if typeof(prob.noise) <: Void
275277
if isinplace
276278
if alg_needs_extra_process(alg)
277279
W = WienerProcess!(t,rand_prototype,rand_prototype,
278280
save_everystep=save_everystep,
279-
timeseries_steps=timeseries_steps)
281+
timeseries_steps=timeseries_steps,
282+
rng = Xorshifts.Xoroshiro128Plus(seed))
280283
else
281284
W = WienerProcess!(t,rand_prototype,
282285
save_everystep=save_everystep,
283-
timeseries_steps=timeseries_steps)
286+
timeseries_steps=timeseries_steps,
287+
rng = Xorshifts.Xoroshiro128Plus(seed))
284288
end
285289
else
286290
if alg_needs_extra_process(alg)
287291
W = WienerProcess(t,rand_prototype,rand_prototype,
288292
save_everystep=save_everystep,
289-
timeseries_steps=timeseries_steps)
293+
timeseries_steps=timeseries_steps,
294+
rng = Xorshifts.Xoroshiro128Plus(seed))
290295
else
291296
W = WienerProcess(t,rand_prototype,
292297
save_everystep=save_everystep,
293-
timeseries_steps=timeseries_steps)
298+
timeseries_steps=timeseries_steps,
299+
rng = Xorshifts.Xoroshiro128Plus(seed))
294300
end
295301
end
296302
else
@@ -318,7 +324,7 @@ function init{uType,tType,isinplace,algType<:Union{AbstractRODEAlgorithm,Abstrac
318324

319325
sol = build_solution(prob,alg,ts,timeseries,W=W,
320326
calculate_error = false,
321-
interp = id, dense = dense)
327+
interp = id, dense = dense, seed = seed)
322328

323329
if recompile_flag == true
324330
FType = typeof(f)

test/iif_methods.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ sol2 = solve(prob2,EM(),dt=1/10)
2323
srand(100)
2424
dts = 1./2.^(7:-1:4) #14->7 good plot
2525
println("IIF scalar")
26-
sim = test_convergence(dts,prob,IIF1M(),numMonte=Int(2e1))
27-
@test abs(sim.𝒪est[:l2]-1) < 0.2 # closer to 1 at this part
26+
sim = test_convergence(dts,prob,IIF1M(),numMonte=Int(1e2))
27+
@test abs(sim.𝒪est[:l2]-0.5) < 0.2 # closer to 1 at this part
2828
sim = test_convergence(dts,no_noise_prob,IIF1M(),numMonte=Int(2e1))
29-
@test abs(sim.𝒪est[:l2]-1) < 0.2 # closer to 1 at this part
29+
@test abs(sim.𝒪est[:l2]-1.0) < 0.2 # closer to 1 at this part
3030

3131
dts = 1./2.^(7:-1:4) #14->7 good plot
3232
println("IIF no noise scalar")
3333
srand(100)
34-
sim = test_convergence(dts,prob,IIF2M(),numMonte=Int(2e1))
35-
@test abs(sim.𝒪est[:l2]-1) < 0.2 # closer to 1 at this part
34+
sim = test_convergence(dts,prob,IIF2M(),numMonte=Int(1e2))
35+
@test abs(sim.𝒪est[:l2]-0.5) < 0.2 # closer to 1 at this part
3636
sim = test_convergence(dts,no_noise_prob,IIF2M(),numMonte=Int(1e1))
3737
@test abs(sim.𝒪est[:l2]-2) < 0.2 # closer to 1 at this part
3838

0 commit comments

Comments
 (0)