LM(M) User Contributed Perl Documentation LM(M) NAME PDL::Fit::LM -- Levenber-Marquardt fitting routine for PDL DESCRIPTION This module provides fitting functions for PDL. Currently, only Levenberg-Marquardt fitting is implemented. Other procedures should be added as required. For a fairly con- cise overview on fitting see Numerical Recipes, chapter 15 "Modeling of data". SYNOPSIS use PDL::Fit::LM; $ym = lmfit $x, $y, $sig, \&expfunc, $a, {Maxiter => 300}; FUNCTIONS lmfit Levenberg-Marquardt fitting of a user supplied model func- tion ($ym,$a,$covar,$iters) = lmfit $x, $y, $sig, \&expfunc, $a, {Maxiter => 300, Eps => 1e-3}; Options: Maxiter: maximum number of iterations before giving up Eps: convergence citerium for fit; success when normalized change in chisquare smaller than Eps The user supplied sub routine reference should accept 4 arguments o a vector of independent values $x o a vector of fitting parameters o a vector of dependent variables that will be assigned upon return o a matrix of partial derivatives with respect to the fitting parameters that will be assigned upon return As an example take this definition of a single exponential with 3 parameters (width, amplitude, offset): sub expdec { my ($x,$par,$ym,$dyda) = @_; my ($a,$b,$c) = map {$par->slice("($_)")} (0..2); my $arg = $x/$a; my $ex = exp($arg); $ym .= $b*$ex+$c; my (@dy) = map {$dyda->slice(",($_)")} (0..2); $dy[0] .= -$b*$ex*$arg/$a; $dy[1] .= $ex; $dy[2] .= 1; } Note usage of the ".=" operator for assignment In scalar context returns a vector of the fitted dependent variable. In list context returns fitted y-values, vector of fitted parameters, an estimate of the covariance matrix (as an indicator of goodness of fit) and number of itera- tions performed. tlmfit threaded version of Levenberg-Marquardt fitting routine mfit tlmfit $x, $y, float(t)->dummy(y), $na, float(t), float(1e-4), $ym=null, $afit=null, \&expdec; Signature: tlmfit(x(x);y(y);sig(g);a(a);iter();eps();[o] ym(m);[o] ao(o); OtherPar => subref) a threaded version of "lmfit" by using perl threading. Direct threading in "lmfit" seemed difficult since we have an if condition in the iteration. In principle that can be worked around by using "where" but .... Send a threaded "lmfit" version if you work it out! Since we are using perl threading here speed is not really great but it is just convenient to have a threaded version for many applications (no explicit for-loops required, etc). Suffers from some of the current limitations of perl level threading. BUGS Not known yet. AUTHOR This file copyright (C) 1999, Christian Soeller (c.soeller@auckland.ac.nz). 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. perl v5.6.1 2001-06-17 LM(M)