-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinitial_params.jl
64 lines (55 loc) · 2.21 KB
/
initial_params.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
export stationary_initial_params_tilde, stationary_initial_params, dynamic_initial_params
"""
stationary_initial_param_tilde(gas::ScoreDrivenModel{D, T}) where {D, T}
#TODO
"""
function stationary_initial_params_tilde(gas::ScoreDrivenModel{D, T}) where {D, T}
biggest_lag = number_of_lags(gas)
n_params = num_params(D)
initial_params_tilde = Matrix{T}(undef, biggest_lag, n_params)
for t in 1:biggest_lag, p in 1:n_params
# ω/(1 - sum(B[p, p]))
initial_params_tilde[t, p] = gas.ω[p]/(1 - sum(v[p, p] for (k, v) in gas.B))
end
return initial_params_tilde
end
"""
stationary_initial_params(gas::ScoreDrivenModel{D, T}) where {D, T}
#TODO
"""
function stationary_initial_params(gas::ScoreDrivenModel{D, T}) where {D, T}
biggest_lag = number_of_lags(gas)
n_params = num_params(D)
initial_params_tilde = Matrix{T}(undef, biggest_lag, n_params)
initial_params = Matrix{T}(undef, biggest_lag, n_params)
for t in 1:biggest_lag, p in 1:n_params
# ω/(1 - sum(B[p, p]))
initial_params_tilde[t, p] = gas.ω[p]/(1 - sum(v[p, p] for (k, v) in gas.B))
unlink!(initial_params, D, initial_params_tilde, t)
end
return initial_params
end
"""
dynamic_initial_params
#TODO This is an heuristic! only seen in some phd thesis.
"""
function dynamic_initial_params(obs::Vector{T}, gas::ScoreDrivenModel{D, T}) where {D, T}
# Take the biggest lag
biggest_lag = ScoreDrivenModels.number_of_lags(gas)
# Allocate memory
initial_params = Matrix{T}(undef, biggest_lag, ScoreDrivenModels.num_params(D))
obs_separated = Vector{Vector{T}}(undef, biggest_lag)
# Loop to fit mle in every component of seasonality
len = length(obs)
for i in 1:biggest_lag
# Indexes of a component of seasonality i.e. of january in a annual seasonality
idx = collect(i:biggest_lag:len)
# Fit MLE in the observations
dist = fit_mle(D, obs[idx])
# Adequate to the ScoreDrivenModels standard
# In Distributions Normal is \mu and \sigma
# In ScoreDrivenModels Normal is \mu and \sigma^2
initial_params[i, :] = permutedims([ScoreDrivenModels.params_sdm(dist)...])
end
return initial_params
end