Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel E Kreindler authored and Gabriel E Kreindler committed Dec 24, 2023
1 parent 6ee0fce commit 46dd3fa
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/functions_estimation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ end
Base.@kwdef mutable struct GMMOptions
path::String = ""
theta_names::Union{Vector{String}, Nothing} = nothing
optimizer::Symbol = :optim # optimizer backend: :optim or :lsqfit
optimizer::Symbol = :optim # optimizer backend: :optim or :lsqfit (LM)
optim_autodiff::Symbol = :none
optim_algo = LBFGS()
optim_opts = nothing
Expand Down Expand Up @@ -420,7 +420,8 @@ function fit_onerun(
end

if opts.optimizer == :optim

# Use the general purpose Optim.jl package for optimization (default)

# load the data
gmm_objective_loaded = theta -> gmm_objective(theta, data, mom_fn, W, weights, trace=opts.trace)

Expand Down Expand Up @@ -470,6 +471,8 @@ function fit_onerun(
idx=idx
)
elseif opts.optimizer == :lsqfit
# use the Levenberg Marquardt algorithm from LsqFit.jl for optimization
# this relies on the fact that the GMM objective function is a sum of squares

# Cholesky decomposition of W = Whalf * Whalf'
if !isa(W, UniformScaling)
Expand All @@ -485,9 +488,6 @@ function fit_onerun(
# (1 x n_moms) x (n_moms x n_moms) = (1 x n_moms)
gmm_objective_loaded = (x, theta) -> vec(mean(mom_fn(data, theta), dims=1) * Whalf)

# old
# gmm_objective_loaded = (x, theta) -> vec(mean(mom_fn(data, theta), dims=1))

# Build options programatically
m = mom_fn(data, theta0)
n_moms = size(m, 2)
Expand Down Expand Up @@ -521,13 +521,6 @@ function fit_onerun(

time_it_took = @elapsed raw_opt_results = curve_fit(lsqfit_main_args...; lsqfit_kwargs...)

# time_it_took = @elapsed result = curve_fit(myobjfunction, zeros(n_moms), zeros(n_moms),
# theta0,
# lower=theta_lower,
# upper=theta_upper,
# show_trace=true,
# maxIter=1000, autodiff=:forwarddiff)

model_fit = GMMFit(
converged = raw_opt_results.converged,
theta_hat = raw_opt_results.param,
Expand Down

0 comments on commit 46dd3fa

Please sign in to comment.