JuliaNLSolvers / Optim.jl

Optimization functions for Julia
Other
1.13k stars 218 forks source link

f_trace #687

Open oschub opened 6 years ago

oschub commented 6 years ago

I'm using LBFGS in combination with Fminbox but the values stored in f_trace are not the actual function values of f, most likely - as @pkofod pointed out - due to the barrier term. This is with Julia v1.0.1. and Optim v0.17.1.

MWE:

using Optim

function f(x)
    return sum(x.^2)
end

function g!(storage, x)
    storage[1] = 2*x[1]
    storage[2] = 2*x[2] 
end

x0 = [10.0, 10.0]
LB = [1.0, 2.0]
UB = [100.0, 100.0]

OptimOptions = Optim.Options(
    outer_iterations = 1,
    iterations = 100,
    store_trace = true,
    show_trace = false)

res = optimize(f, g!, LB, UB, x0, Fminbox(LBFGS()), OptimOptions);

Optim.f_trace(res)
Optim.minimum(res)
f(Optim.minimizer(res))
julia> Optim.f_trace(res)
13-element Array{Float64,1}:
 197.9443170901146
   7.326300276088382
   6.480540749464274
   5.239209399086917
   5.0297684353120875
   4.821652592447441
   4.8029328573378125
   4.796234828248983
   4.795126326889748
   4.795110888289186
   4.7951106164524635
   4.795110616447711
   4.795110616447711

julia> Optim.minimum(res)
5.3028559230540635

julia> f(Optim.minimizer(res))
sum(x .^ 2) = 5.3028559230540635
5.3028559230540635
pkofod commented 5 years ago

Thanks for the write up. I haven't had too much time for Julia-things these past months, but I'll get around to this at some point!