help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What to give as "real column vector of initial parameters" to nonlin


From: Doron Behar
Subject: Re: What to give as "real column vector of initial parameters" to nonlin_curvefit?
Date: Thu, 11 Jun 2020 20:20:52 +0300

On Thu, Jun 11, 2020 at 04:09:03PM +0200, Pavel Hofman wrote:
OK I think I understand.

I think it should be possible to explain this better just as both of you
did here, but in the docs... But thanks anyway :+1:.

Since I'm already here, perhaps you could help me a bit further:

I set this parametric function:

    harmonic_param_func = @(p, t) p(1) * exp(-t/(2 * p(2))) * cos(p(3)*t + p(4))

And I call nonlin_curvefit like this:

    [p, fy, cvg, outp] = nonlin_curvefit( ...
        harmonic_param_func, [ ...
            guessed_max_amplitude; ...
            guessed_tau; ...
            guessed_period; ...
            guessed_phase
        ], ...
        counts, times ...
    );

Where the variables guessed_* are corresponding values I think may be a
good starting guess for the fitting algorithm. But I get this error when
I call it as so:

    error: NA: invalid class name
    error: called from
        __nonlin_residmin__ at line 212 column 21
        nonlin_curvefit at line 83 column 22
        ./harmonic-oscillator.m at line 50 column 21

And if I use `,` instead of `;` I get the error:

    error: initial parameters must be either a structure or a column vector
    error: called from
        __nonlin_residmin__ at line 101 column 7
        nonlin_curvefit at line 83 column 22
        ./harmonic-oscillator.m at line 50 column 21

Maybe I'm just not fluent yet in octave's / matlab's data types. But,
the 2nd error intrigued me more: Is it possible to use a struct where my
`p` is, in the fitting function? If so that's sound like another
undocumented detail of the function?

Doron.

On Thu, Jun 11, 2020 at 04:09:03PM +0200, Pavel Hofman wrote:
> 
> Dne 11. 06. 20 v 14:50 Doron Behar napsal(a):
> > 
> > What am I supposed to give the 2nd argument? It seems like a necessary
> > argument according to the signature. The docs don't explain much about
> > it and I haven't found much in the mailing list's archives.
> 
> Initial values of the searched-for parameters to start with, typically
> some estimate.
> 
> ## initial values:
> init = [.25; .25];  <------
> ## linear constraints, A.' * parametervector + B >= 0
> A = [1; -1]; B = 0; # p(1) >= p(2);
> settings = optimset ("inequc", {A, B});
> 
> ## start optimization
> [p, model_values, cvg, outp] = nonlin_curvefit (f, init, indep, obs, <--
>   settings)
> 
> The definition says
> Function File: [p, fy, cvg, outp] = nonlin_curvefit (f, pin, x, y)
> 
> where pin means p_initial or p_input
> > 
> > I tried to take the example and fiddle with the values they give there
> > and I haven't noticed any change in the final plots of the data vs the
> > fit...
> 
> That is because all your fitting runs converged from the different
> initial values to the same optimal result. The best proof the method
> works :-)
> 
> Best regards,
> 
> Pavel.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]