Comments (10)
Maybe with julia v0.6 it is enough to exemplify the use of the new @. macro in the README example?
from lsqfit.jl.
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.
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.
@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.
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.
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.
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.
@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.
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.
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)
- Fit parameters order of magnitude different HOT 6
- Forcing one of the parameters to a specific value HOT 4
- Named parameters
- Progress bar HOT 1
- Support for NTuple inputs and outputs
- Fitting of 2D data is broken HOT 1
- Exports from `StatsBase`
- Release HOT 5
- n_buffer has wrong dimensions HOT 2
- More documentation issues HOT 1
- Trust - Region
- No method matching curve_fit HOT 1
- (1) hoping you won't remove lmfit, and (2) seeking help re Geodesic acceleration HOT 2
- Citing LsqFit.jl HOT 1
- Support for CUDA HOT 4
- Support for geodesic accelaration with vector function
- Feature request: Seeking stopval or callback, to give greater control over stopping criteria HOT 1
- Weighted LSQfit fails, Message: DomainError [...] sqrt will only return a complex result if called with a complex argument. HOT 4
- Proposal: Add more verbose interface HOT 3
- `stderror` throws `LinearAlgebra.LAPACKException(1)` with weighted least squares fitting. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lsqfit.jl.