@@ -38,7 +38,7 @@ function results(f::Fitted{D, T}) where {D, T}
38
38
estim_results = eval_coefs_stats (f)
39
39
np = length (f. unknowns)
40
40
jarquebera_p_value = pvalue (JarqueBeraTest (f. quantile_residuals))
41
- return EstimationStats {D, T} (f. num_obs, f. llk, f. aic, f. bic, np,
41
+ return EstimationStats {D, T} (f. num_obs, f. llk, f. aic, f. bic, np,
42
42
jarquebera_p_value, estim_results)
43
43
end
44
44
@@ -47,7 +47,7 @@ function eval_coefs_stats(f::Fitted{D, T}) where {D, T}
47
47
inv_H = inv (f. numerical_hessian)
48
48
vars = diag (inv_H)
49
49
for i in eachindex (vars)
50
- if vars[i] <= VARIANCE_ZERO
50
+ if vars[i] <= VARIANCE_ZERO
51
51
vars[i] = VARIANCE_ZERO
52
52
end
53
53
end
@@ -70,7 +70,7 @@ mutable struct AuxEstimation{T <: AbstractFloat}
70
70
function AuxEstimation {T} () where T
71
71
return new (
72
72
Vector {Vector{T}} (undef, 0 ), # psi
73
- Vector {Matrix{T}} (undef, 0 ),
73
+ Vector {Matrix{T}} (undef, 0 ),
74
74
Vector {T} (undef, 0 ), # loglikelihood
75
75
Vector {Optim.OptimizationResults} (undef, 0 ) # opt_result
76
76
)
87
87
88
88
function update_aux_estimation! (aux_est:: AuxEstimation{T} , func:: Optim.TwiceDifferentiable ,
89
89
opt_result:: Optim.OptimizationResults ) where T
90
-
90
+
91
91
push! (aux_est. numerical_hessian, Optim. hessian! (func, opt_result. minimizer))
92
92
push! (aux_est. psi, opt_result. minimizer)
93
93
push! (aux_est. loglikelihood, - opt_result. minimum)
94
94
push! (aux_est. opt_result, opt_result)
95
95
return
96
96
end
97
97
98
- function fit! (gas:: Model {D, T} , y:: Vector{T} ;
98
+ function fit! (gas:: ScoreDrivenModel {D, T} , y:: Vector{T} ;
99
99
initial_params:: Matrix{T} = DEFAULT_INITIAL_PARAM,
100
100
opt_method:: AbstractOptimizationMethod = NelderMead (gas, DEFAULT_NUM_SEEDS),
101
101
verbose:: Int = DEFAULT_VERBOSE,
@@ -111,23 +111,23 @@ function fit!(gas::Model{D, T}, y::Vector{T};
111
111
# Number of initial_points and number of params to estimate
112
112
n_initial_points = length (opt_method. initial_points)
113
113
n = length (y)
114
-
114
+
115
115
unknowns = find_unknowns (gas)
116
116
n_unknowns = length (unknowns)
117
-
117
+
118
118
# Check if the model has no unknowns
119
119
check_model_estimated (n_unknowns) && return gas
120
120
121
121
# Create a copy of the model to estimate
122
122
gas_fit = deepcopy (gas)
123
-
123
+
124
124
# optimize for each initial_point
125
125
aux_est = AuxEstimation {T} ()
126
126
127
127
for i = 1 : n_initial_points
128
- try
129
- func = TwiceDifferentiable (psi_tilde -> log_lik (psi_tilde, y, gas_fit,
130
- initial_params, unknowns, n),
128
+ try
129
+ func = TwiceDifferentiable (psi_tilde -> log_lik (psi_tilde, y, gas_fit,
130
+ initial_params, unknowns, n),
131
131
opt_method. initial_points[i])
132
132
opt_result = optimize (func, opt_method, verbose, i, time_limit_sec)
133
133
update_aux_estimation! (aux_est, func, opt_result)
@@ -141,7 +141,7 @@ function fit!(gas::Model{D, T}, y::Vector{T};
141
141
end
142
142
end
143
143
144
- if isempty (aux_est. loglikelihood)
144
+ if isempty (aux_est. loglikelihood)
145
145
verbose >= 1 && println (" No initial point converged." )
146
146
return
147
147
end
@@ -162,9 +162,9 @@ function fit!(gas::Model{D, T}, y::Vector{T};
162
162
fill_psitilde! (gas, coefs, unknowns)
163
163
164
164
# Calculate pearson residuals
165
- pearson_res = isnan (initial_params[1 ]) ?
165
+ pearson_res = isnan (initial_params[1 ]) ?
166
166
quantile_residuals (y, gas) :
167
167
quantile_residuals (y, gas; initial_params = initial_params)
168
168
169
169
return Fitted {D, T} (n, unknowns, aic, bic, best_llk, coefs, num_hessian, pearson_res)
170
- end
170
+ end
0 commit comments