|
NAMEAlgorithm::CurveFit - Nonlinear Least Squares FittingSYNOPSISuse Algorithm::CurveFit;# Known form of the formula my $formula = 'c + a * x^2'; my $variable = 'x'; my @xdata = read_file('xdata'); # The data corresponsing to $variable my @ydata = read_file('ydata'); # The data on the other axis my @parameters = ( # Name Guess Accuracy ['a', 0.9, 0.00001], # If an iteration introduces smaller ['c', 20, 0.00005], # changes that the accuracy, end. ); my $max_iter = 100; # maximum iterations my $square_residual = Algorithm::CurveFit->curve_fit( formula => $formula, # may be a Math::Symbolic tree instead params => \@parameters, variable => $variable, xdata => \@xdata, ydata => \@ydata, maximum_iterations => $max_iter, ); use Data::Dumper; print Dumper \@parameters; # Prints # $VAR1 = [ # [ # 'a', # '0.201366784209602', # '1e-05' # ], # [ # 'c', # '1.94690440147554', # '5e-05' # ] # ]; # # Real values of the parameters (as demonstrated by noisy input data): # a = 0.2 # c = 2 DESCRIPTION"Algorithm::CurveFit" implements a nonlinear least squares curve fitting algorithm. That means, it fits a curve of known form (sine-like, exponential, polynomial of degree n, etc.) to a given set of data points.For details about the algorithm and its capabilities and flaws, you're encouraged to read the MathWorld page referenced below. Note, however, that it is an iterative algorithm that improves the fit with each iteration until it converges. The following rule of thumb usually holds true:
The curve fitting algorithm is accessed via the 'curve_fit' subroutine. It requires the following parameters as 'key => value' pairs:
The subroutine returns the sum of square residuals after the final iteration as a measure for the quality of the fit. EXPORTNone by default, but you may choose to export "curve_fit" using the standard Exporter semantics.SUBROUTINESThis is a list of public subroutines
NOTES AND CAVEATS
SEE ALSOThe algorithm implemented in this module was taken from:Eric W. Weisstein. "Nonlinear Least Squares Fitting." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/NonlinearLeastSquaresFitting.html New versions of this module can be found on http://steffen-mueller.net or CPAN. This module uses the following modules. It might be a good idea to be familiar with them. Math::Symbolic, Math::MatrixReal, Test::More AUTHORSteffen Mueller, <smueller@cpan.org<gt>COPYRIGHT AND LICENSECopyright (C) 2005-2010 by Steffen MuellerThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6 or, at your option, any later version of Perl 5 you may have available.
Visit the GSP FreeBSD Man Page Interface. |