AI-ParticleSwarmOptimization-MCE
view release on metacpan or search on metacpan
# only for many-core version # the best if == $#cores of your system
# selecting best value if undefined
-workers => 4,
);
my $fitValue = $pso->optimize ();
my ($best) = $pso->getBestParticles (1);
my ($fit, @values) = $pso->getParticleBestPos ($best);
printf "Fit %.4f at (%s)\n",
$fit, join ', ', map {sprintf '%.4f', $_} @values;
sub calcFit {
my @values = @_;
my $offset = int (-@values / 2);
my $sum;
select( undef, undef, undef, 0.01 ); # Simulation of heavy processing...
$sum += ($_ - $offset++) ** 2 for @values;
return $sum;
-exitPlateauBurnin: number, optional
Determines how many iterations to run before checking for plateaus.
Defaults to 50% of the number of iterations (-iterations).
-verbose: flags, optional
If set to a non-zero value -verbose determines the level of
diagnostic print reporting that is generated during optimization.
The following constants may be bitwise ored together to set logging
options:
* kLogBetter
prints particle details when its fit becomes bebtter than its
previous best.
* kLogStall
prints particle details when its velocity reaches 0 or falls
below the stall threshold.
* kLogIter
Shows the current iteration number.
* kLogDetail
Shows additional details for some of the other logging options.
example/PSOTest-MultiCore.pl view on Meta::CPAN
my $beg = time;
$pso->init();
my $fitValue = $pso->optimize ();
my ( $best ) = $pso->getBestParticles (1);
my ( $fit, @values ) = $pso->getParticleBestPos ($best);
my $iters = $pso->getIterationCount();
printf "Fit %.4f at (%s) after %d iterations\n", $fit, join (', ', map {sprintf '%.4f', $_} @values), $iters;
warn "\nTime: ", time - $beg, "\n\n";
#=======================================================================
exit 0;
lib/AI/ParticleSwarmOptimization/MCE.pm view on Meta::CPAN
}
#-------------------------------------------------------------------
return \@chk;
}
#=======================================================================
sub _updateVelocities {
my ( $self, $iter ) = @_;
#-------------------------------------------------------------------
print "Iter $iter\n" if $self->{verbose} & AI::ParticleSwarmOptimization::kLogIter;
my $tpl = $self->_tpl;
my @lst = mce_map {
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $ary = $_;
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $arg = clone( $tpl );
$arg->{ -numParticles } = 1;
lib/AI/ParticleSwarmOptimization/MCE.pm view on Meta::CPAN
$self->{ bestBest } = min grep { defined $_ } map { $_->[ 1 ] } @lst;
#-------------------------------------------------------------------
return;
}
#=======================================================================
sub _moveParticles {
my ( $self, $iter ) = @_;
#-------------------------------------------------------------------
print "Iter $iter\n" if $self->{verbose} & AI::ParticleSwarmOptimization::kLogIter;
my $tpl = $self->_tpl;
my @lst = mce_map {
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $ary = $_;
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $arg = clone( $tpl );
$arg->{ -numParticles } = 1;
lib/AI/ParticleSwarmOptimization/MCE.pm view on Meta::CPAN
# only for many-core version # the best if == $#cores of your system
# selecting best value if undefined
-workers => 4,
);
my $fitValue = $pso->optimize ();
my ($best) = $pso->getBestParticles (1);
my ($fit, @values) = $pso->getParticleBestPos ($best);
printf "Fit %.4f at (%s)\n",
$fit, join ', ', map {sprintf '%.4f', $_} @values;
sub calcFit {
my @values = @_;
my $offset = int (-@values / 2);
my $sum;
select( undef, undef, undef, 0.01 ); # Simulation of heavy processing...
$sum += ($_ - $offset++) ** 2 for @values;
return $sum;
lib/AI/ParticleSwarmOptimization/MCE.pm view on Meta::CPAN
Defaults to 10% of the number of iterations (I<-iterations>).
=item I<-exitPlateauBurnin>: number, optional
Determines how many iterations to run before checking for plateaus.
Defaults to 50% of the number of iterations (I<-iterations>).
=item I<-verbose>: flags, optional
If set to a non-zero value I<-verbose> determines the level of diagnostic print
reporting that is generated during optimization.
The following constants may be bitwise ored together to set logging options:
=over 4
=item * kLogBetter
prints particle details when its fit becomes bebtter than its previous best.
=item * kLogStall
prints particle details when its velocity reaches 0 or falls below the stall
threshold.
=item * kLogIter
Shows the current iteration number.
=item * kLogDetail
Shows additional details for some of the other logging options.
( run in 0.448 second using v1.01-cache-2.11-cpan-de7293f3b23 )