Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing in a scalar function instead of a vector function #145

Open
dpsanders opened this issue Feb 12, 2020 · 4 comments · May be fixed by #202
Open

Allow passing in a scalar function instead of a vector function #145

dpsanders opened this issue Feb 12, 2020 · 4 comments · May be fixed by #202

Comments

@dpsanders
Copy link

It should be possible to pass in a scalar function to fit instead of vectorising it.

@dpsanders dpsanders changed the title All passing in a scalar function instead of a vector function Allow passing in a scalar function instead of a vector function May 4, 2020
@dpsanders
Copy link
Author

Vectorisation just confuses things and is unnecessary.

@zhaiyusci
Copy link

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].

@pkofod
Copy link
Member

pkofod commented Jun 9, 2021

I agree

@gustaphe
Copy link

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.

@gustaphe gustaphe linked a pull request Oct 25, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants