view release on metacpan or search on metacpan
lib/Algorithm/AM/Batch.pm view on Meta::CPAN
if($self->begin_hook){
$self->begin_hook->($self);
}
# save the result objects from all items, all iterations, here
my @all_results;
foreach my $item_number (0 .. $test_set->size - 1) {
if($log->is_debug){
$log->debug('Test items left: ' .
lib/Algorithm/AM/Batch.pm view on Meta::CPAN
my ($batch, $test_item) = @_;
$batch->probability(.5);
print $test_item->comment . "\n";
});
This hook is called by L</classify_all> before any iterations of
classification start for each test item. It is provided with the Batch
object instance and the test item.
=head2 C<begin_repeat_hook>
lib/Algorithm/AM/Batch.pm view on Meta::CPAN
$batch->begin_repeat_hook(sub {
my ($batch, $test_item, @results) = @_;
$batch->probability(.5);
print $test_item->comment . "\n";
my $iterations = @results;
my $correct = 0;
for my $result (@result){
$correct++ if $result->result ne 'incorrect';
}
print 'Item ' . $item->comment .
" correct $correct/$iterations times\n";
});
This hook is called by L</classify_all> after all classifications
of a single item are finished. It is provided with the Batch
object instance as well as a list of the
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/AdaBoost.pm view on Meta::CPAN
}
sub train {
args
my $self,
my $num_iterations => 'Int',
my $training_set => +{ isa => 'ArrayRef', optional => 1 },
my $weak_classifier_generator => +{ isa => 'CodeRef', optional => 1 };
$training_set //= $self->training_set
// Carp::croak('Given no training set.');
lib/Algorithm/AdaBoost.pm view on Meta::CPAN
# Initial distribution is uniform.
my $distribution = [ (1 / $num_training_set) x $num_training_set ];
my ($weak_classifier, $weight);
my @weak_classifiers;
while ($num_iterations--) {
# Construct a weak classifier which classifies data on the distribution.
$weak_classifier = $weak_classifier_generator->(
distribution => $distribution,
training_set => $training_set,
);
lib/Algorithm/AdaBoost.pm view on Meta::CPAN
+{ feature => [...], label => -1, },
...
],
weak_classifier_generator => \&my_poor_learning_algorithm,
);
$learner->train(num_iterations => 1_000);
# Now you have a boost-ed classifier (Algorithm::AdaBoost::Classifier).
my $classifier = $learner->final_classifier;
given ($classifier->classify([...])) {
when ($_ > 0) { say 'The data belongs to class 1.' }
lib/Algorithm/AdaBoost.pm view on Meta::CPAN
This method takes 1 mandatory parameter:
=over 2
=item num_iterations
Specifies how many training iterations to be excuted (i.e., how many weak classifiers to be generated).
=back
and 2 optional parameters:
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/Bertsekas.pm view on Meta::CPAN
printf(" Number of edges: %u\n", $array1_size * $array2_size );
print "\nSolution:\n";
printf(" Optimal assignment: sum of values = %.${decimals}f \n", $optimal_benefit );
printf(" Feasible assignment condition: stepsize = %.4g < 1/$min_size = %.4g \n", $epsilon, 1/$min_size ) if ( $verbose >= 1 and $max_size >= 2 );
printf(" Number of iterations: %u \n", $iter_count_global ) if ( $verbose >= 1 );
print "\n row index = [";
for my $i ( 0 .. $#output_index ) {
printf("%${matrix_spaces}d ", $i);
}
lib/Algorithm/Bertsekas.pm view on Meta::CPAN
Number of edges: 60
Solution:
Optimal assignment: sum of values = 153
Feasible assignment condition: stepsize = 0.1667 < 1/5 = 0.2
Number of iterations: 50
row index = [ 0 1 2 3 4 5 6 7 8 9 10 11 ]
column index = [ 9 8 10 1 5 11 7 4 6 2 0 3 ]
matrix value = [ 17 8 40 36 52 ]
lib/Algorithm/Bertsekas.pm view on Meta::CPAN
Number of edges: 100
Solution:
Optimal assignment: sum of values = 893
Feasible assignment condition: stepsize = 0.09091 < 1/10 = 0.1
Number of iterations: 27
row index = [ 0 1 2 3 4 5 6 7 8 9 ]
column index = [ 5 0 1 8 9 6 2 4 7 3 ]
matrix value = [ 95 76 100 90 81 99 99 88 75 90 ]
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/BinPack.pm view on Meta::CPAN
This module implements the bin packing algorithm described in 'The
Algorithm Design Manual' by Steven S. Skiena.
This module is similar to L<Algorithm::Bucketizer>, but has a few key
differences. The algorithms in Algorithm::Bucketizer are based on
optimization by multiple iterations, so the module is set up
differently. By contrast, the algorithm used in Algorithm::BinPack is
predictable, and does not require multiple iterations. The name also
reflects the well-known name of the problem. Searching for variations
on "bin packing" finds more relevant results than variations on
"bucketizer".
=head1 AUTHOR
view all matches for this distribution
view release on metacpan or search on metacpan
Bucketizer.pm view on Meta::CPAN
);
Optimize bucket distribution. Currently C<"random"> and C<"brute_force">
are implemented. Both can be (C<"random"> I<must> be) terminated
by either the maximum number of seconds (C<maxtime>) or
iterations (C<maxrounds>).
=back
=head1 EXAMPLE
view all matches for this distribution
view release on metacpan or search on metacpan
src/cluster.c view on Meta::CPAN
*
* On output:
*
* the routine returns an integer ierr equal to
* 0: to indicate a normal return,
* k: if the k-th singular value has not been determined after 30 iterations,
* -1: if memory allocation fails.
*
* w contains the n (non-negative) singular values of a (the
* diagonal elements of s). they are unordered.
* If an error exit is made, the singular values should be correct for
src/cluster.c view on Meta::CPAN
inittau (input) double
The initial value of tau, representing the neighborhood function.
niter (input) int
The number of iterations to be performed.
dist (input) char
Defines which distance measure is used, as given by the table:
dist == 'e': Euclidean distance
dist == 'b': City-block distance
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
my $iter_mode = 'time';
my $time_limit = 3; # sane default?
$time_limit = 0.01 if ($time_limit < 0.01);
my $n_iter;
if (defined($p{iterations})) {
$iter_mode = 'iter';
$n_iter = $p{iterations} || 10000;
} else {
$time_limit = $p{time_limit} // $time_limit;
$n_iter = 10000 * $time_limit; # will use this to figure out how long it -really- takes.
}
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
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);
}
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
=item C<fit(time_limit =E<gt> 3)>
If a time limit is given (in seconds), C<fit()> will spend no more than that long trying to fit the data. It may return in much less time. The default is 3.
=item C<fit(iterations =E<gt> 10000)>
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>.
lib/Algorithm/CurveFit/Simple.pm view on Meta::CPAN
=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.
view all matches for this distribution
view release on metacpan or search on metacpan
examples/examplefit.pl view on Meta::CPAN
my @parameters = (
# Name Guess Accuracy
['b', 10, 0.0001],
['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,
);
use Data::Dumper;
print Dumper \@parameters;
print Dumper $square_residual;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/RegressionTree.pm view on Meta::CPAN
while (1) {
print "*" unless $master_interation_index++ % 100;
last unless $iterate_again_flag;
$gamma *= 0.1;
$beta0 = 0.99 * $beta0;
print "\n\n======== starting iterations with gamma= $gamma ===========\n\n\n" if $self->{_debug2_r};
$beta = $beta0;
my $beta_old = Math::GSL::Matrix->new($betarows, 1)->zero;
my $error_old = sum( map abs, ($y - ($X * $beta_old) )->col(0)->as_list ) / $nrows;
my $error;
foreach my $iteration (0 .. 1499) {
lib/Algorithm/RegressionTree.pm view on Meta::CPAN
print "\n\niteration: $iteration gamma: $gamma current error: $error\n";
print "\nnew beta:\n";
display_matrix $beta;
}
if ( vector_norm($beta - $beta_old) < (0.00001 * vector_norm($beta_old)) ) {
print "iterations used: $iteration with gamma: $gamma\n" if $self->{_debug2_r};
$iterate_again_flag = 0;
last;
}
$error_old = $error;
}
view all matches for this distribution
view release on metacpan or search on metacpan
script/bitflip.pl view on Meta::CPAN
use Algorithm::Evolutionary::Simple qw( random_chromosome mutate);
use Time::HiRes qw( gettimeofday tv_interval );
use v5.14;
my $length = 16;
my $iterations = 100000;
my $top_length = 2**15;
do {
my $indi = random_chromosome($length);
say "perlsimple-BitString, $length, ".time_mutations( $iterations, $indi );
$length *= 2;
} while $length <= $top_length;
#--------------------------------------------------------------------
sub time_mutations {
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/Evolutionary/Op/Permutation.pm view on Meta::CPAN
my $op = new Algorithm::Evolutionary::Op::Permutation ; #Create from scratch
my $bit_chromosome = new Algorithm::Evolutionary::Individual::BitString 10;
$op->apply( $bit_chromosome );
my $priority = 2;
my $max_iterations = 100; # Less than 10!, absolute maximum number
# of permutations
$op = new Algorithm::Evolutionary::Op::Permutation $priority, $max_iterations;
my $xmlStr=<<EOC;
<op name='Permutation' type='unary' rate='2' />
EOC
my $ref = XMLin($xmlStr);
lib/Algorithm/Evolutionary/Op/Permutation.pm view on Meta::CPAN
Class independent permutation operator; any individual that has the
C<_str> instance variable (like
L<Algorithm::Evolutionary::Individual::String> and
L<Algorithm::Evolutionary::Individual::BitString>) will have some
of its elements swapped. Each string of length l has l!
permutations; the C<max_iterations> parameter should not be higher
than that.
This kind of operator is used extensively in combinatorial
optimization problems. See, for instance,
@article{prins2004simple,
lib/Algorithm/Evolutionary/Op/Permutation.pm view on Meta::CPAN
our $APPLIESTO = 'Algorithm::Evolutionary::Individual::String';
our $ARITY = 1;
=head1 METHODS
=head2 new( [$rate = 1][, $max_iterations = 10] )
Creates a new permutation operator; see
L<Algorithm::Evolutionary::Op::Base> for details common to all
operators. The chromosome will undergo a random number of at most
C<$max_iterations>. By default, it equals 10.
=cut
sub new {
my $class = shift;
lib/Algorithm/Evolutionary/Op/Permutation.pm view on Meta::CPAN
sub create {
my $class = shift;
my $rate = shift || 1;
my $self = { rate => $rate,
max_iterations => shift || 10 };
bless $self, $class;
return $self;
}
=head2 apply( $chromosome )
Applies at most C<max_iterations> permutations to a "Chromosome" that includes the C<_str>
instance variable. The number of iterations will be random, so
that applications of the operator on the same individual will
create diverse offspring.
=cut
lib/Algorithm/Evolutionary/Op/Permutation.pm view on Meta::CPAN
my $other_point = shift @copy_points ;
substr( $victim->{'_str'}, $this_point, 1, $arr[$other_point]);
}
# my $p = new Algorithm::Permute( \@arr );
# my $iterations = 1+rand($self->{'_max_iterations'}-1);
# for (1..$iterations) {
# @arr = $p->next;
# }
# if ( !@arr) {
# croak "I broke \@arr $iterations ", $self->{'_max_iterations'}, " ", $victim->{'_str'}, "\n";
# }
# if ( join( "", @arr ) eq $arg->{'_str'} ) {
# # Check for all equal
# my %letters;
# map( $letters{$_}=1, @arr );
# if ( scalar keys %letters > 1) {
# $p->reset; # We are looking for anything different, after all
# do {
# @arr = $p->next;
# } until ( join( "", @arr ) ne $arg->{'_str'} );
# # print "Vaya tela $iterations ", $self->{'_max_iterations'}, " ", $victim->{'_str'}, "\n";
# # print $victim->{'_str'}, "\n";
# }
# }
# if ( !@arr) {
# croak "Gosh $iterations ", $self->{'_max_iterations'}, " ", $victim->{'_str'}, "\n";
# }
return $victim;
}
=head2 SEE ALSO
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/Evolve.pm view on Meta::CPAN
C<suspend>'ed.
=item C<$p-E<gt>suspend()>
Call this method from within the callback function to stop the algorithm's
iterations and return from the C<run> method.
=item C<$p-E<gt>resume()>
Start up the algorithm again after being C<suspend>'ed.
view all matches for this distribution
view release on metacpan or search on metacpan
examples/canned_example1.pl view on Meta::CPAN
my $clusterer = Algorithm::ExpectationMaximization->new(
datafile => $datafile,
mask => $mask,
K => 3,
max_em_iterations => 300,
seeding => 'random',
terminal_output => 1,
debug => 0,
);
examples/canned_example1.pl view on Meta::CPAN
$clusterer->visualize_clusters($visualization_mask);
$clusterer->visualize_distributions($visualization_mask);
$clusterer->plot_hardcopy_clusters($visualization_mask);
$clusterer->plot_hardcopy_distributions($visualization_mask);
$clusterer->display_fisher_quality_vs_iterations();
$clusterer->display_mdl_quality_vs_iterations();
my $estimated_priors = $clusterer->return_estimated_priors();
print "Estimated class priors: @$estimated_priors\n";
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/FuzzyCmeans.pm view on Meta::CPAN
Add an input document to the instance of Algorithm::FuzzyCmeans. $id parameter is the identifier of a document, and $vector parameter is the feature vector of a document. $vector parameter must be a hash reference, each key of $vector parameter is th...
=head2 do_clustering($num_cluster, $num_iter)
Do clustering input documents. $num_cluster parameter specifies the number of output clusters, and $num_iter parameter specifies the number of clustering iterations.
=head2 memberships
This method is the accessor of clustering result. The output of the method is a hash reference, the key is the identifier of each input document, and the value is the list of the degrees of membership of each input document in output clusters.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/GoldenSection.pm view on Meta::CPAN
See http://en.wikipedia.org/wiki/Golden_section_search and
http://www.gnu.org/software/gsl/manual/html_node/One-dimensional-Minimization.html.
The module provides a Perl5OO interface. Simply construct a Algorithm::GoldenSection object with appropriate parameters
- see L</SYNOPSIS>. Then call the minimise C<method>. This returns a LIST of the value of x at the minimum, the value of
f(x) at the minimum and the number of iterations used to isolate the minimum.
=cut
=head1 SYNOPSIS
use Algorithm::GoldenSection;
lib/Algorithm/GoldenSection.pm view on Meta::CPAN
$gs = Algorithm::GoldenSection->new( { function => sub { my $x = shift; my $b = $x * sin($x) - 2 * cos($x); return $b },
x_low => 4,
x_int => 4.7,} ) ;
# Call minimisation method to bracket and minimise.
my ($x_min, $f_min, $iterations) = $gs->minimise;
print qq{\nMinimisation results: x a minimum = $x_min, function value at minimum = $f_min. Calculation took $iterations iterations};
=cut
# package-scoped lexicals
Readonly::Scalar my $ouro => 1.618034 ;
view all matches for this distribution
view release on metacpan or search on metacpan
eg/rainmidi3000.pl view on Meta::CPAN
# What thing did we wire up? Some way to visualize this over time might
# also help direct one towards better wirings?
show_wiring($glist);
{
# TWEAK fewer slosh iterations makes the fluid more viscous and thus
# less able to spread out to adjacent cells
#my $slosh_iters;
my $slosh_iters = 2;
my %slosh;
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/KMeans.pm view on Meta::CPAN
# "best" QoC values for all possible K in this manner, it then finds the K for which
# the QoC is the minimum. This is taken to be the best value for K. Finally, the
# output clusters are written out to separate files.
#
# If the KMeans constructor is invoked with the (Kmin, Kmax) options, then, instead
# of iterating through 2 and the maximum permissible value for K, the iterations are
# carried out only between Kmin and Kmax.
sub iterate_through_K {
my $self = shift;
my @all_data_ids = @{$self->{_data_id_tags}};
my $N = $self->{_N};
lib/Algorithm/KMeans.pm view on Meta::CPAN
# This is the main routine that along with the update_cluster_centers() routine
# constitute the two key steps of the K-Means algorithm. In most cases, the infinite
# while() loop will terminate automatically when the cluster assignments of the data
# points remain unchanged. For the sake of safety, we keep track of the number of
# iterations. If this number reaches 100, we exit the while() loop anyway. In most
# cases, this limit will not be reached.
sub assign_data_to_clusters {
my $self = shift;
my $clusters = shift;
my $K = shift;
lib/Algorithm/KMeans.pm view on Meta::CPAN
Version 1.1 is a an object-oriented version of the implementation presented in
version 1.0. The current version should lend itself more easily to code extension.
You could, for example, create your own class by subclassing from the class presented
here and, in your subclass, use your own criteria for the similarity distance between
the data points and for the QoC (Quality of Clustering) metric, and, possibly a
different rule to stop the iterations. Version 1.1 also allows you to directly
access the clusters formed and the cluster centers in your calling script.
=head1 SPECIAL USAGE NOTE
lib/Algorithm/KMeans.pm view on Meta::CPAN
What to use for the QoC metric is obviously a critical issue unto itself. In the
current implementation, the value of QoC is the ratio of the average radius of the
clusters and the average distance between the cluster centers.
Every iterative algorithm requires a stopping criterion. The criterion implemented
here is that we stop iterations when there is no re-assignment of the data points
during the assignment step.
Ordinarily, the output produced by a K-Means clusterer will correspond to a local
minimum for the QoC values, as opposed to a global minimum. The current
implementation protects against that when the module constructor is called with the
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/Kmeanspp.pm view on Meta::CPAN
Add an input document to the instance of Algorithm::Kmeanspp. $id parameter is the identifier of a document, and $vector parameter is the feature vector of a document. $vector parameter must be a hash reference, each key of $vector parameter is the i...
=head2 do_clustering($num_cluster, $num_iter)
Do clustering input documents. $num_cluster parameter specifies the number of output clusters, and $num_iter parameter specifies the number of clustering iterations.
=head2 clusters
This method is the accessor of clustering result. The output of the method is a array reference, and each item in the array reference includes the list of the identifiers of input documents in each cluster.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/LBFGS.pm view on Meta::CPAN
'verbose' just prints out all information of each iteration, while 'logging'
logs the same information in an array ref provided by L</"user_data">.
...
# print out the iterations
fmin($eval_cb, $x0, 'verbose');
# log iterations information in the array ref $log
my $log = [];
fmin($eval_cb, $x0, 'logging', $log);
use Data::Dumper;
lib/Algorithm/LBFGS.pm view on Meta::CPAN
=head3 m
The number of corrections to approximate the inverse hessian matrix.
The L-BFGS algorithm stores the computation results of previous L</"m">
iterations to approximate the inverse hessian matrix of the current
iteration. This parameter controls the size of the limited memories
(corrections). The default value is 6. Values less than 3 are not
recommended. Large values will result in excessive computing time.
=head3 epsilon
lib/Algorithm/LBFGS.pm view on Meta::CPAN
||grad f(x)|| < epsilon * max(1, ||x||)
where ||.|| denotes the Euclidean (L2) norm. The default value is 1e-5.
=head3 max_iterations
The maximum number of iterations.
The L-BFGS algorithm terminates an optimization process with
L</"LBFGSERR_MAXIMUMITERATION"> status code when the iteration count
exceedes this parameter. Setting this parameter to zero continues an
optimization process until a convergence or error. The default value is 0.
lib/Algorithm/LBFGS.pm view on Meta::CPAN
The line-search routine reaches the maximum number of evaluations.
=head3 LBFGSERR_MAXIMUMITERATION
The algorithm routine reaches the maximum number of iterations.
=head3 LBFGSERR_WIDTHTOOSMALL
Relative width of the interval of uncertainty is at most L</"xtol">.
view all matches for this distribution
view release on metacpan or search on metacpan
# ================================
use Getopt::Long;
use Algorithm::LDA;
eval(GetOptions( "version", "help", "topics=s", "stop=s", "iterations=s")) or die ("Please check the above mentioned option(s).\n");
# if help is defined, print out help
if( defined $opt_help ) {
$opt_help = 1;
&showHelp();
# $updateCorpus - 1 = Force update documents, 0 = allow loading from JSON
# $wordThreshold - Minimum number of documents a word must appear in
# $alpha - Default Alpha value
# $numWords - Number of words per topic
my $maxIterations = 1000;
if(defined $opt_iterations) {
$maxIterations = $opt_iterations;
}
my $updateCorpus = 0;
my $wordThreshold = 10;
my $alpha = 0.1;
my $numWords = 5;
print "--help Prints this help message.\n\n";
print "--stoplist FILE A file containing a list of words to be excluded\n\n";
print "--iterations NUM Max number of iterations [Default: 1000]\n\n";
print "--topics NUM Number of topics [Default: 10]\n\n";
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/LUHN_XS.pm view on Meta::CPAN
Perl Algorithm::LUHN module, while the faster check_digit_fast() and really fast
check_digit_rff() are not.
How much faster? Here's a benchmark, running on a 3.4GHz i7-2600:
C<Benchmark: timing 100 iterations>
C<Algorithm::LUHN: 69 secs (69.37 usr 0.00 sys) 1.44/s>
C<check_digit: 2 secs ( 1.98 usr 0.00 sys) 50.51/s>
lib/Algorithm/LUHN_XS.pm view on Meta::CPAN
As with check_digit(), we have 3 versions of is_valid(), each one progressively
faster than the check_digit() that comes in the original pure Perl
Algorithm::LUHN module. Here's a benchmark of 1M total calls to is_valid():
C<Benchmark: timing 100 iterations>
C<Algorithm::LUHN: 100 secs (100.29 usr 0.01 sys) 1.00/s>
C<is_valid: 3 secs ( 2.46 usr 0.11 sys) 38.91/s>
view all matches for this distribution
view release on metacpan or search on metacpan
src/liblinear/linear.cpp view on Meta::CPAN
start_from_all = false;
}
info("\noptimization finished, #iter = %d\n",iter);
if (iter >= max_iter)
info("\nWARNING: reaching max number of iterations\n");
// calculate objective value
double v = 0;
int nSV = 0;
for(i=0;i<w_size*nr_class;i++)
src/liblinear/linear.cpp view on Meta::CPAN
// x, y, Cp, Cn
// eps is the stopping tolerance
//
// solution will be put in w
//
// this function returns the number of iterations
//
// See Algorithm 3 of Hsieh et al., ICML 2008
#undef GETI
#define GETI(i) (y[i]+1)
src/liblinear/linear.cpp view on Meta::CPAN
// x, y, p, C
// eps is the stopping tolerance
//
// solution will be put in w
//
// this function returns the number of iterations
//
// See Algorithm 4 of Ho and Lin, 2012
#undef GETI
#define GETI(i) (0)
src/liblinear/linear.cpp view on Meta::CPAN
// x, y, Cp, Cn
// eps is the stopping tolerance
//
// solution will be put in w
//
// this function returns the number of iterations
//
// See Algorithm 5 of Yu et al., MLJ 2010
#undef GETI
#define GETI(i) (y[i]+1)
src/liblinear/linear.cpp view on Meta::CPAN
// x, y, Cp, Cn
// eps is the stopping tolerance
//
// solution will be put in w
//
// this function returns the number of iterations
//
// See Yuan et al. (2010) and appendix of LIBLINEAR paper, Fan et al. (2008)
//
// To not regularize the bias (i.e., regularize_bias = 0), a constant feature = 1
// must have been added to the original data. (see -B and -R option)
src/liblinear/linear.cpp view on Meta::CPAN
Gmax_old = Gmax_new;
}
info("\noptimization finished, #iter = %d\n", iter);
if(iter >= max_iter)
info("\nWARNING: reaching max number of iterations\n");
// calculate objective value
double v = 0;
int nnz = 0;
src/liblinear/linear.cpp view on Meta::CPAN
// x, y, Cp, Cn
// eps is the stopping tolerance
//
// solution will be put in w
//
// this function returns the number of iterations
//
// See Yuan et al. (2011) and appendix of LIBLINEAR paper, Fan et al. (2008)
//
// To not regularize the bias (i.e., regularize_bias = 0), a constant feature = 1
// must have been added to the original data. (see -B and -R option)
src/liblinear/linear.cpp view on Meta::CPAN
QP_Gmax_old = QP_Gmax_new;
}
if(iter >= max_iter)
info("WARNING: reaching max number of inner iterations\n");
delta = 0;
w_norm_new = 0;
for(j=0; j<w_size; j++)
{
src/liblinear/linear.cpp view on Meta::CPAN
}
info("=========================\n");
info("optimization finished, #iter = %d\n", newton_iter);
if(newton_iter >= max_newton_iter)
info("WARNING: reaching max number of iterations\n");
// calculate objective value
double v = 0;
int nnz = 0;
src/liblinear/linear.cpp view on Meta::CPAN
// x, nu
// eps is the stopping tolerance
//
// solution will be put in w and rho
//
// this function returns the number of iterations
//
// See Algorithm 7 in supplementary materials of Chou et al., SDM 2020.
static int solve_oneclass_svm(const problem *prob, const parameter *param, double *w, double *rho)
{
src/liblinear/linear.cpp view on Meta::CPAN
if (iter % 10 == 0)
info(".");
}
info("\noptimization finished, #iter = %d\n",iter);
if (iter >= max_iter)
info("\nWARNING: reaching max number of iterations\n\n");
// calculate object value
double v = 0;
for(i=0; i<w_size; i++)
v += w[i]*w[i];
src/liblinear/linear.cpp view on Meta::CPAN
case L2R_L2LOSS_SVC_DUAL:
{
iter = solve_l2r_l1l2_svc(prob, param, w, Cp, Cn, dual_solver_max_iter);
if(iter >= dual_solver_max_iter)
{
info("\nWARNING: reaching max number of iterations\nSwitching to use -s 2\n\n");
// primal_solver_tol obtained from eps for dual may be too loose
primal_solver_tol *= 0.1;
l2r_l2_svc_fun fun_obj(prob, param, C);
NEWTON newton_obj(&fun_obj, primal_solver_tol);
newton_obj.set_print_string(liblinear_print_string);
src/liblinear/linear.cpp view on Meta::CPAN
}
case L2R_L1LOSS_SVC_DUAL:
{
iter = solve_l2r_l1l2_svc(prob, param, w, Cp, Cn, dual_solver_max_iter);
if(iter >= dual_solver_max_iter)
info("\nWARNING: reaching max number of iterations\nUsing -s 2 may be faster (also see FAQ)\n\n");
break;
}
case L1R_L2LOSS_SVC:
{
problem prob_col;
src/liblinear/linear.cpp view on Meta::CPAN
case L2R_LR_DUAL:
{
iter = solve_l2r_lr_dual(prob, param, w, Cp, Cn, dual_solver_max_iter);
if(iter >= dual_solver_max_iter)
{
info("\nWARNING: reaching max number of iterations\nSwitching to use -s 0\n\n");
// primal_solver_tol obtained from eps for dual may be too loose
primal_solver_tol *= 0.1;
l2r_lr_fun fun_obj(prob, param, C);
NEWTON newton_obj(&fun_obj, primal_solver_tol);
newton_obj.set_print_string(liblinear_print_string);
src/liblinear/linear.cpp view on Meta::CPAN
}
case L2R_L1LOSS_SVR_DUAL:
{
iter = solve_l2r_l1l2_svr(prob, param, w, dual_solver_max_iter);
if(iter >= dual_solver_max_iter)
info("\nWARNING: reaching max number of iterations\nUsing -s 11 may be faster (also see FAQ)\n\n");
break;
}
case L2R_L2LOSS_SVR_DUAL:
{
iter = solve_l2r_l1l2_svr(prob, param, w, dual_solver_max_iter);
if(iter >= dual_solver_max_iter)
{
info("\nWARNING: reaching max number of iterations\nSwitching to use -s 11\n\n");
// primal_solver_tol obtained from eps for dual may be too loose
primal_solver_tol *= 0.001;
l2r_l2_svr_fun fun_obj(prob, param, C);
NEWTON newton_obj(&fun_obj, primal_solver_tol);
newton_obj.set_print_string(liblinear_print_string);
view all matches for this distribution
view release on metacpan or search on metacpan
examples/example1.pl view on Meta::CPAN
my $clusterer = Algorithm::LinearManifoldDataClusterer->new(
datafile => $datafile,
mask => $mask,
K => 3, # number of clusters
P => 2, # manifold dimensionality
max_iterations => 15,
cluster_search_multiplier => 2,
delta_reconstruction_error => 0.001,
terminal_output => 1,
visualize_each_iteration => 1,
show_hidden_in_3D_plots => 1,
examples/example1.pl view on Meta::CPAN
$clusterer->get_data_from_csv();
my $clusters = $clusterer->linear_manifold_clusterer();
$clusterer->display_reconstruction_errors_as_a_function_of_iterations();
$clusterer->write_clusters_to_files($clusters);
$clusterer->visualize_clusters_on_sphere("final clustering", $clusters);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/Loops.pm view on Meta::CPAN
permutations have the lowest values at the front of the list. As you
iterate, larger values are shifted to be in front of smaller values,
starting at the back of the list. So the value at the very front of the
list will change the fewest times (once for each unique value in the
list), while the value at the very end of the list changes between most
iterations.
=item Fast
If you don't have to deal with duplicate values, then Algorithm::Permute
provides some routines written in C (which makes them harder to install
lib/Algorithm/Loops.pm view on Meta::CPAN
=head4 Iterator
If you don't pass in a final code reference to NestedLoops, then
NestedLoops will return an iterator to you (without having performed
any iterations yet).
The iterator is a code reference. Each time you call it, it returns the
next list of selected values. Any arguments you pass in are ignored (at
least in this release).
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/MasterMind/Evo.pm view on Meta::CPAN
croak "No population" if $self->{'_pop_size'} == 0;
# Variation operators
my $mutation_rate = $options->{'mutation_rate'} || 1;
my $permutation_rate = $options->{'permutation_rate'} || 0;
my $permutation_iters = $options->{'permutation_iterations'} || factorial($options->{'length'}) - 1 ;
my $xover_rate = $options->{'xover_rate'} || 1;
my $max_number_of_consistent = $options->{'consistent_set_card'}
|| MAX_CONSISTENT_SET;
$self->{'_replacement_rate'}= $self->{'_replacement_rate'} || 0.25;
my $m = new Algorithm::Evolutionary::Op::String_Mutation $mutation_rate ; # Rate = 1
view all matches for this distribution
view release on metacpan or search on metacpan
PageRank.pm view on Meta::CPAN
Feed the graph topology. Vertices count from 0.
=head2 iterate
Calculate the pagerank vector. The parameter is the maximal number of
iterations. If the vector does not converge before reaching the
threshold, then calculation will stop at the maximum. Default
iteration number is 100.
You can also reset the dampening factor
($Algorithm::PageRank::d_factor). The default value is 0.05.
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/RandomPointGenerator.pm view on Meta::CPAN
"metropolis_hastings()$!\n" unless $self->{_normalized_input_hist};
die "\nyou must first call set_sigmas_for_proposal_density() before you can call\n" .
"metropolis_hastings()$!\n" unless $self->{_sigmax_for_proposal_density};
my $box = $self->{_bounding_box};
my $N_discard = $self->{_how_many_to_discard};
my $N_iterations = $self->{_N} + $N_discard;
my $sample = [$box->[0][0] + ($box->[0][1] - $box->[0][0]) / 2.0,
$box->[1][0] + ($box->[1][1] - $box->[1][0]) / 2.0];
while ($self->desired_density($sample) == 0) {
$sample = [$self->{_bounding_box}->[0][0] +
random_uniform() * ($self->{_bounding_box}->[0][1] - $self->{_bounding_box}->[0][0]),
$self->{_bounding_box}->[1][0] +
random_uniform() * ($self->{_bounding_box}->[1][1] - $self->{_bounding_box}->[1][0])]
}
print "\nstarting sample: @$sample\n" unless $self->{_command_line_mode};
if ($self->{_command_line_mode}) {
print "\nThe Metropolis-Hastings algorithm will be run over 2500 iterations.\n" .
"Of the 2500 points generated, the first 500 will be discarded.\n" .
"Each dot shown below stands for 50 iterations of the algorithm.\n\n";
} else {
print "\nThe Metropolis-Hastings algorithm will be run for $N_discard more iterations\n" .
"than the number of points you requested. The first $N_discard initial points thus\n" .
"generated will be discarded from the final output.\n\n";
}
my @arr;
foreach my $i (0..$N_iterations-1) {
unless ($self->{_command_line_mode}) {
print "\nIteration number: $i (out of $N_iterations)\n" if $i % ($N_iterations / 10) == 0;
}
print ". " if $i % 50 == 0;
# Get proposal probability q( $y | $x ).
my ($newsample, $prob) = $self->get_sample_using_proposal( $sample );
my $a1 = $self->desired_density( $newsample ) / $self->desired_density( $sample );
lib/Algorithm/RandomPointGenerator.pm view on Meta::CPAN
push @arr, $sample;
} else {
push @arr, $sample;
}
}
print "\nTotal number of iterations run: $N_iterations\n\n" unless $self->{_command_line_mode};
$self->{_generated_points} = \@arr;
}
# From the standpoint of matching the input histogram, the quality of the random
# points generated by the Metropolis-Hastings algorithm is affected by what sort of a
view all matches for this distribution
view release on metacpan or search on metacpan
}
active_size--;
}
}
// unshrink, check all variables again before final iterations
if(unshrinked || Gmax1 + Gmax2 > eps*10) return;
unshrinked = true;
reconstruct_gradient();
}
active_size--;
}
}
// unshrink, check all variables again before final iterations
if(unshrinked || max(Gmax1+Gmax2,Gmax3+Gmax4) > eps*10) return;
unshrinked = true;
reconstruct_gradient();
for (i=0;i<l;i++)
if (labels[i] > 0) prior1+=1;
else prior0+=1;
int max_iter=100; // Maximal number of iterations
double min_step=1e-10; // Minimal step taken in line search
double sigma=1e-12; // For numerically strict PD of Hessian
double eps=1e-5;
double hiTarget=(prior1+1.0)/(prior1+2.0);
double loTarget=1/(prior0+2.0);
break;
}
}
if (iter>=max_iter)
info("Reaching maximal iterations in two-class probability estimates\n");
free(t);
}
double sigmoid_predict(double decision_value, double A, double B)
{
view all matches for this distribution
view release on metacpan or search on metacpan
SVMLight.patch view on Meta::CPAN
+ printf("\nMaximum size of QP-subproblems [%ld] must be larger than the number of\n",learn_parm->svm_maxqpsize);
+ printf("new variables [%ld] entering the working set in each iteration.\n",learn_parm->svm_newvarsinqp);
+ return 0;
+ }
+ if(learn_parm->svm_iter_to_shrink<1) {
+ printf("\nMaximum number of iterations for shrinking not in valid range: %ld [1,..]\n",learn_parm->svm_iter_to_shrink);
+ return 0;
+ }
+ if(learn_parm->svm_c<0) {
+ printf("\nThe C parameter must be greater than zero!\n\n");
+ return 0;
SVMLight.patch view on Meta::CPAN
- wait_any_key();
- print_help();
- exit(0);
- }
- if(learn_parm->svm_iter_to_shrink<1) {
- printf("\nMaximum number of iterations for shrinking not in valid range: %ld [1,..]\n",learn_parm->svm_iter_to_shrink);
- wait_any_key();
- print_help();
- exit(0);
- }
- if(learn_parm->svm_c<0) {
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Algorithm/SpiralSearch.pm view on Meta::CPAN
our @EXPORT = qw(spiral_search);
our $VERSION = '1.20';
sub spiral_search {
my $usage = '($opt_x, $opt_y) = spiral_search($lower_boundx,$upper_boundx,' .
'$lower_boundy,$upper_boundy,$iterations,$function,' .
"'MAX|MIN')";
my ($lbx, $ubx, $lby, $uby, $iters, $f, $max_or_min) = @_;
croak 'A valid input/output funtion reference must be passed in'
unless $f =~ /CODE/;
croak 'Two or more iterations are required : ' if $iters < 2;
croak 'Upper boundary on first parameter must be non-zero : ' if $ubx == 0.0;
croak 'Upper boundary on second parameter must be non-zero : '
if $uby == 0.0;
croak 'Final parameter must be set to MAX or MIN : '
lib/Algorithm/SpiralSearch.pm view on Meta::CPAN
}
=head1 DESCRIPTION
A spiral search is a method used to optimize a two-parameter, relatively,
well-behaved function. Boundary conditions, the maximum number of iterations, a
reference to a function, and an indicator to maximize or minimize the function
are passed to the spiral_search function. spiral_search() returns the optimal
point in the function passed to it. It's an elegant optimization algorithm, but
is not well-suited for most applications. SETI uses the spiral search in huntingfor strong radio signals. Spiral search is most effective in situations where
function evaluations are expensive and where there's a small amount of random
lib/Algorithm/SpiralSearch.pm view on Meta::CPAN
=head1 METHODS
=head2 Search Methods
B<spiral_search($lowerBound_x, $upperBound_x, $lowerBound_y, $upperBound_y,
$iterations, \&function, $MAX_or_MIN)>
Initiates the spiral search. The first four parameters define the search space
plane. Spiral search is of order O(n), so the number of iterations defines how
many refinements the algorithm should take into account. The greater the numberof iterations, the more accurate the findings.
The sixth parameter should be a reference to a function for which the parameters
will be plugged into. This function should return only one value - a scalar
output indicative of the accuracy of the inputs. The last input parameter shouldbe either one of the two strings 'MAX' or 'MIN', each corresponding to how
spiral_search will optimize its given function. spiral_search returns a pair of
view all matches for this distribution