STOR-i / GaussianProcesses.jl

A Julia package for Gaussian Processes
https://stor-i.github.io/GaussianProcesses.jl/latest/
Other
308 stars 53 forks source link

Specifying number of iterations in `optimize!` #174

Closed laserkelvin closed 3 years ago

laserkelvin commented 3 years ago

I am having trouble specifying the maximum number of iterations in optimize!; by running:

optimize!(gp; options=Optim.Options(iterations=50))

should work, as it should get passed as a kwarg to optimize. Instead, it returns:

MethodError: no method matching optimize(::NLSolversBase.OnceDifferentiable{Float64,Array{Float64,1},Array{Float64,1}}, ::Array{Float64,1}, ::Optim.LBFGS{Nothing,LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Optim.var"#15#17"}, ::Optim.Options{Float64,Nothing}; options=                x_abstol = 0.0
                x_reltol = 0.0
                f_abstol = 0.0
                f_reltol = 0.0
                g_abstol = 1.0e-8
                g_reltol = 1.0e-8
          outer_x_abstol = 0.0
          outer_x_reltol = 0.0
          outer_f_abstol = 0.0
          outer_f_reltol = 0.0
          outer_g_abstol = 1.0e-8
          outer_g_reltol = 1.0e-8
           f_calls_limit = 0
           g_calls_limit = 0
           h_calls_limit = 0
       allow_f_increases = true
 allow_outer_f_increases = true
        successive_f_tol = 1
              iterations = 50
        outer_iterations = 1000
             store_trace = false
           trace_simplex = false
              show_trace = false
          extended_trace = false
              show_every = 1
                callback = nothing
              time_limit = NaN
)
Closest candidates are:
  optimize(::D, ::Tx, ::M, ::Optim.Options{T,TCallback}) where {D<:NLSolversBase.AbstractObjective, M<:Optim.AbstractOptimizer, Tx<:AbstractArray, T, TCallback} at /home/kelvin/.julia/packages/Optim/auGGa/src/multivariate/optimize/optimize.jl:33 got unsupported keyword argument "options"
  optimize(::D, ::Tx, ::M, ::Optim.Options{T,TCallback}, !Matched::Any) where {D<:NLSolversBase.AbstractObjective, M<:Optim.AbstractOptimizer, Tx<:AbstractArray, T, TCallback} at /home/kelvin/.julia/packages/Optim/auGGa/src/multivariate/optimize/optimize.jl:33 got unsupported keyword argument "options"
  optimize(::Any, ::AbstractArray, ::Optim.AbstractOptimizer, ::Optim.Options; inplace, autodiff) at /home/kelvin/.julia/packages/Optim/auGGa/src/multivariate/optimize/interface.jl:141 got unsupported keyword argument "options"
  ...

Stacktrace:
 [1] kwerr(::NamedTuple{(:options,),Tuple{Optim.Options{Float64,Nothing}}}, ::Function, ::NLSolversBase.OnceDifferentiable{Float64,Array{Float64,1},Array{Float64,1}}, ::Array{Float64,1}, ::Optim.LBFGS{Nothing,LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Optim.var"#15#17"}, ::Optim.Options{Float64,Nothing}) at ./error.jl:157
 [2] optimize!(::GPE{LinearAlgebra.Adjoint{Float64,Array{Float64,1}},Array{Float64,1},MeanZero,SEIso{Float64},GaussianProcesses.FullCovariance,GaussianProcesses.IsotropicData{Array{Float64,2}},PDMats.PDMat{Float64,Array{Float64,2}},GaussianProcesses.Scalar{Float64}}, ::Optim.LBFGS{Nothing,LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Optim.var"#15#17"}; domean::Bool, kern::Bool, noise::Bool, lik::Bool, meanbounds::Nothing, kernbounds::Nothing, noisebounds::Nothing, likbounds::Nothing, kwargs::Base.Iterators.Pairs{Symbol,Optim.Options{Float64,Nothing},Tuple{Symbol},NamedTuple{(:options,),Tuple{Optim.Options{Float64,Nothing}}}}) at /home/kelvin/.julia/packages/GaussianProcesses/ccdmQ/src/optimize.jl:28
 [3] top-level scope at In[107]:1

AFAIK this should work from PR #50. I couldn't find anything in the docs, and based on how I interpret the source for both GaussianProcesses and Optim, this should work. I'm still a novice in Julia, and I could just be making a very silly mistake—hopefully someone can point that out to me.

optimize! works, as long as the options kwarg is not specified: I've tried doing optimize!(gp; options=Optim.Options()) which just produces the default options.

fredcallaway commented 3 years ago

I'm using v0.12.3 and I found that this works:

optimize!(gp, Optim.Options(iterations=10))
maximerischard commented 3 years ago

That's right, the Optim options are not a keyword argument, they're passed as the last argument to the optimize! method. Thank you @fredcallaway.