Algorithm-CurveFit
view release on metacpan or search on metacpan
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:
* A good guess improves the probability of convergence and the quality
of the fit.
* Increasing the number of free parameters decreases the quality and
convergence speed.
* Make sure that there are no correlated parameters such as in 'a + b *
e^(c+x)'. (The example can be rewritten as 'a + b * e^c * e^x' in
which 'c' and 'b' are basically equivalent parameters.
The curve fitting algorithm is accessed via the 'curve_fit' subroutine.
params
The parameters are the symbols in the formula whose value is varied by
the algorithm to find the best fit of the curve to the data. There may
be one or more parameters, but please keep in mind that the number of
parameters 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 ],
...
];
lib/Algorithm/CurveFit.pm view on Meta::CPAN
}
push @ary, $value;
}
}
else {
$deriv = $deriv->new; # better safe than sorry
foreach my $x ( 0 .. $#xdata ) {
my $xv = $xdata[$x];
my $value = $deriv->value(
$variable => $xv,
map { ( @{$_}[ 0, 1 ] ) } @parameters # a, guess
);
if (not defined $value) { # fall back to numeric five-point stencil
my $h = SQRT_EPS*$xv; my $t = $xv + $h; $h = $t-$xv; # numerics. Cf. NR
$value = $formula_sub->($xv, map { $_->[1] } @parameters)
}
push @ary, $value;
}
}
push @cols, \@ary;
}
lib/Algorithm/CurveFit.pm view on Meta::CPAN
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:
=over 2
=item
A good guess improves the probability of convergence and the quality
of the fit.
=item
Increasing the number of free parameters decreases the quality and
convergence speed.
=item
Make sure that there are no correlated parameters such as in 'a + b * e^(c+x)'.
lib/Algorithm/CurveFit.pm view on Meta::CPAN
=item params
The parameters are the symbols in the formula whose value is varied by the
algorithm to find the best fit of the curve to the data. There may be
one or more parameters, but please keep in mind that the number of parameters
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:
( run in 0.525 second using v1.01-cache-2.11-cpan-ba35b6b0368 )