Tuesday 9 June 2015

Week 2: lsqnonlin and lsqcurvefit

A bit late blogging about week 2. 

Almost completed functions lsqnonlin and lsqcurvefit. 
Successfully mapped user-specified Jacobian. 
In Matlab, if the Jacobian option is set to "on",  the model function must return 
a second output which is the Jacobian function.
In Octave, the Jacobian function handle is given to the dfdp option using optimset.

Lsqnonlin function description:

[x,resnorm,residual,exitflag,output,lambda,jacobian] = ...
lsqnonlin(fun,x0,lb,ub,options)

This function maps on:

[x, residual, exitflag, output] = nonlin_residmin (fun, x0, options)

Features of lsqnonlin in Octave:
  • Input arguments: Acceptable forms are lsqnonlin(fun,x0), lsqnonlin(fun,x0,lb,ub) and lsqnonlin(fun,x0,lb,ub,options)
  • Outputs
    • x, exitflag, residual and output currently same as nonlin_residmin.
    • resnorm=sum(residual.^2)
    • Lambda is computed using the complementary pivoting in __lm_svd__.
      It's values differ from Matlab's due to the difference in backends.
    • Jacobian is computed using the function residmin_stat ().


Lsqcurvefit function description:

[x,resnorm,residual,exitflag,output,lambda,jacobian] = ...
lsqcurvefit(fun,x0,xdata,ydata,lb,ub,options)

This function maps on

[x, fy, exitflag, output] = nonlin_curvefit (fun, x0, xdata, ydata, options)

Features of lsqcurvefit in Octave:
  • Input arguments: Acceptable forms are lsqcurvefit (fun,x0,xdata,ydata), lsqcurvefit (fun,x0,xdata,ydata,lb,ub) and lsqcurvefit (fun,x0,lb,ub,xdata,ydata,options)
  • Outputs
    • x, exitflag, residual and output currently same as nonlin_curvefit.
    • residual = fy-ydata, resnorm = sum(residual.^2)
    • Lambda and Jacobian same as in lsqnonlin.
There are only minor interface differences between lsqcurvefit and lsqnonlin.

This week's plan:

  • Hopefully, with lsqnonlin and lsqcurvefit wrapped up, I'll move on to nlinfit
  • Three key challenges need to be addressed when wrapping nlinfit using nonlin_curvefit
    and curvefit_stat:
    • Weight functions: Currently, no such functionality exists in nonlin_curvefit,
       where a user can specify weight functions to perform Robust regression
      (weights computed using the specified function in every iteration).
    • Error Models and ErrorModelInfo
    • Setting options using statset instead of optimset or optimoptions. 

No comments:

Post a Comment