@@ -2,7 +2,7 @@ export fit, fit!, fit_stats
2
2
3
3
const DEFAULT_INITIAL_PARAM = NaN .* ones (1 , 1 )
4
4
const DEFAULT_NUM_SEEDS = 3
5
- const DEFAULT_VERBOSE = 0
5
+ const DEFAULT_VERBOSE = 1
6
6
const VARIANCE_ZERO = 1e-10
7
7
8
8
struct Fitted{D <: Distribution , T <: AbstractFloat }
@@ -96,6 +96,7 @@ function fit(gas::Model{D, T}, y::Vector{T};
96
96
opt_method:: AbstractOptimizationMethod = NelderMead (gas, DEFAULT_NUM_SEEDS),
97
97
verbose:: Int = DEFAULT_VERBOSE) where {D, T}
98
98
99
+ verbose in [0 , 1 , 2 , 3 ] || throw (ErrorException, " verbose argument must be in [0, 1, 2, 3]" )
99
100
# Number of initial_points and number of params to estimate
100
101
n_initial_points = length (opt_method. initial_points)
101
102
n = length (y)
@@ -114,18 +115,20 @@ function fit(gas::Model{D, T}, y::Vector{T};
114
115
115
116
for i = 1 : n_initial_points
116
117
try
117
- func = TwiceDifferentiable (psi_tilde -> log_lik (psi_tilde, y, gas_fit, initial_params, unknowns, n), opt_method. initial_points[i])
118
+ func = TwiceDifferentiable (psi_tilde -> log_lik (psi_tilde, y, gas_fit,
119
+ initial_params, unknowns, n),
120
+ opt_method. initial_points[i])
118
121
opt_result = optimize (func, opt_method, verbose, i)
119
122
update_aux_estimation! (aux_est, func, opt_result)
120
- println (" Round $i of $n_initial_points - Log-likelihood: $(- opt_result. minimum) " )
123
+ verbose >= 1 && println (" Round $i of $n_initial_points - Log-likelihood: $(- opt_result. minimum) " )
121
124
catch err
122
125
println (err)
123
- println (" Round $i diverged" )
126
+ verbose >= 1 && println (" Round $i diverged" )
124
127
end
125
128
end
126
129
127
130
if isempty (aux_est. loglikelihood)
128
- println (" No initial point converged." )
131
+ verbose >= 1 && println (" No initial point converged." )
129
132
return
130
133
end
131
134
@@ -135,12 +138,11 @@ function fit(gas::Model{D, T}, y::Vector{T};
135
138
aic = AIC (n_unknowns, best_llk)
136
139
bic = BIC (n, n_unknowns, best_llk)
137
140
138
- if verbose >= 1
141
+ if verbose >= 2
139
142
println (" \n Best optimization result:" )
140
143
println (aux_est. opt_result[best_seed])
141
144
end
142
145
143
- println (" Finished!" )
144
146
return Fitted {D, T} (n, unknowns, aic, bic, best_llk, coefs, num_hessian)
145
147
end
146
148
0 commit comments