-
Notifications
You must be signed in to change notification settings - Fork 231
Closed
Description
Dear Optim contributors,
The functor type is not supported with univariate analysis.
# optimization of functor y
using Optim
"Model parameter"
struct y
p
end
"Univariable Functor"
function (s::y)(x)
return x*s.p
end
"Multivariable Functor with array input"
function (s::y)(x_v)
return x_v[1]*s.p
end
model = y(1.0)
Optim.optimize(model, -1, 2, [1.]) #PASS
Optim.optimize(model, -1, 2, 1.) #ERROR
It reports error when using univariate input
julia> Optim.optimize(model, -1, 2, [1.]); #PASS
julia> Optim.optimize(model, -1, 2, 1.); #ERROR
ERROR: MethodError: no method matching optimize(::y, ::Int64, ::Int64, ::Float64)
Closest candidates are:
optimize(::Any, ::Any, ::Number, ::Number, ::AbstractArray{T,N} where N, ::Optim.Options; kwargs...) where T at /Users/stevenchiu/.julia/packages/Optim/TNmSw/src/multivariate/solvers/constrained/fminbox.jl:164
optimize(::Any, ::Number, ::Number, ::AbstractArray{T,N} where N; kwargs...) where T at /Users/stevenchiu/.julia/packages/Optim/TNmSw/src/multivariate/solvers/constrained/fminbox.jl:156
optimize(::Any, ::Number, ::Number, ::AbstractArray{T,N} where N, ::Optim.AbstractConstrainedOptimizer) where T at /Users/stevenchiu/.julia/packages/Optim/TNmSw/src/multivariate/solvers/constrained/fminbox.jl:160
...
Stacktrace:
[1] top-level scope at none:1
julia> Proposed changes
Univariate analysis only supports function type, while functor (object-like function) should be included
| function optimize(f::F, |
| function optimize(f::F, |
| function optimize(f::F, |
It is better to remove ::F to make those API to support functor inputs, which is already supported in multivariate analysis.
Reason to use functor type
I'm currently working on biological model and found funtor is an elegant way to integrating algorithm with common parameters.
Further Information
This issue is first addressed at Julia Community
https://discourse.julialang.org/t/functor-usage-for-optim-jl/45778/5
Thank you for reviewing this issue.
Steven Chiu
Metadata
Metadata
Assignees
Labels
No labels