JuliaAstro / JuliaAstro/PSFModels.jl
[feature] Optimize does not work on `Colorant{T,1}`
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 11
- Forks
- 3
- Avg merge
- 13h 59m
- Merged PRs (30d)
- 4
Description
When trying to fit an image of a bead, it is most commonly represented as an array of colorants. The most likely for this use in particular is for it to be some subtype of AbstractGray. But when trying to fit some kind of Gray array, there it throws:
ERROR: MethodError: no method matching DiffResults.DiffResult(::Gray{Float64}, ::Vector{Float64})
Closest candidates are:
DiffResults.DiffResult(::Union{Number, AbstractArray}, ::Union{Number, AbstractArray}...) at ~/.julia/packages/DiffResults/wASAy/src/DiffResults.jl:52
Stacktrace:
[1] (::NLSolversBase.var"#14#18"{Gray{Float64}, PSFModels.var"#_loss#42"{NamedTuple{(), Tuple{}}, typeof(abs2), Float64, typeof(gaussian), Matrix{Gray{Float64}}, Tuple{Int64, Int64}, Tuple{Int64, Int64}, CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, NTuple{4, Symbol}}, ForwardDiff.GradientConfig{ForwardDiff.Tag{PSFModels.var"#_loss#42"{NamedTuple{(), Tuple{}}, typeof(abs2), Float64, typeof(gaussian), Matrix{Gray{Float64}}, Tuple{Int64, Int64}, Tuple{Int64, Int64}, CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, NTuple{4, Symbol}}, Gray{Float64}}, Gray{Float64}, 5, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PSFModels.var"#_loss#42"{NamedTuple{(), Tuple{}}, typeof(abs2), Float64, typeof(gaussian), Matrix{Gray{Float64}}, Tuple{Int64, Int64}, Tuple{Int64, Int64}, CartesianIndices{2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}, NTuple{4, Symbol}}, Gray{Float64}}, Gray{Float64}, 5}}}})(out::Vector{Float64}, x::Vector{Gray{Float64}})
@ NLSolversBase ~/.julia/packages/NLSolversBase/cfJrN/src/objective_types/oncedifferentiable.jl:69
[2] value_gradient!!(obj::NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Gray{Float64}}}, x::Vector{Gray{Float64}})
@ NLSolversBase ~/.julia/packages/NLSolversBase/cfJrN/src/interface.jl:82
[3] initial_state(method::Optim.LBFGS{Nothing, LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}, options::Optim.Options{Float64, Nothing}, d::NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Gray{Float64}}}, initial_x::Vector{Gray{Float64}})
@ Optim ~/.julia/packages/Optim/wFOeG/src/multivariate/solvers/first_order/l_bfgs.jl:164
[4] optimize(d::NLSolversBase.OnceDifferentiable{Float64, Vector{Float64}, Vector{Gray{Float64}}}, initial_x::Vector{Gray{Float64}}, method::Optim.LBFGS{Nothing, LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}, options::Optim.Options{Float64, Nothing})
@ Optim ~/.julia/packages/Optim/wFOeG/src/multivariate/optimize/optimize.jl:36
[5] optimize(f::Function, initial_x::Vector{Gray{Float64}}, method::Optim.LBFGS{Nothing, LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}, options::Optim.Options{Float64, Nothing}; inplace::Bool, autodiff::Symbol)
@ Optim ~/.julia/packages/Optim/wFOeG/src/multivariate/optimize/interface.jl:142
[6] fit(model::typeof(gaussian), params::NamedTuple{(:x, :y, :fwhm, :amp), Tuple{Float64, Float64, Tuple{Int64, Int64}, Int64}}, image::Matrix{Gray{Float64}}, inds::Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}; func_kwargs::NamedTuple{(), Tuple{}}, loss::typeof(abs2), alg::Optim.LBFGS{Nothing, LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}, maxfwhm::Float64, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ PSFModels ~/.julia/packages/PSFModels/G3WuK/src/fitting.jl:99
[7] fit (repeats 2 times)
@ ~/.julia/packages/PSFModels/G3WuK/src/fitting.jl:76 [inlined]
[8] top-level scope
@ REPL[167]:1
Could there be definition such as:
function fit(..., image::AbstractArray{T}, ...) where {T<:AbstractGray}
fit(..., Real.(image), ...)
end
Do you think it is a good idea?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at fit in fitting.jl:76 and fitting.jl:99, then reproduce the reported optimize failure with a Matrix{Gray{Float64}}. Determine whether the fit entry point should support AbstractGray inputs as proposed, and verify that fitting such an image completes without the DiffResult MethodError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100