LsqFit.jl
LsqFit.jl copied to clipboard
Allow passing in a scalar function instead of a vector function
It should be possible to pass in a scalar function to fit instead of vectorising it.
Vectorisation just confuses things and is unnecessary.
I agree. Vectorization should be the package authors' job, instead of the users'.
Or we can recommend an always-multivariable API, say, the user can always assume that the model is a multivariable function, and user write the model as like f(x::Vector{Float64}, p::Vector{Float64})=p[1]*exp(p[2]*x[1])+p[3]
.
I agree
I've found a pretty convincing case for this (if it wasn't already):
function model(x, p)
a = p[1:3:end]
m = p[2:3:end]
w = p[3:3:end]
return exp.(-(x .- m').^2 ./ (2w' .^ 2))*a
end
i.e. a normal [no pun intended] sum-of-gaussians. This returns a vector just fine when x
is input as a vector, but for scalar x
it returns a 1 element Vector
, which causes check_data_health
to fail (because of isinf(::Vector{Float64})
). The only way around this is to write a broadcastable version of the same function and doing Ref
fu. That should not be on the user.