help-octave
[Top][All Lists]
Advanced

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

Custom jacobian (dfdp) in nonlin_curvefit - calling parameters?


From: Pavel Hofman
Subject: Custom jacobian (dfdp) in nonlin_curvefit - calling parameters?
Date: Fri, 15 Nov 2019 14:54:22 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

Hi,

I am trying to find out, if providing custom jacobian results in faster execution than the default real finite differences. However, I got stuck at defining the custom dfdp function. Please is there any example which involves multiple independent values?

My case is fitting sum of two sine functions at vector of times t to observed values y. The problem is I do not know how the custom dfdp function should look like, with what params it is being called. In my code below my dfdp (f_dfdp) gets called with row of times (t) which I cannot convert to the jacobian matrix. The dfdp description in nonlin_residmin talks about some structures, but I was not able to find any example.

As of the unit test in nonlin_curfit.m (chittkowski_327) - I was able to find the commit diff but this case again looks like a single independent value is being used.

I very much appreciate any help, thanks a lot.

Best regards,

Pavel.


t = 0:100;

function y = f_calc(f1, a1, s1, f2, a2, s2, t)
  persistent PI2 = 2 * pi;

  y = a1 * cos(PI2 * f1 * t + s1) + a2 * cos(PI2 * f2 * t + s2);
endfunction

function J = f_dfdp(f1, a1, s1, f2, a2, s2, t)
  persistent PI2 = 2 * pi;

J = [-PI2 * a1 * t * sin(PI2 * f1 * t + s1) , cos(PI2 * f1 * t + s1) , -a1 * sin(PI2 * f1 * t + s1), -PI2 * a2 * t * sin(PI2 * f2 * t + s2), cos(PI2 * f2 * t + s2), -a2 * sin(PI2 * f2 * t + s2)];
endfunction


f = @(p, t) f_calc(p(1), p(2), p(3), p(4), p(5), p(6), t);

my_dfdp= @(p, t) f_dfdp(p(1), p(2), p(3), p(4), p(5), p(6), t);

settings = optimset ('dfdp', my_dfdp, 'Display','iter');


init = [measF1; measA1; measPhase1;measF2; measA2; measPhase2];


[p, model_values, cvg, outp] = nonlin_curvefit(f, init, t, y, settings);






reply via email to

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