Algorithm-CurveFit

 view release on metacpan or  search on metacpan

lib/Algorithm/CurveFit.pm  view on Meta::CPAN

not only increases processing time, but also decreases the quality of the fit.

The value of this options should be an anonymous array. This array should
hold one anonymous array for each parameter. That array should hold (in order)
a parameter name, an initial guess, and optionally an accuracy measure.

Example:

  $params = [
    ['parameter1', 5,  0.00001],
    ['parameter2', 12, 0.0001 ],
    ...
  ];

  Then later:
  curve_fit(
  ...
    params => $params,
  ...
  );

The accuracy measure means that if the change of parameters from one iteration
to the next is below each accuracy measure for each parameter, convergence is
assumed and the algorithm stops iterating.

In order to prevent looping forever, you are strongly encouraged to make use of
the accuracy measure (see also: maximum_iterations).

The final set of parameters is B<not> returned from the subroutine but the
parameters are modified in-place. That means the original data structure will
hold the best estimate of the parameters.

=item xdata

This should be an array reference to an array holding the data for the
variable of the function. (Which defaults to 'x'.)

=item ydata

This should be an array reference to an array holding the function values
corresponding to the x-values in 'xdata'.

=item maximum_iterations

Optional parameter to make the process stop after a given number of iterations.
Using the accuracy measure and this option together is encouraged to prevent
the algorithm from going into an endless loop in some cases.

=back

The subroutine returns the sum of square residuals after the final iteration
as a measure for the quality of the fit.

=head2 EXPORT

None by default, but you may choose to export C<curve_fit> using the
standard Exporter semantics.

=head2 SUBROUTINES

This is a list of public subroutines

=over 2

=item curve_fit

This subroutine implements the curve fitting as explained in
L<DESCRIPTION> above.

=back

=head1 NOTES AND CAVEATS

=over 2

=item *

When computing the derivative symbolically using C<Math::Symbolic>, the
formula simplification algorithm can sometimes fail to find the equivalent
of C<(x-x_0)/(x-x_0)>. Typically, these would be hidden in a more complex
product. The effect is that for C<x -E<gt> x_0>, the evaluation of the
derivative becomes undefined.

Since version 1.05, we fall back to numeric differentiation
using five-point stencil in such cases. This should help with one of the
primary complaints about the reliability of the module.

=item *

This module is NOT fast.
For slightly better performance, the formulas are compiled to
Perl code if possible.

=back

=head1 SEE ALSO

The 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. L<Math::Symbolic>, L<Math::MatrixReal>, L<Test::More>

=head1 AUTHORS

Steffen Mueller, E<lt>smueller@cpan.orgE<gt>
Paul Cochrane, E<lt>ptc@cpan.orgE<gt> (maintainer)

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2005-2010, 2025 by Steffen Mueller

This 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.

=cut



( run in 1.365 second using v1.01-cache-2.11-cpan-39bf76dae61 )