This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
monte.jl
99 lines (77 loc) · 2.82 KB
/
monte.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using DiffEqMonteCarlo, StochasticDiffEq, DiffEqBase,
DiffEqProblemLibrary, OrdinaryDiffEq
using Base.Test
prob = prob_sde_2Dlinear
prob2 = MonteCarloProblem(prob)
sim = solve(prob2,SRIW1(),dt=1//2^(3),num_monte=10)
err_sim = calculate_monte_errors(sim;weak_dense_errors=true)
@test length(sim) == 10
sim = solve(prob2,SRIW1(),dt=1//2^(3),adaptive=false,num_monte=10)
err_sim = calculate_monte_errors(sim;weak_timeseries_errors=true)
sim = solve(prob2,SRIW1(),dt=1//2^(3),num_monte=10,parallel_type=:threads)
calculate_monte_errors(sim)
@test length(sim) == 10
sim = solve(prob2,SRIW1(),dt=1//2^(3),num_monte=10,parallel_type=:split_threads)
calculate_monte_errors(sim)
@test length(sim) == 10
sim = solve(prob2,SRIW1(),dt=1//2^(3),num_monte=10,parallel_type=:none)
calculate_monte_errors(sim)
@test length(sim) == 10
sim = solve(prob2,SRIW1(),dt=1//2^(3),num_monte=10,parallel_type=:parfor)
calculate_monte_errors(sim)
@test length(sim) == 10
sim = solve(prob2,SRIW1(),Val{false},dt=1//2^(3),num_monte=10)
@test length(sim) == 10
sim = solve(prob2,SRIW1(),Val{false},dt=1//2^(3),num_monte=10,parallel_type=:threads)
@test length(sim) == 10
prob = prob_sde_additivesystem
prob2 = MonteCarloProblem(prob)
sim = solve(prob2,SRA1(),dt=1//2^(3),num_monte=10)
calculate_monte_errors(sim)
output_func = function (sol,i)
last(last(sol))^2
end
prob2 = MonteCarloProblem(prob,output_func=output_func)
sim = solve(prob2,SRA1(),dt=1//2^(3),num_monte=10)
prob = prob_sde_lorenz
prob2 = MonteCarloProblem(prob)
sim = solve(prob2,SRIW1(),dt=1//2^(3),num_monte=10)
output_func = function (sol,i)
last(sol)
end
prob = prob_ode_linear
prob_func = function (prob,i)
prob.u0 = rand()*prob.u0
prob
end
srand(100)
reduction = function (u,batch,I)
u = append!(u,batch)
u,((var(u)/sqrt(last(I)))/mean(u)<0.5)?true:false
end
prob2 = MonteCarloProblem(prob,prob_func=prob_func,output_func=output_func,reduction=reduction,u_init=Vector{Float64}())
sim = solve(prob2,Tsit5(),num_monte=10000,batch_size=20)
@test sim.converged == true
srand(100)
reduction = function (u,batch,I)
u = append!(u,batch)
u,false
end
prob2 = MonteCarloProblem(prob,prob_func=prob_func,output_func=output_func,reduction=reduction,u_init=Vector{Float64}())
sim = solve(prob2,Tsit5(),num_monte=100,batch_size=20)
@test sim.converged == false
srand(100)
reduction = function (u,batch,I)
u+sum(batch),false
end
prob2 = MonteCarloProblem(prob,prob_func=prob_func,output_func=output_func,reduction=reduction,u_init=0.0)
sim2 = solve(prob2,Tsit5(),num_monte=100,batch_size=20)
@test sim2.converged == false
@test mean(sim.u) ≈ sim2.u/100
immutable SomeUserType end
output_func = function (sol,i)
SomeUserType()
end
prob2 = MonteCarloProblem(prob,prob_func=prob_func,output_func=output_func)
sim2 = solve(prob2,Tsit5(),num_monte=2)
@test !sim2.converged && typeof(sim2.u) == Vector{SomeUserType}