
PDL::Fit::Levmar::Func - Create model functions for Levenberg-Marquardt fit routines

This module creates and manages functions for use with the Levmar fitting module. The functions are created with a very simple description language (that is mostly C), or are pure C, or are perl code. For many applications, the present document is not necessary because levmar uses the Levmar::Func module transparantly. Therefore, before reading the following, refer to PDL::Fit::Levmar.

use PDL::Fit::Levmar::Func;
$func = levmar_func( FUNC => # define and link function
'
function gaussian
loop
x[i] = p[0] * exp(-(t[i] - p[1])*(t[i] - p[1])*p[2]);
end function
jacobian jacgaussian
double arg, expf;
loop
arg = t[i] - p[1];
expf = exp(-arg*arg*p[2]);
d0 = expf;
d1 = p[0]*2*arg*p[2]*expf;
d2 = p[0]*(-arg*arg)*expf;
end jacobian
'
);
$hout = PDL::Fit::Levmar::levmar($p,$x,$t, # fit the data
FUNCTION => $func,
);

This function creates and links a function, ie, takes a function definition and returns a function (object instance) ready for use by levmar. see PDL::Fit::Levmar::Func for more information.
levmar_func
Call (evaluate) the fit function in a Levmar::Func object.
use PDL::Fit::Levmar::Func; $Gh = levmar_func(FUNC=>$fcode); $x = $Gh->call($p,$t); Here $fcode is a function definition (say lpp code). (This does not currently work with perl subroutines, I think. Of course, you can call the subroutine directly. But it would be good to support it for consistency.) $p is a pdl or ref to array of parameters. $t is a pdl of co-ordinate values. $x is the fit function evaluated at $p and $t. $x has the same shape as $t.
$Gf = levmar_func( FUNC => '
function
x = p0 * t * t;
');
print $Gf->call([2],sequence(10)) , "\n";
[0 2 8 18 32 50 72 98 128 162]

Copyright (C) 2006 John Lapeyre. All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation under certain conditions. For details, see the file COPYING in the PDL distribution. If this file is separated from the PDL distribution, the copyright notice should be included in the file.
my $fitfunc = new PDL::Fit::Levmar::Func(...); or my $fitfunc = levmar_func(...);
Generic constructor