Skip to content

Commit 9b962c8

Browse files
Maximize mean loglikelihood (#114)
* Update dependencies * Maximize the mean llk * Remove Beta distribution
1 parent 0e180ac commit 9b962c8

File tree

9 files changed

+15
-91
lines changed

9 files changed

+15
-91
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1111
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1212

1313
[compat]
14-
julia = "1"
1514
Distributions = "0.23"
16-
Optim = "0.20"
15+
Optim = "0.20, 0.21, 0.22, 1.2"
1716
SpecialFunctions = "0.8"
17+
julia = "1"
1818

1919
[extras]
2020
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"

src/MLE.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function fit(gas::Model{D, T}, y::Vector{T};
120120
opt_method.initial_points[i])
121121
opt_result = optimize(func, opt_method, verbose, i)
122122
update_aux_estimation!(aux_est, func, opt_result)
123-
verbose >= 1 && 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 * length(y))")
124124
catch err
125125
println(err)
126126
verbose >= 1 && println("Round $i diverged")
@@ -133,6 +133,8 @@ function fit(gas::Model{D, T}, y::Vector{T};
133133
end
134134

135135
best_llk, best_seed = findmax(aux_est.loglikelihood)
136+
# We optimize the average loglikelihood inside log_lik
137+
best_llk = best_llk * length(y)
136138
num_hessian = aux_est.numerical_hessian[best_seed]
137139
coefs = aux_est.psi[best_seed]
138140
aic = AIC(n_unknowns, best_llk)

src/ScoreDrivenModels.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ include("opt_methods/NelderMead.jl")
3131
# Distributions
3232
include("distributions/non_native_dists.jl")
3333
include("distributions/common_interface.jl")
34-
include("distributions/beta.jl")
3534
include("distributions/betalocationscale.jl")
3635
include("distributions/exponential.jl")
3736
include("distributions/gamma.jl")

src/distributions/beta.jl

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/distributions/betalocationscale.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ function score!(score_til::Matrix{T}, y::T, ::Type{BetaLocationScale}, param::Ma
2727
return
2828
end
2929

30-
function fisher_information!(aux::AuxiliaryLinAlg{T}, ::Type{BetaLocationScale}, param::Matrix{T}, t::Int) where T
31-
return error("Fisher information not implemented for BetaLocationScale distribution.")
32-
end
33-
3430
function log_likelihood(::Type{BetaLocationScale}, y::Vector{T}, param::Matrix{T}, n::Int) where T
3531
loglik = 0.0
3632
for t in 1:n

src/distributions/common_interface.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Currently supported distributions
22
const DISTS = [
3-
Beta,
43
BetaLocationScale,
54
Exponential,
65
Gamma,
@@ -14,10 +13,7 @@ const DISTS = [
1413
Weibull
1514
]
1615

17-
export Beta,
18-
BetaLocationScale,
19-
Chi,
20-
Chisq,
16+
export BetaLocationScale,
2117
Exponential,
2218
Gamma,
2319
LogitNormal,

src/model.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,5 @@ function log_lik(psitilde::Vector{T}, y::Vector{T}, gas::Model{D, T},
168168
params = score_driven_recursion(gas, y; initial_params = initial_params)
169169
end
170170

171-
return log_likelihood(D, y, params, n)
171+
return log_likelihood(D, y, params, n) / length(y)
172172
end

test/test_diagnostics.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
@testset "quantile and pearson residuals" begin
22
n = 10^3
33
lags = 1
4-
normality_quantile_and_pearson_residuals(Beta, n, lags)
54
normality_quantile_and_pearson_residuals(Normal, n, lags)
65
normality_quantile_and_pearson_residuals(LogNormal, n, lags)
76
normality_quantile_and_pearson_residuals(Gamma, n, lags)

test/test_estimate.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
@testset "Estimate" begin
2-
@testset "Beta" begin
2+
@testset "Normal" begin
33
ω = [0.1, 0.1]
44
A = [0.5 0; 0 0.5]
55
B = [0.5 0; 0 0.5]
6-
simulation = simulate_GAS_1_1(Beta, 0.0, ω, A, B, 1)
6+
simulation = simulate_GAS_1_1(Normal, 0.0, ω, A, B, 1)
77
@testset "Estimation by passing number of initial_points" begin
88
# LBFGS
9-
gas = Model(1, 1, Beta, 0.0)
9+
gas = Model(1, 1, Normal, 0.0)
1010
fit!(gas, simulation; verbose = 2, opt_method = ScoreDrivenModels.LBFGS(gas, 3))
1111
test_coefficients_GAS_1_1(gas, ω, A, B)
1212
# NelderMead
13-
gas = Model(1, 1, Beta, 0.0)
13+
gas = Model(1, 1, Normal, 0.0)
1414
fit!(gas, simulation; verbose = 2, opt_method = ScoreDrivenModels.NelderMead(gas, 3))
1515
test_coefficients_GAS_1_1(gas, ω, A, B)
1616
# IPNewton
17-
gas = Model(1, 1, Beta, 0.0)
17+
gas = Model(1, 1, Normal, 0.0)
1818
fit!(gas, simulation; verbose = 2, opt_method = ScoreDrivenModels.IPNewton(gas, 3))
1919
test_coefficients_GAS_1_1(gas, ω, A, B)
2020
end
2121
@testset "Estimation by passing initial_points" begin
2222
# LBFGS
23-
gas = Model(1, 1, Beta, 0.0)
23+
gas = Model(1, 1, Normal, 0.0)
2424
initial_points = [[0.1, 0.1, 0.5, 0.5, 0.5, 0.5]]
2525
fit!(gas, simulation; verbose = 1, opt_method = ScoreDrivenModels.LBFGS(gas, initial_points))
2626
test_coefficients_GAS_1_1(gas, ω, A, B)
2727
# NelderMead
28-
gas = Model(1, 1, Beta, 0.0)
28+
gas = Model(1, 1, Normal, 0.0)
2929
initial_points = [[0.1, 0.1, 0.5, 0.5, 0.5, 0.5]]
3030
fit!(gas, simulation; verbose = 1, opt_method = ScoreDrivenModels.NelderMead(gas, initial_points))
3131
test_coefficients_GAS_1_1(gas, ω, A, B)
3232
# IPNewton
33-
gas = Model(1, 1, Beta, 0.0)
33+
gas = Model(1, 1, Normal, 0.0)
3434
initial_points = [[0.1, 0.1, 0.5, 0.5, 0.5, 0.5]]
3535
fit!(gas, simulation; verbose = 1, opt_method = ScoreDrivenModels.IPNewton(gas, initial_points))
3636
test_coefficients_GAS_1_1(gas, ω, A, B)

0 commit comments

Comments
 (0)