Giter Club home page Giter Club logo

Comments (10)

IlyaOrson avatar IlyaOrson commented on June 15, 2024 2

Maybe with julia v0.6 it is enough to exemplify the use of the new @. macro in the README example?

from lsqfit.jl.

mlubin avatar mlubin commented on June 15, 2024

Here's a reduced example that might reveal what's going on:

julia> x = ones(2)
2-element Array{Float64,1}:
 1.0
 1.0

julia> x^2
ERROR: MethodError: `*` has no method matching *(::Array{Float64,1}, ::Array{Float64,1})
...

from lsqfit.jl.

kzapfe avatar kzapfe commented on June 15, 2024

Yes, exactly that is it, but it is going internally on the curve_fit routine and I seem to not be able to make it go away. I actually have a simpler example (adjusting a degree 2 polynomial) and it seems to trigger the same problem. Maybe I am not understanding the syntaxis right...

 model(x,p)=p[3]+p[2]*x+p[1]*x*x
    ydata=map(x->log(x),yys)
    rara=curve_fit(model,xxs,ydata, [0,0,0])

returns the same error.

from lsqfit.jl.

davidssmith avatar davidssmith commented on June 15, 2024

@mlubin was just being nice. He was trying to tell you the bug is on your end. When you define the function, you need to use elemental operations like .* because curve_fit internally is evaluating the function for vector values.

Specifically, you need to write

model(x,p)=(1/(sqrt(2*pi)*p[1])) * exp(-( (x-p[2])/(sqrt(2)*p[1])) .^2)

Note the extra period before the power.

from lsqfit.jl.

kzapfe avatar kzapfe commented on June 15, 2024

Oh, I know he was nice, anyone who responds is doing good. Was I rude? in that case my apologies, probably is because I write a bit rough. Going back to the issue, yes, it seems to be that I don't understand the point syntaxis in Julia well. How is that p[1] is NOT an element of an array? I put the point in every operator now and it works, but I still don't understand what it is supposed to mean (well I have another error now...)

from lsqfit.jl.

davidssmith avatar davidssmith commented on June 15, 2024

No, you were not rude. Sorry if I implied that.

p[1] is an element of an array, but in the context of the evaluation of the model function, it is a scalar. The argument x of the function appears to be a scalar to you, but it is a vector inside curve_fit.

Here is a simple example.

f(x,p) = x*p[1] + p[2]
f(1,[2,3]) = 1*2 + 3 = 5
f([1,2,3],[2,3]) = [5,7,9]

You are thinking of the function like the second line, while inside curve_fit it is being called like in the third line.

from lsqfit.jl.

CaBeOli avatar CaBeOli commented on June 15, 2024

I had this problem, but I didn't understand how to use the point yet. I put in diferente places but the ERROR continuing coming. Someone can help or say where I can find a tutorial about that?
My code:

`model(t, p) = ((p[1]*p[2])/(sqrt((1/sqrt(p[3]p[4]))^2-(p[2]/(2p[3]))^2)*p[3]))*sin(sqrt((1/sqrt(p[3]p[4]))^2-(p[2]/(2p[3]))^2)*t)exp(-(p[2]/(2p[3]))*t)

fit = curve_fit(model, time, Volts, [Vm, R, L, C])`

from lsqfit.jl.

blakejohnson avatar blakejohnson commented on June 15, 2024

@CaBeOli, when your model is evaluated, the t is a Vector{Float64}. So, anywhere you have a t on both sides of a binary operator, you should use the element-wise syntax. In your case, this should be sufficient:

model(t, p) = ((p[1]*p[2])/(sqrt((1/sqrt(p[3]p[4]))^2 -
              (p[2]/(2p[3]))^2)*p[3])) * sin(sqrt((1/sqrt(p[3]p[4]))^2-(p[2]/(2p[3]))^2)*t)
                                      .* exp(-(p[2]/(2p[3]))*t)

from lsqfit.jl.

blakejohnson avatar blakejohnson commented on June 15, 2024

Maybe the more appropriate question if whether we should modify LsqFit.jl to not require the user to write their model in a vectorized form?

from lsqfit.jl.

pkofod avatar pkofod commented on June 15, 2024

Maybe with julia v0.6 it is enough to exemplify the use of the new @. macro in the README example?

I agree.

from lsqfit.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.