1
- function simulate_GAS_Sarima_1_1 (D:: Type{Beta} , scaling:: Float64 )
2
- # Create model
3
- Random. seed! (13 )
4
- vec = [0.1 ; 0.1 ]
5
-
1
+ function simulate_GAS_1_1 (D:: Type{<:Distribution} , scaling:: Float64 , ω:: Vector{T} , A:: Matrix{T} ,
2
+ B:: Matrix{T} , seed:: Int ) where T
3
+ Random. seed! (seed)
6
4
gas = GAS (1 , 1 , D, scaling)
7
5
8
- gas. ω = vec
9
- gas. A[1 ] = convert (Matrix{Float64}, Diagonal (5 * vec))
10
- gas. B[1 ] = convert (Matrix{Float64}, Diagonal (5 * vec))
6
+ gas. ω = ω
7
+ gas. A[1 ] = A
8
+ gas. B[1 ] = B
9
+ series, param = simulate (gas, 1000 )
10
+
11
+ return series
12
+ end
13
+
14
+ function simulate_GAS_1_12 (D:: Type{<:Distribution} , scaling:: Float64 )
15
+ Random. seed! (123 )
16
+ v = [0.1 , 0.1 ]
17
+ gas = GAS ([1 , 12 ], [1 , 12 ], D, scaling)
11
18
12
- # Simulate 1000 observations
13
- serie_simulated, param_simulated = simulate (gas, 1000 )
19
+ gas. ω = v
20
+ gas. A[1 ] = convert (Matrix{Float64}, Diagonal (3 * v))
21
+ gas. A[12 ] = convert (Matrix{Float64}, Diagonal (- 3 * v))
22
+ gas. B[1 ] = convert (Matrix{Float64}, Diagonal (3 * v))
23
+ gas. B[12 ] = convert (Matrix{Float64}, Diagonal (- 3 * v))
14
24
15
- return serie_simulated
25
+ series, param = simulate (gas, 5000 )
26
+
27
+ return series
16
28
end
17
29
18
- function test_coefficients_GAS_Sarima_1_1 (gas:: GAS{Beta, T} ; atol = 1e-1 , rtol = 1e-1 ) where T
19
- @test gas. ω[1 ] ≈ 0.1 atol = atol rtol = rtol
20
- @test gas. ω[2 ] ≈ 0.1 atol = atol rtol = rtol
21
- @test gas. A[1 ][1 , 1 ] ≈ 0.5 atol = atol rtol = rtol
22
- @test gas. A[1 ][2 , 2 ] ≈ 0.5 atol = atol rtol = rtol
23
- @test gas. B[1 ][1 , 1 ] ≈ 0.5 atol = atol rtol = rtol
24
- @test gas. B[1 ][2 , 2 ] ≈ 0.5 atol = atol rtol = rtol
30
+ function test_coefficients_GAS_1_1 (gas:: GAS{D, T} , ω:: Vector{T} , A:: Matrix{T} , B:: Matrix{T} ;
31
+ atol = 1e-1 , rtol = 1e-1 ) where {D <: Distribution , T}
32
+ @test gas. ω[1 ] ≈ ω[1 ] atol = atol rtol = rtol
33
+ @test gas. ω[2 ] ≈ ω[2 ] atol = atol rtol = rtol
34
+ @test gas. A[1 ][1 , 1 ] ≈ A[1 , 1 ] atol = atol rtol = rtol
35
+ @test gas. A[1 ][2 , 2 ] ≈ A[2 , 2 ] atol = atol rtol = rtol
36
+ @test gas. B[1 ][1 , 1 ] ≈ B[1 , 1 ] atol = atol rtol = rtol
37
+ @test gas. B[1 ][2 , 2 ] ≈ B[2 , 2 ] atol = atol rtol = rtol
25
38
return
26
39
end
27
40
28
- function test_estimation_GAS_Sarima_1_1 (gas:: GAS{D, T} , simulation:: Vector{T} ) where {D, T}
29
- estimate! (gas, simulation; verbose = 1 ,
30
- opt_method = ScoreDrivenModels. LBFGS (gas, 5 ))
31
-
32
- test_coefficients_GAS_Sarima_1_1 (gas)
33
- return
41
+ function test_coefficients_GAS_1_12 (gas:: GAS{D, T} ; atol = 1e-1 , rtol = 1e-1 ) where {D <: Distribution , T}
42
+ @test gas. ω[1 ] ≈ 0.1 atol = atol rtol = rtol
43
+ @test gas. ω[2 ] ≈ 0.1 atol = atol rtol = rtol
44
+ @test gas. A[1 ][1 , 1 ] ≈ 0.3 atol = atol rtol = rtol
45
+ @test gas. A[1 ][2 , 2 ] ≈ 0.3 atol = atol rtol = rtol
46
+ @test gas. A[12 ][1 , 1 ] ≈ - 0.3 atol = atol rtol = rtol
47
+ @test gas. A[12 ][2 , 2 ] ≈ - 0.3 atol = atol rtol = rtol
48
+ @test gas. B[1 ][1 , 1 ] ≈ 0.3 atol = atol rtol = rtol
49
+ @test gas. B[1 ][2 , 2 ] ≈ 0.3 atol = atol rtol = rtol
50
+ @test gas. B[12 ][1 , 1 ] ≈ - 0.3 atol = atol rtol = rtol
51
+ @test gas. B[12 ][2 , 2 ] ≈ - 0.3 atol = atol rtol = rtol
52
+ return
34
53
end
35
54
36
55
@testset " Estimate" begin
37
56
@testset " Beta" begin
38
- simulation = simulate_GAS_Sarima_1_1 (Beta, 0.0 )
39
- gas = GAS (1 , 1 , Beta, 0.0 )
40
- test_estimation_GAS_Sarima_1_1 (gas, simulation)
57
+ ω = [0.1 , 0.1 ]
58
+ A = [0.5 0 ; 0 0.5 ]
59
+ B = [0.5 0 ; 0 0.5 ]
60
+ simulation = simulate_GAS_1_1 (Beta, 0.0 , ω, A, B, 13 )
61
+ @testset " Estimation by passing number of seeds" begin
62
+ gas = GAS (1 , 1 , Beta, 0.0 )
63
+ estimate! (gas, simulation; verbose = 1 , opt_method = ScoreDrivenModels. LBFGS (gas, 3 ))
64
+ test_coefficients_GAS_1_1 (gas, ω, A, B)
65
+ end
66
+ @testset " Estimation by passing seeds" begin
67
+ gas = GAS (1 , 1 , Beta, 0.0 )
68
+ seeds = [[0.1 , 0.1 , 0.5 , 0.5 , 0.5 , 0.5 ]]
69
+ estimate! (gas, simulation; verbose = 1 , opt_method = ScoreDrivenModels. LBFGS (gas, seeds))
70
+ test_coefficients_GAS_1_1 (gas, ω, A, B)
71
+ end
72
+ end
73
+
74
+ @testset " Lognormal" begin
75
+ @testset " Scaling = 0.0" begin
76
+ ω = [0.1 , 0.1 ]
77
+ A = [0.5 0 ; 0 0.5 ]
78
+ B = [0.5 0 ; 0 0.5 ]
79
+ simulation = simulate_GAS_1_1 (LogNormal, 0.0 , ω, A, B, 13 )
80
+ gas = GAS (1 , 1 , LogNormal, 0.0 )
81
+ estimate! (gas, simulation; verbose = 1 , opt_method = ScoreDrivenModels. LBFGS (gas, 3 ))
82
+ test_coefficients_GAS_1_1 (gas, ω, A, B)
83
+ end
84
+ # @testset "Scaling = 0.5" begin
85
+ # gas = GAS(1, 1, LogNormal, 0.5)
86
+ # estimate!(gas, simulation; verbose = 1, opt_method = ScoreDrivenModels.LBFGS(gas, 3))
87
+ # test_coefficients_GAS_1_1(gas)
88
+ # end
89
+ # @testset "Scaling = 1.0" begin
90
+ # ω = [0.5, 0.5]
91
+ # A = [0.1 0; 0 0.1]
92
+ # B = [0.1 0; 0 0.1]
93
+ # simulation = simulate_GAS_1_1(LogNormal, 1.0, ω, A, B, 123)
94
+ # gas = GAS(1, 1, LogNormal, 1.0)
95
+ # estimate!(gas, simulation; verbose = 1, opt_method = ScoreDrivenModels.LBFGS(gas, 3))
96
+ # test_coefficients_GAS_1_1(gas)
97
+ # end
98
+ @testset " GAS([1, 12], [1, 12])" begin
99
+ simulation = simulate_GAS_1_12 (LogNormal, 0.0 )
100
+ gas = GAS ([1 , 12 ], [1 , 12 ], LogNormal, 0.0 )
101
+ estimate! (gas, simulation; verbose = 1 , opt_method = ScoreDrivenModels. LBFGS (gas, 3 ))
102
+ test_coefficients_GAS_1_12 (gas)
103
+ end
41
104
end
42
105
end
0 commit comments