Skip to content

Commit

Permalink
make param update in optSlices optional
Browse files Browse the repository at this point in the history
  • Loading branch information
floswald committed Feb 11, 2019
1 parent bb759c2 commit fcea0f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
12 changes: 0 additions & 12 deletions src/mopt/econometrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@ function FD_gradient(m::MProb,p::Union{Dict,OrderedDict};step_perc=0.01)
D[row,:] = v
end

# row = 0
# @showprogress "Computing derivative..." for (k,v) in p
# row += 1
# h = rs[k] * step_perc
# pp = deepcopy(p)
# pp[k] = v + h
# # println("changing $k from $v to $(pp[k]) by step $h")
# xx = evaluateObjective(m,pp)
# smm = collect(values(filter((x,y)->in(x,mnames),xx.simMoments)))
# D[row,:] = (smm .- gp) / h
# end

return D

end
Expand Down
14 changes: 8 additions & 6 deletions src/mopt/slices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ end
Computes [`Slice`](@ref)s of an [`MProb`](@ref) and keeps the best value from each slice. This implements a naive form of gradient descent in that it optimizes wrt to one direction at a time, keeping the best value. It's naive because it does a grid search in that direction. The grid size shrinks, however, at a rate `update`.
"""
function optSlices(m::MProb,npoints::Int;parallel=false,tol=1e-5,update=0.4,filename="trace.jld2")
function optSlices(m::MProb,npoints::Int;parallel=false,tol=1e-5,update=nothing,filename="trace.jld2")

t0 = time()
# res = Slice(m.initial_value, m.moments)
Expand Down Expand Up @@ -221,12 +221,14 @@ function optSlices(m::MProb,npoints::Int;parallel=false,tol=1e-5,update=0.4,file

# update search ranges
# maintain range boundaries
for (k,v) in bestp
r = (ranges[k][:ub] - ranges[k][:lb])/2
ranges[k][:lb] = max(v - update * r,ranges[k][:lb])
ranges[k][:ub] = min(v + update * r,ranges[k][:ub])
if update!=nothing
for (k,v) in bestp
r = (ranges[k][:ub] - ranges[k][:lb])/2
ranges[k][:lb] = max(v - update * r,ranges[k][:lb])
ranges[k][:ub] = min(v + update * r,ranges[k][:ub])
end
@debug(logger,"search ranges updated to $ranges")
end
@debug(logger,"search ranges updated to $ranges")

# println(cur_param)
# println(bestp)
Expand Down

0 comments on commit fcea0f3

Please sign in to comment.