view release on metacpan or search on metacpan
portable/k_haspag.c view on Meta::CPAN
return 1;
}
/*
* Check for the PAG group pair. The first two groups, when combined with
* a rather strange formula, must result in a number matching the single
* group number we already checked for.
*/
if (ngroups < 2) {
free(groups);
return 0;
view all matches for this distribution
view release on metacpan or search on metacpan
one way more easy would be to steam a large amount knowledge over complete discipline structure and categorize it on the smallest node .
then we sort density and lower the scope to compute compounding
by the factor the density map is large.
as more detailed the steaming becomes minimum for compounding (math formulas , corresponding arithmetic)
the Categorizer has to adapt but we will have him well trained with the initial steam.
all left to compounding is the hypothesis and experiment compatible with harvested formulas and arithmetic
on a very small scope or adjustable by density.
:)
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AI/NaiveBayes.pm view on Meta::CPAN
Best category = ArgMax -----------------------
cat in cats P(words)
Since C<P(words)> doesn't change over the range of categories, we can get rid
of it. That's good, because we didn't want to have to compute these values
anyway. So our new formula is:
Best category = ArgMax P(words | cat) P(cat)
cat in cats
Finally, we note that if C<w1, w2, ... wn> are the words in the document,
then this expression is equivalent to:
Best category = ArgMax P(w1|cat)*P(w2|cat)*...*P(wn|cat)*P(cat)
cat in cats
That's the formula I use in my document categorization code. The last
step is the only non-rigorous one in the derivation, and this is the
"naive" part of the Naive Bayes technique. It assumes that the
probability of each word appearing in a document is unaffected by the
presence or absence of each other word in the document. We assume
this even though we know this isn't true: for example, the word
view all matches for this distribution
view release on metacpan or search on metacpan
BackProp.pm view on Meta::CPAN
my $delta = $ammount * ($what - $value) * $self->{SYNAPSES}->{LIST}->[$i]->{INPUT};
$self->{SYNAPSES}->{LIST}->[$i]->{WEIGHT} += $delta;
$self->{SYNAPSES}->{LIST}->[$i]->{PKG}->weight($ammount,$what);
}
# This formula in use by default is original by me (Josiah Bryan) as far as I know.
# If it is equal, then don't adjust
#
### Disabled because this soemtimes causes
### infinte loops when learning with range limits enabled
view all matches for this distribution
view release on metacpan or search on metacpan
t/annealing_tests.t view on Meta::CPAN
# The cost_function_factory() takes a reference to an array containing
# real-world market distances and returns a reference to a cost function.
# The cost function takes a reference to an array of three coefficients,
# and returns the mean absolute percentage deviation of the calculated
# results from the real-world results based on this formula:
#
# (a * sqrt(x + b)) + c
#
# where x is a number of trading days in the range 3 to 63.
sub cost_function_factory {
view all matches for this distribution
view release on metacpan or search on metacpan
lib/AI/TensorFlow/Libtensorflow/Manual/Notebook/InferenceUsingTFHubMobileNetV2Model.pod view on Meta::CPAN
</span><span style="color: #6666cc;">NumDims </span><span style=""> </span><span style="color: #ff6633;">2</span><span style="">
</span><span style="color: #6666cc;">ElementCount </span><span style=""> </span><span style="color: #ff6633;">1001</span><span style="">
</span><span style="color: #33ccff;">}</span><span style="">
</span></code></pre></span>
Then we send the batched image data. The returned scores need to by normalised using the L<softmax function|https://en.wikipedia.org/wiki/Softmax_function> with the following formula (taken from Wikipedia):
$$ {\displaystyle \sigma (\mathbf {z} )I<{i}={\frac {e^{z>{i}}}{\sum I<{j=1}^{K}e^{z>{j}}}}\ \ {\text{ for }}i=1,\dotsc ,K{\text{ and }}\mathbf {z} =(zI<{1},\dotsc ,z>{K})\in \mathbb {R} ^{K}.} $$
my $output_pdl_batched = FloatTFTensorToPDL($RunSession->($session, $t));
my $softmax = sub { ( map $_/sumover($_)->dummy(0), exp($_[0]) )[0] };
view all matches for this distribution
view release on metacpan or search on metacpan
doc/examples/petmarket/petmarket/api/stringresourcesservice.pm view on Meta::CPAN
$strings{"QTY_LBL_str"}="Qty";
$strings{"PRODUCT_LBL_str"}="Product";
$strings{"ITEMS_IN_CART_LBL_str"}="Items:";
$strings{"CART_SUBTOTAL_LBL_str"}="Subtotal:";
$strings{"ADVERT_COPY_DEFAULT_str"}="Keep your pets healthy and happy with\n Pet Market brand pet foods.";
$strings{"ADVERT_COPY_CONTEXT_str"}="Keep your pet healthy! Try our special formula of pet foods, available in assorted sizes and flavors.";
$strings{"OK_BTN_LBL_str"}="OK";
$strings{"EXCEEDS_AVAILABLE_MB_MSG_str"}="The quantity you entered exceeds the number we currently have available. The quantity will be automatically reset to the maximum available at this time.";
$strings{"EXCEEDS_AVAILABLE_MB_TTL_str"}="Quantity Available Exceeded";
$strings{"REQUIRED_FIELD_INDICATOR_str"}="*";
$strings{"ERROR_FIELD_INDICATOR_str"}="<";
view all matches for this distribution
view release on metacpan or search on metacpan
script/rest-client view on Meta::CPAN
#$load = floor(500 / $tc_in_config);
my %load_test_cases;
#If config file has 10 test cases, formula for $tc_count is 10*$load
my $total_tc = 0;
while ( $load > 0 ) {
foreach my $num ( sort { $a <=> $b } keys(%test_cases) ) {
view all matches for this distribution
view release on metacpan or search on metacpan
share/AXLSoap.xsd view on Meta::CPAN
</xsd:element>
<xsd:element name="locationName" type="axlapi:String50" default="Hub_None" nillable="false"/>
</xsd:choice>
<xsd:element name="subUnit" type="xsd:nonNegativeInteger" nillable="false" minOccurs="0">
<xsd:annotation>
<xsd:documentation>Applicable for Cisco Conference Bridge (WS-SVC-CMM) and Cisco Media Server(WS-SVC-CMM-MS). Valid values range from 1 to 4.The value should be given as per the formula. Cisco Media Server : ...
</xsd:annotation>
</xsd:element>
<xsd:element name="loadInformation" type="axlapi:XLoadInformation" nillable="true" minOccurs="0">
<xsd:annotation>
<xsd:documentation>This tag is used only by Cisco Conference Bridge Hardware.For devices with load information, if any special load information is specified, the special attribute is set to TRUE. Otherwise, the load information is the default fo...
view all matches for this distribution
view release on metacpan or search on metacpan
devdata/https_mojolicious.io_blog_2018_12_24_async-await-the-mojo-way_ view on Meta::CPAN
As a bulwark against future implimentation changes, it comes with a pluggable backend system, not unlike how Mojo::IOLoop's pluggable reactor system works.
The default implementation may change and users may choose to use any available backend if they have a preference (once new ones come along, and others <strong>are</strong> in the works).</p>
<h2>Conclusion</h2>
<p>So now the formula is simple.</p>
<ul>
<li>Use libraries that return promises rather than take callbacks.</li>
<li>Use the <code>async</code> keyword when declaring functions that need to <code>await</code> promises.</li>
<li>Organize your promises using <a href="https://mojolicious.org/perldoc/Mojo/Promise#all">all</a>, <a href="https://mojolicious.org/perldoc/Mojo/Promise#race">race</a> (only wait for the first resolved promise) or some <a href="https://mojolicious....
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Acme/Glue.pm view on Meta::CPAN
Thanks to all who contributed a snippet
=head1 SEE ALSO
L<https://www.formulanon.com/glue>
L<https://www.youtube.com/watch?v=OXcHLAL_luU>
L<https://leejo.github.io/acme-glue-talk/presentation.html#1>
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Acme/Labs.pm view on Meta::CPAN
(my $plan = join "", <0>) =~ s[(.*^\s*use\s+Acme::Labs\s*;)]["\n" x (split /\n/, $1)]mes; # capture intro for preserving later on (and leave behind the same number of \n's so we don't throw off the line numbers)
do {eval brainier $plan or print STDERR $@; exit} if AYPWIP($plan); # if we recognise a Pinky's Plan, apply to North Pole, I mean, Brain
open 0, ">$0" or print "Cannot get pinking shears! '$0'\n" and exit; # Otherwise, prepare to pinkify!
print {0} $1, pinking $plan # write out reformulated plan
and print STDOUT "Fun-fun-silly-willy!\n"
and do {eval brainier $plan or print STDERR $@; exit}; # and execute our plan
#----------------------------------------------------------------------
view all matches for this distribution
view release on metacpan or search on metacpan
t/classical_all.t view on Meta::CPAN
is PL_N("error", 0) => "error's"; # classical "zero" not active
is PL_N("wildebeest") => "wildebeest's"; # classical "herd" not active
is PL_N("Sally") => "Sally's"; # classical "names" active
is PL_N("brother") => "brother's"; # classical others not active
is PL_N("person") => "people"; # classical "persons" not active
is PL_N("formula") => "formula's"; # classical "ancient" not active
# CLASSICAL PLURALS ACTIVATED...
classical "all";
is PL_N("error", 0) => "error"; # classical "zero" active
is PL_N("wildebeest") => "wildebeest"; # classical "herd" active
is PL_N("Sally") => "Sally's"; # classical "names" active
is PL_N("brother") => "brethren"; # classical others active
is PL_N("person") => "person's"; # classical "persons" active
is PL_N("formula") => "formulae"; # classical "ancient" active
# CLASSICAL PLURALS DEACTIVATED...
classical all => 0;
is PL_N("error", 0) => "error's"; # classical "zero" not active
is PL_N("wildebeest") => "wildebeest's"; # classical "herd" not active
is PL_N("Sally") => "Sally's"; # classical "names" not active
is PL_N("brother") => "brother's"; # classical others not active
is PL_N("person") => "people"; # classical "persons" not active
is PL_N("formula") => "formula's"; # classical "ancient" not active
# CLASSICAL PLURALS REACTIVATED...
classical all => 1;
is PL_N("error", 0) => "error"; # classical "zero" active
is PL_N("wildebeest") => "wildebeest"; # classical "herd" active
is PL_N("Sally") => "Sally's"; # classical "names" active
is PL_N("brother") => "brethren"; # classical others active
is PL_N("person") => "person's"; # classical "persons" active
is PL_N("formula") => "formulae"; # classical "ancient" active
# CLASSICAL PLURALS REDEACTIVATED...
classical 0;
is PL_N("error", 0) => "error's"; # classical "zero" not active
is PL_N("wildebeest") => "wildebeest's"; # classical "herd" not active
is PL_N("Sally") => "Sally's"; # classical "names" not active
is PL_N("brother") => "brother's"; # classical others not active
is PL_N("person") => "people"; # classical "persons" not active
is PL_N("formula") => "formula's"; # classical "ancient" not active
# CLASSICAL PLURALS REREACTIVATED...
classical 1;
is PL_N("error", 0) => "error"; # classical "zero" active
is PL_N("wildebeest") => "wildebeest"; # classical "herd" active
is PL_N("Sally") => "Sally's"; # classical "names" active
is PL_N("brother") => "brethren"; # classical others active
is PL_N("person") => "person's"; # classical "persons" active
is PL_N("formula") => "formulae"; # classical "ancient" active
# CLASSICAL PLURALS REREDEACTIVATED...
classical 0;
is PL_N("error", 0) => "error's"; # classical "zero" not active
is PL_N("wildebeest") => "wildebeest's"; # classical "herd" not active
is PL_N("Sally") => "Sally's"; # classical "names" not active
is PL_N("brother") => "brother's"; # classical others not active
is PL_N("person") => "people"; # classical "persons" not active
is PL_N("formula") => "formula's"; # classical "ancient" not active
# CLASSICAL PLURALS REREREACTIVATED...
classical;
is PL_N("error", 0) => "error"; # classical "zero" active
is PL_N("wildebeest") => "wildebeest"; # classical "herd" active
is PL_N("Sally") => "Sally's"; # classical "names" active
is PL_N("brother") => "brethren"; # classical others active
is PL_N("person") => "person's"; # classical "persons" active
is PL_N("formula") => "formulae"; # classical "ancient" active
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Acme/Math/PerfectChristmasTree.pm view on Meta::CPAN
So it has nothing to do with data structure.
This module is using an equation which was devised by mathematics club of The University Of Sheffield.
For more details, refer to the following web site.
L<http://www.shef.ac.uk/news/nr/debenhams-christmas-tree-formula-1.227810>
=head1 METHODS
=over
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Acme/MetaSyntactic/renault.pm view on Meta::CPAN
Renault_Logan
Renault_Sandero
Renault_Symbol_II
Renault_Duster
Renault_Pulse
# names formula_1
Renault_RS01
Renault_RS10
Renault_RE20
Renault_RE30
Renault_RE40
view all matches for this distribution
view release on metacpan or search on metacpan
When perl calls def(), PL_markstack_ptr is explicitly incremented just prior
to the termination of def();
When perl calls ghi(); PL_markstack_ptr is not explicitly incremented at all.
Those are the only differences between the 3 functions.
I conclude that abc() is the one that has been correctly formulated because
never croaks.
But I don't really understand how both def() and ghi() manage to see 5 args.
And I don't understand how it is that, in test1.t, def() and ghi() pass tests
3 and 4 (respectively), yet fail tests 6 and 7 respectively.
view all matches for this distribution
view release on metacpan or search on metacpan
Example 2:
my @e=map sprintf("%02d%02d", reverse(easter($_))), 1800..300000;
print "First: ".min(@e)." Last: ".max(@e)."\n"; # First: 0322 Last: 0425
Note: The Spencer Jones formula differs Oudins used in C<easter()> in some years
before 1498. However, in that period the Julian calendar with a different formula was
used anyway. Countries introduced the current Gregorian calendar between 1583 and 1926.
=cut
sub easter { use integer;my$Y=shift;my$C=$Y/100;my$L=($C-$C/4-($C-($C-17)/25)/3+$Y%19*19+15)%30;
Three persons: 6
Four persons: 24
Five persons: 120
Six persons: 720
The formula is C<x!> where the postfix unary operator C<!>, also known as I<faculty> is defined as:
C<x! = x * (x-1) * (x-2) ... * 1>. Example: C<5! = 5 * 4 * 3 * 2 * 1 = 120>.Run this to see the 100 first C<< n! >>
perl -MAcme::Tools -le'$i=big(1);print "$_!=",$i*=$_ for 1..100'
1! = 1
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Activator/Pager.pm view on Meta::CPAN
# Last page is total/length when evenly divisible. We mod them, if
# there is remainder, add 1 for the last page. EG: 101/10 == 10
# pages + 1 on the last page
#
# this new hotness courtesy Frank Wallingford
# TODO: write pager tests, use this formula
#$self->{last_page} = int(($total + ( $page_size - 1 ) ) / $page_size );
# old and crufty
$self->{last_page} = int($total/$page_size) + ( ($total % $page_size > 0) ? 1 : 0 );
lib/Activator/Pager.pm view on Meta::CPAN
# divisible so that we don't offset off the end of the available
# results. If there is a remainder, subtract nothing.
#WARN( qq{ ($self->{last_page} * $page_size) - ( ($total % $page_size > 0) ? 0 : $page_size) });
# this new hotness courtesy Frank Wallingford
# TODO: write pager tests, use this formula
#$self->{last_offset} = int( ( $total - 1 ) / $page_size ) + 1;
# old and crufty
$self->{last_offset} = int($total/$page_size) * $page_size - ( ($total % $page_size > 0) ? 0 : $page_size ); ;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Aion/Query.pm view on Meta::CPAN
quote(0.0+"126") # => 126
quote("127"+0.0) # => 127
quote("128"-0.0) # => 128
quote("129"+1.e-100) # => 129.0
# use for insert formula: SELECT :x as summ â x => \"xyz + 123"
quote \"without quote" # => without quote
# use in: WHERE id in (:x)
quote [1,2,"5"] # => 1, 2, '5'
view all matches for this distribution
view release on metacpan or search on metacpan
t/test.data view on Meta::CPAN
let VBP O
us PRP B
responsibly RB O
and CC O
effectively RB O
formulate VB O
and CC O
execute VB O
our PRP$ B
budget NN I
, , O
t/test.data view on Meta::CPAN
significant JJ I
improvement NN I
in IN O
the DT B
budget NN I
formulation NN I
and CC I
execution NN I
process NN I
which WDT B
, , O
t/test.data view on Meta::CPAN
extensive JJ I
testing NN I
to TO O
date VB B
of IN O
reformulated VBN B
gasolines NNS I
, , O
said VBD O
Joe NNP B
Colucci NNP I
t/test.data view on Meta::CPAN
being VBG O
planned VBN O
, , O
will MD O
test VB O
reformulated VBN B
gasolines NNS I
on IN O
newer JJR B
engine NN I
technologies NNS I
t/test.data view on Meta::CPAN
be VB O
a DT B
way NN I
to TO O
promote VB O
reformulated VBN B
gasoline NN I
. . O
Oil NNP B
and CC I
t/test.data view on Meta::CPAN
clean-fuels NNS I
program VBP I
that WDT B
specifically RB O
mentions VBZ O
reformulated VBN B
gasoline NN I
as IN O
an DT B
alternative NN I
. . O
view all matches for this distribution
view release on metacpan or search on metacpan
* variations() is much better, almost twice as fast and does not
create SVs
0.07 November 5 2005
* Documented the corresponding formulas
* Slicing is done now in Perl. The code is much more clear and in my
benchmarks no significant difference is measured
* The iterator now may receive an initial arrayref (this is private
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
# fit() - only public function for this distribution
# Given at least parameter "xy", generate a best-fit curve within a time limit.
# Output: max deviation, avg deviation, implementation source string (perl or C, for now).
# Optional parameters and their defaults:
# terms => 3 # number of terms in formula, max is 10
# time_limit => 3 # number of seconds to try for better fit
# inv => 1 # invert sense of curve-fit, from x->y to y->x
# impl_lang => 'perl' # programming language used for output implementation: perl, c
# impl_name => 'x2y' # name given to output implementation function
sub fit {
my %p = @_;
my $formula = _init_formula(%p);
my ($xdata, $ydata) = _init_data(%p);
my $parameters = _init_parameters($xdata, $ydata, %p);
my $iter_mode = 'time';
my $time_limit = 3; # sane default?
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
$n_iter = 10000 * $time_limit; # will use this to figure out how long it -really- takes.
}
my ($n_sec, $params_ar_ar);
if ($iter_mode eq 'time') {
($n_sec, $params_ar_ar) = _try_fit($formula, $parameters, $xdata, $ydata, $n_iter, $p{fitter_class});
$STATS_H{iter_mode} = $iter_mode;
$STATS_H{fit_calib_iter} = $n_iter;
$STATS_H{fit_calib_time} = $n_sec;
$STATS_H{fit_calib_parar} = $params_ar_ar;
$n_iter = int(($time_limit / $n_sec) * $n_iter + 1);
}
($n_sec, $params_ar_ar) = _try_fit($formula, $parameters, $xdata, $ydata, $n_iter, $p{fitter_class});
$STATS_H{fit_iter} = $n_iter;
$STATS_H{fit_time} = $n_sec;
$STATS_H{fit_parar} = $params_ar_ar;
my $coderef = _implement_formula($params_ar_ar, "coderef", "", $xdata, \%p);
my ($max_dev, $avg_dev) = _calculate_deviation($coderef, $xdata, $ydata);
my $impl_lang = $p{impl_lang} // 'perl';
$impl_lang = lc($impl_lang);
my $impl_name = $p{inv} ? "y2x" : "x2y";
$impl_name = $p{impl_name} // $impl_name;
my $impl = $coderef;
$impl = _implement_formula($params_ar_ar, $impl_lang, $impl_name, $xdata, \%p) unless($impl_lang eq 'coderef');
return ($max_dev, $avg_dev, $impl);
}
# ($n_sec, $params_ar_ar) = _try_fit($formula, $parameters, $xdata, $ydata, $n_iter, $p{fitter_class});
sub _try_fit {
my ($formula, $parameters, $xdata, $ydata, $n_iter, $fitter_class) = @_;
$fitter_class //= "Algorithm::CurveFit";
my $params_ar_ar = [map {[@$_]} @$parameters]; # making a copy because curve_fit() is destructive
my $tm0 = Time::HiRes::time();
my $res = $fitter_class->curve_fit(
formula => $formula,
params => $params_ar_ar,
variable => 'x',
xdata => $xdata,
ydata => $ydata,
maximum_iterations => $n_iter
);
my $tm_elapsed = Time::HiRes::time() - $tm0;
return ($tm_elapsed, $params_ar_ar);
}
sub _init_formula {
my %p = @_;
my $formula = 'k + a*x + b*x^2 + c*x^3'; # sane'ish default
my $terms = $p{terms} // 3;
die "maximum of 10 terms\n" if ($terms > 10);
if ($terms != 3) {
$formula = 'k';
for (my $i = 1; $i <= $terms; $i++) {
my $fact = chr(ord('a') + $i - 1);
$formula .= " + $fact * x^$i";
}
}
return $formula;
}
# ($xdata, $ydata) = _init_data(%p);
sub _init_data {
my %p = @_;
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
my $terms = $p{terms} // 3;
push @params, map {[chr(ord('a')+$_-1), 0.5, 0.0000001]} (1..$terms);
return \@params;
}
# $impl = _implement_formula($params_ar_ar, $impl_lang, $impl_name, $xdata, \%p) unless($impl_lang eq 'coderef');
sub _implement_formula {
my ($params_ar_ar, $impl_lang, $impl_name, $xdata, $opt_hr) = @_;
return _implement_formula_as_coderef(@_) if ($impl_lang eq 'coderef');
# return _implement_formula_as_python(@_) if ($impl_lang eq 'python'); # zzapp
return _implement_formula_as_C(@_) if ($impl_lang eq 'c');
# return _implement_formula_as_R(@_) if ($impl_lang eq 'r'); # zzapp
# return _implement_formula_as_MATLAB(@_) if ($impl_lang eq 'matlab'); # zzapp
return _implement_formula_as_perl(@_);
}
sub _implement_formula_as_coderef {
my ($params_ar_ar, $impl_lang, $impl_name, $xdata, $opt_hr) = @_;
my $k_ar = $params_ar_ar->[0];
my $formula = sprintf("%f", $k_ar->[1]);
for (my $i = 1; defined($params_ar_ar->[$i]); $i++) {
my $fact = $params_ar_ar->[$i]->[1];
my $pow = ($i == 1) ? "" : "**$i";
$formula .= sprintf(' + %f * $x%s', $fact, $pow);
}
$STATS_H{impl_formula} = $formula;
my $bounder = '';
if ($opt_hr->{bounds_check}) {
my ($high_x, $low_x) = ($xdata->[0], $xdata->[0]);
foreach my $x (@$xdata) {
$high_x = $x if ($high_x < $x);
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
}
$bounder = 'die "x out of bounds (high)" if ($x > '.$high_x.'); die "x out of bounds (low)" if ($x < '.$low_x.');';
}
my $rounder = '';
$rounder = '$y = int($y + 0.5);' if ($opt_hr->{round_result});
my $src = 'sub { my($x) = @_; '.$bounder.' my $y = '.$formula.'; '.$rounder.' return $y; }';
$STATS_H{impl_source} = $src;
$STATS_H{impl_exception} = '';
my $coderef = eval($src);
$STATS_H{impl_exception} = $@ unless(defined($coderef));
return $coderef;
}
sub _implement_formula_as_perl {
my ($params_ar_ar, $impl_lang, $impl_name, $xdata, $opt_hr) = @_;
my $k_ar = $params_ar_ar->[0];
my $formula = sprintf("%.11f", $k_ar->[1]);
for (my $i = 1; defined($params_ar_ar->[$i]); $i++) {
my $fact = $params_ar_ar->[$i]->[1];
my $pow = ($i == 1) ? "" : "**$i";
$formula .= sprintf(' + %.11f * $x%s', $fact, $pow);
}
$STATS_H{impl_formula} = $formula;
my $bounder = '';
if ($opt_hr->{bounds_check}) {
my ($high_x, $low_x) = ($xdata->[0], $xdata->[0]);
foreach my $x (@$xdata) {
$high_x = $x if ($high_x < $x);
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
$rounder = ' $y = int($y + 0.5);'."\n" if ($opt_hr->{round_result});
my $src = join("\n",(
"sub $impl_name {",
' my($x) = @_;',
$bounder,
' my $y = '.$formula.';',
$rounder,
' return $y;',
'}'
));
$STATS_H{impl_source} = $src;
$STATS_H{impl_exception} = '';
return $src;
}
sub _implement_formula_as_C {
my ($params_ar_ar, $impl_lang, $impl_name, $xdata, $opt_hr) = @_;
my $k_ar = $params_ar_ar->[0];
my $src = "";
$src .= "#include <math.h>\n" if ($opt_hr->{round_result} && !$opt_hr->{suppress_includes});
$src .= "double $impl_name(double x) {\n";
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
# zzapp -- this is kludgy. better way to signal bounds violation?
$src .= sprintf(" if (x > %.11f) return -1.0;\n", $high_x) .
sprintf(" if (x < %.11f) return -1.0;\n", $low_x);
}
my $formula = "";
for (my $i = 1; defined($params_ar_ar->[$i]); $i++) {
my $fact = $params_ar_ar->[$i]->[1];
$formula .= sprintf(" y += %.11f * xx;\n", $fact);
$formula .= " xx *= x;\n" if(defined($params_ar_ar->[$i+1]));
}
$STATS_H{impl_formula} = $formula; # zzapp -- not clean!
$src .= $formula;
$src .= " y = round(y);\n" if ($opt_hr->{round_result});
$src .= " return y;\n}\n";
$STATS_H{impl_source} = $src;
$STATS_H{impl_exception} = '';
return $src;
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
# Alternatively pass data as array of [x,y] pairs:
my ($max_dev, $avg_dev, $src) = fit(xydata => [[1, 2], [2, 5], [3, 10]], ..options..);
=head1 DESCRIPTION
This is a convenience wrapper around L<Algorithm::CurveFit>. Given a body of (x, y) data points, it will generate a polynomial formula f(x) = y which fits that data.
Its main differences from L<Algorithm::CurveFit> are:
=over 4
=item * It synthesizes the initial formula for you,
=item * It allows for a time limit on the curve-fit instead of an iteration count,
=item * It implements the formula as source code (or as a perl coderef, if you want to use the formula immediately in your program).
=back
Additionally it returns a maximum deviation and average deviation of the formula vs the xydata, which is more useful (to me, at least) than L<Algorithm::CurveFit>'s square residual output. Closer to 1.0 indicates a better fit. Play with C<terms =E<...
=head1 SUBROUTINES
There is only one public subroutine, C<fit()>. It B<must> be given either C<xydata> or C<xdata> and C<ydata> parameters. All other paramters are optional.
It returns three values: A maximum deviation, the average deviation and the formula implementation.
=head2 Options
=over 4
=item C<fit(xdata =E<gt> \@xdata, ydata =E<gt> \@ydata)>
The data points the formula will fit. Same as L<Algorithm::CurveFit> parameters of the same name.
=item C<fit(xydata =E<gt> [[1, 2, 3, 4], [10, 17, 26, 37]])>
=item C<fit(xydata =E<gt> [[1, 10], [2, 17], [3, 26], [4, 37]])>
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
If an iteration count is given, C<fit()> will ignore any time limit and iterate up to C<iterations> times trying to fit the curve. Same as L<Algorithm::CurveFit> parameter of the same name.
=item C<fit(inv =E<gt> 1)>
Setting C<inv> inverts the sense of the fit. Instead of C<f(x) = y> the formula will fit C<f(y) = x>.
=item C<fit(impl_lang =E<gt> "perl")>
Sets the programming language in which the formula will be implemented. Currently supported languages are C<"C">, C<"coderef"> and the default, C<"perl">.
When C<impl_lang =E<gt> "coderef"> is specified, a code reference is returned instead which may be used immediately by your perl script:
my($max_dev, $avg_dev, $x2y) = fit(xydata => \@xy, impl_lang => "coderef");
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
More implementation languages will be supported in the future.
=item C<fit(impl_name =E<gt> "x2y")>
Sets the name of the function implementing the formula. The default is C<"x2y">. Has no effect when used with C<impl_lang =E<gt> "coderef")>.
my($max_dev, $avg_dev, $src) = fit(xydata => \@xy, impl_name => "converto");
print "$src\n";
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
return $y;
}
=item C<fit(bounds_check =E<gt> 1)>
When set, the implementation will include logic for checking whether the input is out-of-bounds, per the highest and lowest x points in the data used to fit the formula. For implementation languages which support exceptions, an exception will be thr...
For instance, if the highest x in C<$xydata> is 83.0 and the lowest x is 60.0:
my($max_dev, $avg_dev, $src) = fit(xydata => \@xy, bounds_check => 1);
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
=over 4
=item C<deviation_max_offset_datum>: The x data point corresponding with returned maximum deviation.
=item C<fit_calib_parar>: Arrayref of formula parameters as returned by L<Algorithm::CurveFit> after a short fitting attempt used for timing calibration.
=item C<fit_calib_time>: The number of seconds L<Algorithm::CurveFit> spent in the calibration run.
=item C<fit_iter>: The iterations parameter passed to L<Algorithm::CurveFit>.
=item C<fit_parar>: Arrayref of formula parameters as returned by L<Algorithm::CurveFit>.
=item C<fit_time>: The number of seconds L<Algorithm::CurveFit> actually spent fitting the formula.
=item C<impl_exception>: The exception thrown when the implementation was used to calculate the deviations, or the empty string if none.
=item C<impl_formula>: The formula part of the implementation.
=item C<impl_source>: The implementation source string.
=item C<iter_mode>: One of C<"time"> or C<"iter">, indicating whether a time limit was used or an iteration count.
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
=item * If C<xydata> is very large, iterating over it to calculate deviances can take more time than permitted by C<time_limit>.
=item * The dangers of overfitting are real! L<https://en.wikipedia.org/wiki/Overfitting>
=item * Using too many terms can dramatically reduce the accuracy of the fitted formula.
=item * Sometimes calling L<Algorithm::CurveFit> with a ten-term polynomial causes it to hang.
=back
=head1 TO DO
=over 4
=item * Support more programming languages for formula implementation: R, MATLAB, python
=item * Calculate the actual term sigfigs and set precision appropriately in the formula implementation instead of just "%.11f".
=item * Support trying a range of terms and returning whatever gives the best fit.
=item * Support piecewise output formulas.
=item * Work around L<Algorithm::CurveFit>'s occasional hang problem when using ten-term polynomials.
=back
view all matches for this distribution
view release on metacpan or search on metacpan
examples/examplefit.pl view on Meta::CPAN
use warnings;
use lib '../lib';
use Algorithm::CurveFit;
my $formula = 'b*cos(x/10)+c*sin(x/10)';
my $variable = 'x';
my @xdata;
my @ydata;
unless (@ARGV) {
examples/examplefit.pl view on Meta::CPAN
['c', 2, 0.0005],
);
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,
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/DecisionTree.pm view on Meta::CPAN
value of the argument C<stage_index> would go from 0 to 9, with 0 corresponding to
the base tree.
=item B<trust_weighted_majority_vote_classifier():>
Uses the "final classifier" formula of the AdaBoost algorithm to pool together the
classification decisions made by the individual trees while taking into account the
trust factors associated with the trees. As mentioned earlier, we associate with
each tree of the cascade a trust factor that depends on the overall misclassification
rate associated with that tree.
view all matches for this distribution
view release on metacpan or search on metacpan
sucking time out of mastermind EAs
2010-09-25 Juan J. Merelo <jmerelo@sheldon>
* lib/Algorithm/Evolutionary/Fitness/Rastrigin.pm (Rastrigin):
Fixed formula
* lib/Algorithm/Evolutionary.pm: Starting 0.74_1 with cosmetic
changes and an attempt to fix sporadic test errors.
2010-09-24 Juan Julian Merelo Guervos <jmerelo@usuario-desktop>
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Utils.pm view on Meta::CPAN
use XML::Parser;
use Statistics::Basic qw(mean);
=head2 entropy( $population)
Computes the entropy using the well known Shannon's formula: L<http://en.wikipedia.org/wiki/Information_entropy>
'to avoid botching highlighting
=cut
sub entropy {
lib/Algorithm/Evolutionary/Utils.pm view on Meta::CPAN
return $entropy;
}
=head2 genotypic_entropy( $population)
Computes the entropy using the well known Shannon's formula:
L<http://en.wikipedia.org/wiki/Information_entropy> 'to avoid botching
highlighting; in this case we use chromosome frequencies instead of
fitness.
=cut
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Utils.pm view on Meta::CPAN
use XML::Parser;
use Statistics::Basic qw(mean);
=head2 entropy( $population)
Computes the entropy using the well known Shannon's formula: L<http://en.wikipedia.org/wiki/Information_entropy>
'to avoid botching highlighting
=cut
sub entropy {
lib/Algorithm/Evolutionary/Utils.pm view on Meta::CPAN
return $entropy;
}
=head2 genotypic_entropy( $population)
Computes the entropy using the well known Shannon's formula:
L<http://en.wikipedia.org/wiki/Information_entropy> 'to avoid botching
highlighting; in this case we use chromosome frequencies instead of
fitness.
=cut
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/Kelly.pm view on Meta::CPAN
use strict;
use warnings;
package Algorithm::Kelly;
$Algorithm::Kelly::VERSION = '0.03';
# ABSTRACT: calculates the fraction of a bankroll to bet using the Kelly formula
BEGIN
{
require Exporter;
use base 'Exporter';
lib/Algorithm/Kelly.pm view on Meta::CPAN
=encoding UTF-8
=head1 NAME
Algorithm::Kelly - calculates the fraction of a bankroll to bet using the Kelly formula
=head1 VERSION
version 0.03
view all matches for this distribution
view release on metacpan or search on metacpan
}
}
/*
Convergence test.
The criterion is given by the following formula:
|g(x)| / \max(1, |x|) < \epsilon
*/
if (xnorm < 1.0) xnorm = 1.0;
if (gnorm / xnorm <= param->epsilon) {
/* Convergence. */
vecdot(&ys, it->y, it->s, n);
vecdot(&yy, it->y, it->y, n);
it->ys = ys;
/*
Recursive formula to compute dir = -(H \cdot g).
This is described in page 779 of:
Jorge Nocedal.
Updating Quasi-Newton Matrices with Limited Storage.
Mathematics of Computation, Vol. 35, No. 151,
pp. 773--782, 1980.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/MOS.pm view on Meta::CPAN
}
# Now, let's deduct 2.5 r_value per percentage of packet_loss
$r_value = $r_value - ($packet_loss * 2.5);
# Convert the r_value into an MOS value. (this is a known formula)
$ret_val = 1 +
(0.035) *
$r_value +
(0.000007) *
$r_value *
view all matches for this distribution