view release on metacpan or search on metacpan
lib/Math/Amoeba.pm view on Meta::CPAN
The simplest use is the B<MinimiseND> function. This takes a reference
to an array of guess values for the parameters at the function
minimum, a reference to an array of scales for these parameters
(sensible ranges around the guess in which to look), a reference to
the function, a convergence tolerence for the minimum, the maximum
number of iterations to be taken and the verbose flag (default ON).
It returns an array consisting of a reference to the function parameters
at the minimum and the value there.
=item C<Amoeba>
lib/Math/Amoeba.pm view on Meta::CPAN
Simpex Method in Multidimensions. It takes a reference to an array of
references to arrays which are the initial n+1 vertices (where n is
the number of function parameters), a reference to the function
valuation at these vertices, a reference to the function, a
convergence tolerence for the minimum, the maximum number of
iterations to be taken and the verbose flag (default ON).
It returns an array consisting of a reference to the function parameters
at the minimum and the value there.
=item C<ConstructVertices>
lib/Math/Amoeba.pm view on Meta::CPAN
# Stopping conditions
my $rtol = 2*abs($y->[$ihi]-$y->[$ilo])/(abs($y->[$ihi])+abs($y->[$ilo])+TINY);
if ($rtol<$ftol) { last; }
if ($iter++>$itmax) {
carp "Amoeba exceeded maximum iterations\n" if ($verbose);
last;
}
# Determine the Centroid
if ($recalc) {
view all matches for this distribution
view release on metacpan or search on metacpan
t/MyTestHelpers.pm view on Meta::CPAN
#
# use Exporter;
# use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
# @ISA = ('Exporter');
# @EXPORT_OK = qw(findrefs
# main_iterations
# warn_suppress_gtk_icon
# glib_gtk_versions
# any_signal_connections
# nowarnings);
# %EXPORT_TAGS = (all => \@EXPORT_OK);
t/MyTestHelpers.pm view on Meta::CPAN
#-----------------------------------------------------------------------------
# Gtk/Glib helpers
# Gtk 2.16 can go into a hard loop on events_pending() / main_iteration_do()
# if dbus is not running, or something like that. In any case limiting the
# iterations is good for test safety.
#
sub main_iterations {
my $count = 0;
if (DEBUG) { MyTestHelpers::diag ("main_iterations() ..."); }
while (Gtk2->events_pending) {
$count++;
Gtk2->main_iteration_do (0);
if ($count >= 500) {
MyTestHelpers::diag ("main_iterations(): oops, bailed out after $count events/iterations");
return;
}
}
MyTestHelpers::diag ("main_iterations(): ran $count events/iterations");
}
# warn_suppress_gtk_icon() is a $SIG{__WARN__} handler which suppresses spam
# from Gtk trying to make you buy the hi-colour icon theme. Eg,
#
t/MyTestHelpers.pm view on Meta::CPAN
while (! $done) {
if (DEBUG >= 2) { MyTestHelpers::diag ("wait_for_event() iteration $count"); }
Gtk2->main_iteration;
$count++;
}
MyTestHelpers::diag ("wait_for_event(): '$signame' ran $count events/iterations\n");
$widget->signal_handler_disconnect ($sig_id);
Glib::Source->remove ($timer_id);
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Base/Convert/Shortcuts.pm view on Meta::CPAN
$pad = 0 if $pad == $dpr;
if ($pad) {
$str = ($padchar x $pad) . $str; # pad string with zero value digit
}
# number of iterations % digits/register
$len += $pad;
my $i = 0;
my @d32;
while ($i < $len) {
#
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Basic/XS.pm view on Meta::CPAN
}
});
...
Benchmark: timing 1000000 iterations of Math::Basic, XS...
Math::Basic: 5 wallclock secs ( 5.00 usr + 0.00 sys = 5.00 CPU) @ 200000.00/s (n=1000000)
XS: 2 wallclock secs ( 2.21 usr + 0.05 sys = 2.26 CPU) @ 442477.88/s (n=1000000)
=head1 AUTHOR
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/BigInt/Calc.pm view on Meta::CPAN
# First input argument is modified.
my ($c, $n, $k) = @_;
# If k > n/2, or, equivalently, 2*k > n, compute nok(n, k) as
# nok(n, n-k), to minimize the number if iterations in the loop.
{
my $twok = $c->_mul($c->_two(), $c->_copy($k)); # 2 * k
if ($c->_acmp($twok, $n) > 0) { # if 2*k > n
$k = $c->_sub($c->_copy($n), $k); # k = n - k
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Brent.pm view on Meta::CPAN
to the function's minimum using Brent's method.
($x, $y) = Minimise1D($guess, $scale, \&func);
The minimum is reached within a certain tolerance (defaulting 1e-7), and
attempts to do so within a maximum number of iterations (defaulting to 100).
You may override them by providing alternate values:
($x, $y) = Minimise1D($guess, $scale, \&func, 1.5e-8, 120);
=cut
lib/Math/Brent.pm view on Meta::CPAN
=back
Brent() isolates the minimum to a fractional precision of about B<$tol>
using Brent's method.
A maximum number of iterations B<$itmax> may be specified for this search - it
defaults to 100. Returned is a list consisting of the abcissa of the minum
and the function value there.
=cut
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Business/BlackScholes/Binaries/Greeks/Delta.pm view on Meta::CPAN
my $hyp_part = 0;
my $stability_constant =
Math::Business::BlackScholesMerton::Binaries::get_stability_constant_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w, $eta, 2);
my $iterations_required = Math::Business::BlackScholesMerton::Binaries::get_min_iterations_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $vol, $w);
for (my $k = 1; $k < $iterations_required; $k++) {
my $lambda_k_dash = (0.5 * (($mu_dash * $mu_dash) / ($vol * $vol) + ($k * $k * $pi * $pi * $vol * $vol) / ($h * $h)));
my $phi = ($vol * $vol) / ($h * $h * $h) * exp(-$lambda_k_dash * $t) * $k * $k / $lambda_k_dash;
$series_part += $phi * $pi * $pi * cos($k * $pi * ($h - $x) / $h);
view all matches for this distribution
view release on metacpan or search on metacpan
BlackScholes.pm view on Meta::CPAN
the price of the call option, and the volatility is returned.
You can override the default option price tolerance of 1e-4 by passing an
additional argument beyond C<$fractional_yield>.
If called in an array context, the second element of the return value is an
estimate of the error magnitude, and the third element is the number of
iterations required to obtain the result.
The error magnitude may be quite large unless you use a
reference option whose price exceeds its intrinsic value by an amount larger
than or comparable to the absolute difference of the market price and the
strike price, and it is undefined if the price of the reference option is
less than what would be calculated with zero volatility.
If the price of the reference option is greater than what would be calculated
with infinite volatility, then both the result and the error estimate are
undefined.
An exception is thrown if it fails to converge within
C<$Math::Business::BlackScholes::max_iter> (100 by default) iterations.
An analogous implied_volatility_put() is also available.
=head2 American Options
Whereas a European stock option may be exercised only when it expires,
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Business/BlackScholesMerton/Binaries.pm view on Meta::CPAN
#
# SANITY CHECKS
#
# For extreme cases, the price will be wrong due the values in the
# infinite series getting too large or too small, which causes
# roundoff errors in the computer. Thus no matter how many iterations
# you make, the errors will never go away.
#
# For example try this:
#
# my ($S, $U, $D, $t, $r, $q, $vol, $w)
lib/Math/Business/BlackScholesMerton/Binaries.pm view on Meta::CPAN
# These constants will determine whether or not this contract can be
# evaluated to a predefined accuracy. It is VERY IMPORTANT because
# if these conditions are not met, the prices can be complete nonsense!!
my $stability_constant = get_stability_constant_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $eta, 1);
# The number of iterations is important when recommending the
# range of the upper/lower barriers on our site. If we recommend
# a range that is too big and our iteration is too small, the
# price will be wrong! We must know the rate of convergence of
# the formula used.
my $iterations_required = get_min_iterations_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w);
for (my $k = 1; $k < $iterations_required; $k++) {
my $lambda_k_dash = (0.5 * (($mu_dash * $mu_dash) / ($sigma * $sigma) + ($k * $k * $pi * $pi * $sigma * $sigma) / ($h * $h)));
my $phi = ($sigma * $sigma) / ($h * $h) * exp(-$lambda_k_dash * $t) * $k / $lambda_k_dash;
$series_part += $phi * $pi * sin($k * $pi * ($h - $x) / $h);
lib/Math/Business/BlackScholesMerton/Binaries.pm view on Meta::CPAN
my $x = log($S / $D);
return exp(-$mu_new * $x / ($sigma * $sigma)) * common_function_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, 0);
}
=head2 get_min_iterations_pelsser_1997
USAGE
my $min = get_min_iterations_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy)
DESCRIPTION
An estimate of the number of iterations required to achieve a certain
level of accuracy in the price.
=cut
sub get_min_iterations_pelsser_1997 {
my ($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy) = @_;
if (not defined $accuracy) {
$accuracy = $MIN_ACCURACY_UPORDOWN_PELSSER_1997;
}
lib/Math/Business/BlackScholesMerton/Binaries.pm view on Meta::CPAN
$accuracy = $MIN_ACCURACY_UPORDOWN_PELSSER_1997;
} elsif ($accuracy <= 0) {
$accuracy = $MIN_ACCURACY_UPORDOWN_PELSSER_1997;
}
my $it_up = _get_min_iterations_ot_up_ko_down_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy);
my $it_down = _get_min_iterations_ot_down_ko_up_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy);
my $min = max($it_up, $it_down);
return $min;
}
=head2 _get_min_iterations_ot_up_ko_down_pelsser_1997
USAGE
my $k_min = _get_min_iterations_ot_up_ko_down_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy)
DESCRIPTION
An estimate of the number of iterations required to achieve a certain
level of accuracy in the price for ONETOUCH-UP-KNOCKOUT-DOWN.
=cut
sub _get_min_iterations_ot_up_ko_down_pelsser_1997 {
my ($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy) = @_;
if (!defined $accuracy) {
die "accuracy required";
}
lib/Math/Business/BlackScholesMerton/Binaries.pm view on Meta::CPAN
my $delta_dash = $accuracy;
my $delta = $delta_dash * exp(-$mu_new * ($h - $x) / ($sigma * $sigma)) * (($h * $h) / ($pi * $sigma * $sigma));
# This can happen when stability condition fails
if ($delta * $B <= 0) {
die "(_get_min_iterations_ot_up_ko_down_pelsser_1997) Cannot "
. "evaluate minimum iterations because too many iterations "
. "required!! delta=$delta, B=$B for input parameters S=$S, "
. "U=$U, D=$D, t=$t, r_q=$r_q, mu=$mu, sigma=$sigma, w=$w, "
. "accuracy=$accuracy";
}
lib/Math/Business/BlackScholesMerton/Binaries.pm view on Meta::CPAN
}
return int($k_min);
}
=head2 _get_min_iterations_ot_down_ko_up_pelsser_1997
USAGE
DESCRIPTION
An estimate of the number of iterations required to achieve a certain
level of accuracy in the price for ONETOUCH-UP-KNOCKOUT-UP.
=cut
sub _get_min_iterations_ot_down_ko_up_pelsser_1997 {
my ($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy) = @_;
my $h = log($U / $D);
my $mu_new = $mu - (0.5 * $sigma * $sigma);
$accuracy = $accuracy * exp($mu_new * $h / ($sigma * $sigma));
return _get_min_iterations_ot_up_ko_down_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy);
}
=head2 range
USAGE
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Business/BlackScholes/Binaries.pm view on Meta::CPAN
#
# SANITY CHECKS
#
# For extreme cases, the price will be wrong due the values in the
# infinite series getting too large or too small, which causes
# roundoff errors in the computer. Thus no matter how many iterations
# you make, the errors will never go away.
#
# For example try this:
#
# my ($S, $U, $D, $t, $r, $q, $vol, $w)
lib/Math/Business/BlackScholes/Binaries.pm view on Meta::CPAN
# These constants will determine whether or not this contract can be
# evaluated to a predefined accuracy. It is VERY IMPORTANT because
# if these conditions are not met, the prices can be complete nonsense!!
my $stability_constant = get_stability_constant_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $eta, 1);
# The number of iterations is important when recommending the
# range of the upper/lower barriers on our site. If we recommend
# a range that is too big and our iteration is too small, the
# price will be wrong! We must know the rate of convergence of
# the formula used.
my $iterations_required = get_min_iterations_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w);
for (my $k = 1; $k < $iterations_required; $k++) {
my $lambda_k_dash = (0.5 * (($mu_dash * $mu_dash) / ($sigma * $sigma) + ($k * $k * $pi * $pi * $sigma * $sigma) / ($h * $h)));
my $phi = ($sigma * $sigma) / ($h * $h) * exp(-$lambda_k_dash * $t) * $k / $lambda_k_dash;
$series_part += $phi * $pi * sin($k * $pi * ($h - $x) / $h);
lib/Math/Business/BlackScholes/Binaries.pm view on Meta::CPAN
my $x = log($S / $D);
return exp(-$mu_new * $x / ($sigma * $sigma)) * common_function_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, 0);
}
=head2 get_min_iterations_pelsser_1997
USAGE
my $min = get_min_iterations_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy)
DESCRIPTION
An estimate of the number of iterations required to achieve a certain
level of accuracy in the price.
=cut
sub get_min_iterations_pelsser_1997 {
my ($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy) = @_;
if (not defined $accuracy) {
$accuracy = $MIN_ACCURACY_UPORDOWN_PELSSER_1997;
}
lib/Math/Business/BlackScholes/Binaries.pm view on Meta::CPAN
$accuracy = $MIN_ACCURACY_UPORDOWN_PELSSER_1997;
} elsif ($accuracy <= 0) {
$accuracy = $MIN_ACCURACY_UPORDOWN_PELSSER_1997;
}
my $it_up = _get_min_iterations_ot_up_ko_down_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy);
my $it_down = _get_min_iterations_ot_down_ko_up_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy);
my $min = max($it_up, $it_down);
return $min;
}
=head2 _get_min_iterations_ot_up_ko_down_pelsser_1997
USAGE
my $k_min = _get_min_iterations_ot_up_ko_down_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy)
DESCRIPTION
An estimate of the number of iterations required to achieve a certain
level of accuracy in the price for ONETOUCH-UP-KNOCKOUT-DOWN.
=cut
sub _get_min_iterations_ot_up_ko_down_pelsser_1997 {
my ($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy) = @_;
if (!defined $accuracy) {
die "accuracy required";
}
lib/Math/Business/BlackScholes/Binaries.pm view on Meta::CPAN
my $delta_dash = $accuracy;
my $delta = $delta_dash * exp(-$mu_new * ($h - $x) / ($sigma * $sigma)) * (($h * $h) / ($pi * $sigma * $sigma));
# This can happen when stability condition fails
if ($delta * $B <= 0) {
die "(_get_min_iterations_ot_up_ko_down_pelsser_1997) Cannot "
. "evaluate minimum iterations because too many iterations "
. "required!! delta=$delta, B=$B for input parameters S=$S, "
. "U=$U, D=$D, t=$t, r_q=$r_q, mu=$mu, sigma=$sigma, w=$w, "
. "accuracy=$accuracy";
}
lib/Math/Business/BlackScholes/Binaries.pm view on Meta::CPAN
}
return int($k_min);
}
=head2 _get_min_iterations_ot_down_ko_up_pelsser_1997
USAGE
DESCRIPTION
An estimate of the number of iterations required to achieve a certain
level of accuracy in the price for ONETOUCH-UP-KNOCKOUT-UP.
=cut
sub _get_min_iterations_ot_down_ko_up_pelsser_1997 {
my ($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy) = @_;
my $h = log($U / $D);
my $mu_new = $mu - (0.5 * $sigma * $sigma);
$accuracy = $accuracy * exp($mu_new * $h / ($sigma * $sigma));
return _get_min_iterations_ot_up_ko_down_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy);
}
=head2 range
USAGE
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Business/BlackScholesMerton/Binaries.pm view on Meta::CPAN
#
# SANITY CHECKS
#
# For extreme cases, the price will be wrong due the values in the
# infinite series getting too large or too small, which causes
# roundoff errors in the computer. Thus no matter how many iterations
# you make, the errors will never go away.
#
# For example try this:
#
# my ($S, $U, $D, $t, $r, $q, $vol, $w)
lib/Math/Business/BlackScholesMerton/Binaries.pm view on Meta::CPAN
# These constants will determine whether or not this contract can be
# evaluated to a predefined accuracy. It is VERY IMPORTANT because
# if these conditions are not met, the prices can be complete nonsense!!
my $stability_constant = get_stability_constant_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $eta, 1);
# The number of iterations is important when recommending the
# range of the upper/lower barriers on our site. If we recommend
# a range that is too big and our iteration is too small, the
# price will be wrong! We must know the rate of convergence of
# the formula used.
my $iterations_required = get_min_iterations_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w);
for (my $k = 1; $k < $iterations_required; $k++) {
my $lambda_k_dash = (0.5 * (($mu_dash * $mu_dash) / ($sigma * $sigma) + ($k * $k * $pi * $pi * $sigma * $sigma) / ($h * $h)));
my $phi = ($sigma * $sigma) / ($h * $h) * exp(-$lambda_k_dash * $t) * $k / $lambda_k_dash;
$series_part += $phi * $pi * sin($k * $pi * ($h - $x) / $h);
lib/Math/Business/BlackScholesMerton/Binaries.pm view on Meta::CPAN
my $x = log($S / $D);
return exp(-$mu_new * $x / ($sigma * $sigma)) * common_function_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, 0);
}
=head2 get_min_iterations_pelsser_1997
USAGE
my $min = get_min_iterations_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy)
DESCRIPTION
An estimate of the number of iterations required to achieve a certain
level of accuracy in the price.
=cut
sub get_min_iterations_pelsser_1997 {
my ($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy) = @_;
if (not defined $accuracy) {
$accuracy = $MIN_ACCURACY_UPORDOWN_PELSSER_1997;
}
lib/Math/Business/BlackScholesMerton/Binaries.pm view on Meta::CPAN
$accuracy = $MIN_ACCURACY_UPORDOWN_PELSSER_1997;
} elsif ($accuracy <= 0) {
$accuracy = $MIN_ACCURACY_UPORDOWN_PELSSER_1997;
}
my $it_up = _get_min_iterations_ot_up_ko_down_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy);
my $it_down = _get_min_iterations_ot_down_ko_up_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy);
my $min = max($it_up, $it_down);
return $min;
}
=head2 _get_min_iterations_ot_up_ko_down_pelsser_1997
USAGE
my $k_min = _get_min_iterations_ot_up_ko_down_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy)
DESCRIPTION
An estimate of the number of iterations required to achieve a certain
level of accuracy in the price for ONETOUCH-UP-KNOCKOUT-DOWN.
=cut
sub _get_min_iterations_ot_up_ko_down_pelsser_1997 {
my ($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy) = @_;
if (!defined $accuracy) {
die "accuracy required";
}
lib/Math/Business/BlackScholesMerton/Binaries.pm view on Meta::CPAN
my $delta_dash = $accuracy;
my $delta = $delta_dash * exp(-$mu_new * ($h - $x) / ($sigma * $sigma)) * (($h * $h) / ($pi * $sigma * $sigma));
# This can happen when stability condition fails
if ($delta * $B <= 0) {
die "(_get_min_iterations_ot_up_ko_down_pelsser_1997) Cannot "
. "evaluate minimum iterations because too many iterations "
. "required!! delta=$delta, B=$B for input parameters S=$S, "
. "U=$U, D=$D, t=$t, r_q=$r_q, mu=$mu, sigma=$sigma, w=$w, "
. "accuracy=$accuracy";
}
lib/Math/Business/BlackScholesMerton/Binaries.pm view on Meta::CPAN
}
return int($k_min);
}
=head2 _get_min_iterations_ot_down_ko_up_pelsser_1997
USAGE
DESCRIPTION
An estimate of the number of iterations required to achieve a certain
level of accuracy in the price for ONETOUCH-UP-KNOCKOUT-UP.
=cut
sub _get_min_iterations_ot_down_ko_up_pelsser_1997 {
my ($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy) = @_;
my $h = log($U / $D);
my $mu_new = $mu - (0.5 * $sigma * $sigma);
$accuracy = $accuracy * exp($mu_new * $h / ($sigma * $sigma));
return _get_min_iterations_ot_up_ko_down_pelsser_1997($S, $U, $D, $t, $r_q, $mu, $sigma, $w, $accuracy);
}
=head2 range
USAGE
view all matches for this distribution
view release on metacpan or search on metacpan
NewtonRaphson.pm view on Meta::CPAN
};
# Now iterate.
my $curGuess = $guess;
my $lastGuess = !$guess;
my $iterations = 0;
while ($iterations < $MAXITERATIONS && $curGuess != $lastGuess) {
# Write traceback.
$self->{'traceback'} .= "$iterations\t$curGuess\n";
# Sub value in.
$lastGuess = $curGuess;
eval {
$curGuess = $lastGuess - $self->evaluateTree($fiter, $variable => $lastGuess, %mappings);
} || ($self->{'error'} ||= "Fatal error! $@");
# Increment iterations counter.
$iterations++;
}
# Return an appropriate value (or lack thereof...).
if ($self->{'error'}) {
return undef;
view all matches for this distribution
view release on metacpan or search on metacpan
TaylorSeries.pm view on Meta::CPAN
# Create a clone of the expression object that we'll differentiate and prepare to find co-efficients.
my $diffExp = $self->clone;
my @coeffs = ();
my $coeffsFound = 0;
# Loop until we've found enough terms or we hit our maximum number of iterations.
my $numIters = 0;
while ($coeffsFound < $terms) {
# Evaluate.
my $coeff = $diffExp->evaluate($variable => $about);
return undef unless defined($coeff);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Cephes.pm view on Meta::CPAN
$sum = Math::Cephes::simpsn_wrap($f, $count-1, $h);
my $test = abs($sum - $sumold);
return $sum if ($test < $abs or abs($test/$sum) < $rel);
$sumold = $sum;
}
warn("Math::Cephes::simpson: Maximum number $nmax of iterations reached");
return undef;
}
sub bernum {
my $i = shift;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/DifferenceSet/Planar.pm view on Meta::CPAN
The class methods
C<Math::DifferenceSet::Planar-E<gt>iterate_known_I<E<lt>typeE<gt>>_refs(@args)>
with I<E<lt>typeE<gt>> one of C<std>, C<lex>, or C<gap>, provide
iterators analogous to I<iterate>, but iterating over the reference
sets of the respective type rather than unspecified samples. Note that
these iterations may terminate sooner than I<iterate> and may even skip
some orders.
=item I<known_std_ref_min_order>
=item I<known_std_ref_max_order>
lib/Math/DifferenceSet/Planar.pm view on Meta::CPAN
already present, before it can be regarded as scientifically acceptable.
For each order, we used Singer's construction to generate a sample
set, which is provably valid, and iterated through its multiples
to find reference sets with their respective optimality properties.
As this was of course performed by computer programs and computers may
malfunction, repetitions or, even better, independent reiterations
will increase confidence in the results and weed out actual errors.
Verifying difference set properties using complete difference tables is
impractical for large sets. Verification using reference sets, on the
other hand, relies partly on conjectures. Therefore, we are still looking
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/EMA.pm view on Meta::CPAN
=head1 SYNOPSIS
use Math::EMA;
my $avg=Math::EMA->new(alpha=>0.926119, ema=>$initial_value);
$avg->set_param($iterations, $end_weight);
$avg->alpha=$new_alpha;
$avg->ema=$new_value;
$avg->add($some_value);
my $ema=$avg->ema;
lib/Math/EMA.pm view on Meta::CPAN
=head2 How to choose alpha?
The value of alpha determines how fast a given value vanes but it never
completely drops out. Assume you can define a limit say after 10
iterations the weight of a certain value should be 1% or 0.01. Then
_____
_10 / `
alpha = \ / 0.01 = exp( log(0.01) / 10 )
\/
lib/Math/EMA.pm view on Meta::CPAN
=head3 $obj-E<gt>ema
set or retrieve the current average
=head3 $obj-E<gt>set_param($iterations, $end_weight)
computes alpha from the passed values. After C<$iterations> new values a
certain value should have a weight of C<$end_weight> in the average.
=head1 SEE ALSO
L<http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average>
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Erf/Approx.pm view on Meta::CPAN
=head1 BENCHMARKS
Benchmarking against L<Games::Go::Erf> (on a fairly underpowered netbook)...
Benchmark: timing 100000 iterations of GGE, MEA...
GGE: 6 wallclock secs ( 6.34 usr + 0.01 sys = 6.35 CPU) @ 15748.03/s (n=100000)
MEA: 3 wallclock secs ( 2.71 usr + 0.00 sys = 2.71 CPU) @ 36900.37/s (n=100000)
There are considerations other than raw speed though...
view all matches for this distribution
view release on metacpan or search on metacpan
benchmark.pl view on Meta::CPAN
use Benchmark qw(cmpthese);
use Math::Expression::Evaluator;
use Data::Dumper;
my $statement = '2 + a + 5 + (3+4)';
my $iterations = $ARGV[0] || 200;
sub with_optimize {
my $m = Math::Expression::Evaluator->new($statement);
$m->optimize;
for (1..$iterations){
$m->val({a => $_});
}
}
sub no_optimize {
my $m = Math::Expression::Evaluator->new($statement);
for (1..$iterations){
$m->val({a => $_});
}
}
sub compiled {
my $m = Math::Expression::Evaluator->new($statement);
my $c = $m->compiled();
for (1..$iterations){
$c->({a => $_});
}
}
sub opt_compiled {
my $m = Math::Expression::Evaluator->new($statement);
$m->optimize();
my $c = $m->compiled();
for (1..$iterations){
$c->({a => $_});
}
}
view all matches for this distribution
view release on metacpan or search on metacpan
Expression.pm view on Meta::CPAN
$self->PrintError("Loops not enabled, set property PermitLoops to do so");
return;
}
while(1) {
if($self->{MaxLoopCount} && ++$self->{LoopCount} > $self->{MaxLoopCount}) {
$self->PrintError("Loop exceeded maximum iterations: MaxLoopCount = $self->{MaxLoopCount}");
return;
}
# left is loop condition, right is body:
my @left = $self->EvalTree($tree->{left}, 0);
return $ret unless($left[-1]);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Fractal/Julia.pm view on Meta::CPAN
constant => [ $cx, $cy ]
=back
The default maximum number of iterations is 600.
The default limit is 5.
The default bounds is [-2.2, -1.1, 1.0, 1.1, 640, 480].
The default constant is [0.0, 0.0].
my $julia = Math::Fractal::Julia->new();
lib/Math/Fractal/Julia.pm view on Meta::CPAN
=item Return value: undefined
=back
Set the maximum number of iterations. The default value is 600.
Math::Fractal::Julia->set_max_iter($max);
$julia->set_max_iter($max);
lib/Math/Fractal/Julia.pm view on Meta::CPAN
=over 4
=item Arguments: $x, $y
=item Return value: The number of iterations needed to exceed the limit
or 0 if the the limit is not exceeded.
=back
This function translates the coordinates using the bounds and then
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Fractal/Mandelbrot.pm view on Meta::CPAN
=head2 set_max_iter()
Math::Fractal::Mandelbrot->set_max_iter($max_iter);
Set the maximum number of iterations. 600 is the default and quite suitable
for the start image. When zooming in, this value should be increased to
not loose details.
=head2 set_limit()
lib/Math/Fractal/Mandelbrot.pm view on Meta::CPAN
=head2 set_epsilon()
Math::Fractal::Mandelbrot->set_epsilon($e);
The default value is 0.001. When the change between two iterations is less
than this number, the point is considered to be on the inside.
=head2 set_bounds()
Math::Fractal::Mandelbrot->set_bounds($x1,$y1,$x2,$y2,$w,$h);
lib/Math/Fractal/Mandelbrot.pm view on Meta::CPAN
my $iter = Math::Fractal::Mandelbrot->point($x,$y);
Calculates the value at the point C<$x> and C<$y>. The return value 0 means
the point is inside the fractal (typical the black area), any value >0 means
the number of iterations it took to find out that the point is on the outside.
$x and $y should be between 0 and C<w> and 0 and C<h>, respectively (see
L<set_bounds()>).
=head2 hor_line($x1,$y1,$l)
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Function/Roots.pm view on Meta::CPAN
solution B<must> lie within [min,max].
=head2 I<epsilon> and I<max_iter> Parameters
Epsilon (I<e>) is used to set the desired accuracy. Less accurate
answers take fewer iterations and are therefore quicker to compute. In
general I<e> referres to the maximum distance from the given solution
to the actual solution. If you need 6 decimals of accuracy, then I<e>
= .000_000_1 is appropriate, this is the default. Calculating a few
decimals beyond what you need is generally recommended to prevent
compounding rounding errors. I<epsilon> is a named parameter to set
lib/Math/Function/Roots.pm view on Meta::CPAN
return $E;
}
=pod
Similar to epsilon, the maximum number of iterations an algorithm
should run for may be set with the I<max_iter> named parameter, or
globally with I<max_iter>(i). This maximum is normally used to catch
errors, i.e. when a given function doesn't converge, or when there is
a bug (nah...). Do not use this to control run-time, if you need an
answer faster, use a larger epsilon. The only reason to change this
lib/Math/Function/Roots.pm view on Meta::CPAN
=head1 PERFORMANCE CHECKING
=head2 last_iter( )
This will return the number of iterations used to find the last
result. This might help to give an indication on how an algorithm
performs on your data.
=cut
lib/Math/Function/Roots.pm view on Meta::CPAN
$a = $p;
$ay = $py;
}
}
carp "Maximum iterations: possible bad solution";
return $p;
}
=head2 fixed_point( I<fixed point function, guess> )
lib/Math/Function/Roots.pm view on Meta::CPAN
if( abs( $p - $last_p ) <= $E ){
return $p;
}
$last_p = $p;
}
carp "Maximum iterations: divergence likely";
return undef;
}
=head2 secant( I<function>, guess1, guess2 >)
lib/Math/Function/Roots.pm view on Meta::CPAN
return $p;
}
$p1 = $p;
}
carp "Maximum iterations: divergence likely";
return undef;
}
=head2 false_position( I<function, min, max> )
lib/Math/Function/Roots.pm view on Meta::CPAN
$b = $p;
$by = $py;
}
$last_py = $py;
}
carp "Maximum iterations: possible bad solution";
return $p;
}
=head2 find()
lib/Math/Function/Roots.pm view on Meta::CPAN
It will most likely return the root nearest your guess, but no
guarantees. Don't provide a range with more than one root in it, you
might find one, you might not. More information will give higher
performance and more control over which root is being found, but if
you don't know anything about the function, give it a try without a
guess. Settings from epsilon and maximum iterations apply as normal.
=cut
sub find(&;$$%){
my $f = shift;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/GF.pm view on Meta::CPAN
return $p if $first_only;
push @retval, $p;
$n /= $p until $n % $p;
}
my $p = 5; # tentative divisor, will increase through iterations
my $top = int(sqrt($n) + MARGIN); # top attempt for divisor
my $d = 2; # increase for $p, alternates between 4 and 2
while ($p <= $top) {
if ($n % $p == 0) {
return $p if $first_only;
view all matches for this distribution
view release on metacpan or search on metacpan
X = ($mpz*X + $ui) mod (2 ** $m2exp). The low bits of X in this
algorithm are not very random. The least significant bit will have a
period no more than 2, and the second bit no more than 4, etc. For
this reason only the high half of each X is actually used.
When a random number of more than m2exp/2 bits is to be generated,
multiple iterations of the recurrence are used and the results
concatenated.
$state = fgmp_randinit_lc_2exp_size($ui);
This is the Math::GMPf interface to the gmp library function
'gmp_randinit_lc_2exp_size'.
view all matches for this distribution
view release on metacpan or search on metacpan
X = ($mpz*X + $ui) mod (2 ** $m2exp). The low bits of X in this
algorithm are not very random. The least significant bit will have a
period no more than 2, and the second bit no more than 4, etc. For
this reason only the high half of each X is actually used.
When a random number of more than m2exp/2 bits is to be generated,
multiple iterations of the recurrence are used and the results
concatenated.
$state = qgmp_randinit_lc_2exp_size($ui);
This is the Math::GMPq interface to the gmp library function
'gmp_randinit_lc_2exp_size'.
view all matches for this distribution
view release on metacpan or search on metacpan
X = ($mpz*X + $ui) mod (2 ** $m2exp). The low bits of X in this
algorithm are not very random. The least significant bit will have a
period no more than 2, and the second bit no more than 4, etc. For
this reason only the high half of each X is actually used.
When a random number of more than m2exp/2 bits is to be generated,
multiple iterations of the recurrence are used and the results
concatenated.
$state = zgmp_randinit_lc_2exp_size($ui);
This is the Math::GMPz interface to the gmp library function
'gmp_randinit_lc_2exp_size'.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/GSL/Eigen.pm view on Meta::CPAN
@ISA = qw( Math::GSL::Eigen );
%OWNER = ();
%ITERATORS = ();
*swig_size_get = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_size_get;
*swig_size_set = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_size_set;
*swig_max_iterations_get = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_max_iterations_get;
*swig_max_iterations_set = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_max_iterations_set;
*swig_n_iter_get = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_n_iter_get;
*swig_n_iter_set = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_n_iter_set;
*swig_n_evals_get = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_n_evals_get;
*swig_n_evals_set = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_n_evals_set;
*swig_compute_t_get = *Math::GSL::Eigenc::gsl_eigen_francis_workspace_compute_t_get;
lib/Math/GSL/Eigen.pm view on Meta::CPAN
*swig_size_set = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_size_set;
*swig_work_get = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_work_get;
*swig_work_set = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_work_set;
*swig_n_evals_get = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_n_evals_get;
*swig_n_evals_set = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_n_evals_set;
*swig_max_iterations_get = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_max_iterations_get;
*swig_max_iterations_set = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_max_iterations_set;
*swig_n_iter_get = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_n_iter_get;
*swig_n_iter_set = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_n_iter_set;
*swig_eshift_get = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_eshift_get;
*swig_eshift_set = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_eshift_set;
*swig_needtop_get = *Math::GSL::Eigenc::gsl_eigen_gen_workspace_needtop_get;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Gauss/XS.pm view on Meta::CPAN
This module just rewrites the L<Math::Gauss> module in XS. The precision and
exported function remain the same as in the original.
The benchmark results are
Benchmark: timing 30000000 iterations of pp/pdf, xs/pdf...
pp/pdf: 15 wallclock secs (14.99 usr + 0.00 sys = 14.99 CPU) @ 2001334.22/s (n=30000000)
xs/pdf: 2 wallclock secs ( 2.16 usr + 0.00 sys = 2.16 CPU) @ 13888888.89/s (n=30000000)
Benchmark: timing 30000000 iterations of pp/cdf, xs/cdf...
pp/cdf: 40 wallclock secs (38.93 usr + 0.00 sys = 38.93 CPU) @ 770613.92/s (n=30000000)
xs/cdf: 2 wallclock secs ( 2.22 usr + 0.00 sys = 2.22 CPU) @ 13513513.51/s (n=30000000)
Benchmark: timing 30000000 iterations of pp/inv_cdf, xs/inv_cdf...
pp/inv_cdf: 15 wallclock secs (16.02 usr + 0.00 sys = 16.02 CPU) @ 1872659.18/s (n=30000000)
xs/inv_cdf: 2 wallclock secs ( 2.18 usr + 0.00 sys = 2.18 CPU) @ 13761467.89/s (n=30000000)
=for Pod::Coverage cdf inv_cdf pdf
view all matches for this distribution
view release on metacpan or search on metacpan
src/triangle.c view on Meta::CPAN
lnextself(topleft);
printtriangle(m, b, &topleft);
printf(" and right ");
printtriangle(m, b, &horiz);
}
/* On the next iterations, consider the two edges that were */
/* exposed (this is, are now visible to the newly inserted */
/* vertex) by the edge flip. */
lprevself(horiz);
leftvertex = farvertex;
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/LOESS/_swig.pm view on Meta::CPAN
*swig_statistics_set = *Math::LOESS::_swigc::loess_control_statistics_set;
*swig_cell_get = *Math::LOESS::_swigc::loess_control_cell_get;
*swig_cell_set = *Math::LOESS::_swigc::loess_control_cell_set;
*swig_trace_hat_get = *Math::LOESS::_swigc::loess_control_trace_hat_get;
*swig_trace_hat_set = *Math::LOESS::_swigc::loess_control_trace_hat_set;
*swig_iterations_get = *Math::LOESS::_swigc::loess_control_iterations_get;
*swig_iterations_set = *Math::LOESS::_swigc::loess_control_iterations_set;
sub new {
my $pkg = shift;
my $self = Math::LOESS::_swigc::new_loess_control(@_);
bless $self, $pkg if defined($self);
}
view all matches for this distribution