Greetings!
I am trying to perform a multivariate nonlinear regression (2D curve fitting). Let’s assume my data has the following form:
function multimodel(x, p)
a = x[1]
t = x[2]
α = p[1]
τ = p[2]
(α .* a) * (τ .* (t.^2)')
end
t = -1.0:0.1:1.0 |> collect
a = 0.0:0.1:1.0 |> collect
p = [0.9,1.1]
x = [a, t]
y = multimodel(x, p) + 0.1 * rand(length(a), length(t))
using PyPlot
mesh(t, a, y)
Which gives the following noisy data:
I tried fitting using LsqFit
:
using LsqFit
fit = curve_fit(multimodel, x, y, [1.0, 1.0])
which results in
MethodError: no method matching isinf(::Array{Float64,1})
I have to admit that that’s not how the LsqFit
documentation says how their multivariate regression works. In there it states:
There’s nothing inherently different if there are more than one variable entering the problem. We just need to specify the columns appropriately in our model specification:
@. multimodel(x, p) = p[1]*exp(-x[:, 1]*p[2]+x[:, 2]*p[3])
But I don’t quite understand that because the arrays of the two independent variables must have the same length? And I don’t get a 2D array out of that function.
I also tried modelling my problem with JuMP
but I didn’t get very far there.
Does anyone have some experience with this kind of curve fitting?