1
1
@testset " sobolindices" begin
2
2
x = RandomVariable .(Uniform (- π, π), [:x1 , :x2 , :x3 ])
3
3
4
- ishigami = Model (
5
- df -> sin .(df. x1) + 7 .* sin .(df. x2) .^ 2 + 0.1 .* df. x3 .^ 4 .* sin .(df. x1), :f
4
+ ishigami1 = Model (
5
+ df -> sin .(df. x1) + 7 .* sin .(df. x2) .^ 2 + 0.1 .* df. x3 .^ 4 .* sin .(df. x1), :f1
6
6
)
7
+ ishigami2 = Model (
8
+ df -> sin .(df. x1) + 7 .* sin .(df. x2) .^ 2 + 0.05 .* df. x3 .^ 4 .* sin .(df. x1), :f2
9
+ )
10
+
11
+ n_mc = 4000
12
+ n_qmc = 2300
7
13
8
- n = 1000
14
+ firstorder_analytical1 = [0.3138 , 0.4424 , 0.00 ]
15
+ totaleffect_analytical1 = [0.5574 , 0.4424 , 0.2436 ]
9
16
10
- firstorder_analytical = [0.3138 , 0.4424 , 0.00 ]
11
- totaleffect_analytical = [0.5574 , 0.4424 , 0.2436 ]
17
+ firstorder_analytical2 = [0.219 , 0.687 , 0.00 ]
18
+ totaleffect_analytical2 = [0.3136 , 0.687 , 0.0946 ]
12
19
13
20
@testset " Monte Carlo" begin
14
21
Random. seed! (8128 )
15
22
16
- si = sobolindices ([ishigami] , x, :f , MonteCarlo (n ))
23
+ si = sobolindices (ishigami1 , x, :f1 , MonteCarlo (n_mc ))
17
24
18
25
Random. seed! ()
19
26
20
- @test all (isapprox (si. FirstOrder, firstorder_analytical ; rtol= 0.1 ))
21
- @test all (isapprox (si. TotalEffect, totaleffect_analytical ; rtol= 0.1 ))
27
+ @test all (isapprox (si. FirstOrder, firstorder_analytical1 ; rtol= 0.1 ))
28
+ @test all (isapprox (si. TotalEffect, totaleffect_analytical1 ; rtol= 0.1 ))
22
29
end
23
30
24
31
@testset " Sobol" begin
25
- Random . seed! ( 8128 )
32
+ si = sobolindices (ishigami1, x, :f1 , SobolSampling (n_qmc) )
26
33
27
- si = sobolindices ([ishigami], x, :f , SobolSampling (n))
34
+ @test all (isapprox (si. FirstOrder, firstorder_analytical1; rtol= 0.1 ))
35
+ @test all (isapprox (si. TotalEffect, totaleffect_analytical1; rtol= 0.1 ))
36
+ end
28
37
29
- Random. seed! ()
38
+ @testset " Sobol Nultiple Outputs" begin
39
+ si = sobolindices ([ishigami1, ishigami2], x, [:f1 , :f2 ], SobolSampling (n_qmc))
30
40
31
- @test all (isapprox (si. FirstOrder, firstorder_analytical; rtol= 0.1 ))
32
- @test all (isapprox (si. TotalEffect, totaleffect_analytical; rtol= 0.1 ))
41
+ @test all (isapprox (si[:f1 ]. FirstOrder, firstorder_analytical1; rtol= 0.1 ))
42
+ @test all (isapprox (si[:f1 ]. TotalEffect, totaleffect_analytical1; rtol= 0.1 ))
43
+ @test all (isapprox (si[:f2 ]. FirstOrder, firstorder_analytical2; rtol= 0.1 ))
44
+ @test all (isapprox (si[:f2 ]. TotalEffect, totaleffect_analytical2; rtol= 0.1 ))
33
45
end
34
46
35
47
@testset " Halton" begin
36
- Random. seed! (8128 )
37
-
38
- si = sobolindices ([ishigami], x, :f , MonteCarlo (n))
48
+ si = sobolindices (ishigami1, x, :f1 , HaltonSampling (n_qmc))
39
49
40
- Random. seed! ()
41
-
42
- @test all (isapprox (si. FirstOrder, firstorder_analytical; rtol= 0.1 ))
43
- @test all (isapprox (si. TotalEffect, totaleffect_analytical; rtol= 0.1 ))
50
+ @test all (isapprox (si. FirstOrder, firstorder_analytical1; rtol= 0.1 ))
51
+ @test all (isapprox (si. TotalEffect, totaleffect_analytical1; rtol= 0.1 ))
44
52
end
45
53
46
54
@testset " Latin Hypercube" begin
47
- Random . seed! ( 8128 )
55
+ si = sobolindices (ishigami1, x, :f1 , LatinHypercubeSampling (n_qmc) )
48
56
49
- si = sobolindices ([ishigami], x, :f , MonteCarlo (n ))
50
-
51
- Random . seed! ()
57
+ @test all ( isapprox (si . FirstOrder, firstorder_analytical1; rtol = 0.1 ))
58
+ @test all ( isapprox (si . TotalEffect, totaleffect_analytical1; rtol = 0.1 ))
59
+ end
52
60
53
- @test all (isapprox (si. FirstOrder, firstorder_analytical; rtol= 0.1 ))
54
- @test all (isapprox (si. TotalEffect, totaleffect_analytical; rtol= 0.1 ))
61
+ @testset " Convenience Functions" begin
62
+ x1 = RandomVariable (Uniform (- π, + π), :x1 )
63
+ x2 = RandomVariable (Uniform (0 , + π), :x2 )
64
+ t1 = Model (df -> sin .(df. x1), :t1 )
65
+ t2 = Model (df -> cos .(df. x1), :t2 )
66
+
67
+ @test isa (sobolindices ([t1; t2], x1, :t1 , SobolSampling (2 )), DataFrame)
68
+ @test isa (sobolindices (t1, [x1; x2], :t1 , SobolSampling (2 )), DataFrame)
69
+ @test isa (sobolindices ([t1; t2], [x1; x2], :t1 , SobolSampling (2 )), DataFrame)
70
+ @test isa (
71
+ sobolindices ([t1; t2], x1, [:t1 , :t2 ], SobolSampling (2 )), Dict{Symbol,DataFrame}
72
+ )
73
+ @test isa (sobolindices (t1, x1, :t1 , SobolSampling (2 )), DataFrame)
55
74
end
56
75
57
76
@testset " Polynomial Chaos Expansion" begin
58
77
p = 6
59
78
Ψ = PolynomialChaosBasis (LegendreBasis .([p, p, p]), p)
60
79
61
80
gq = GaussQuadrature ()
62
- pce, _ = polynomialchaos (x, ishigami , Ψ, :f , gq)
81
+ pce, _ = polynomialchaos (x, ishigami1 , Ψ, :f1 , gq)
63
82
64
83
si = sobolindices (pce)
65
84
66
- @test all (isapprox (si. FirstOrder, firstorder_analytical ; rtol= 0.1 ))
67
- @test all (isapprox (si. TotalEffect, totaleffect_analytical ; rtol= 0.1 ))
85
+ @test all (isapprox (si. FirstOrder, firstorder_analytical1 ; rtol= 0.1 ))
86
+ @test all (isapprox (si. TotalEffect, totaleffect_analytical1 ; rtol= 0.1 ))
68
87
end
69
- end
88
+ end
0 commit comments