AI-ParticleSwarmOptimization-MCE

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    AI::ParticleSwarmOptimization::MCE - Particle Swarm Optimization
    (object oriented) with support for multi-core processing

SYNOPSIS

        use AI::ParticleSwarmOptimization::MCE;
    
        my $pso = AI::ParticleSwarmOptimization::MCE->new (
            -fitFunc        => \&calcFit,
            -dimensions     => 3,
            -iterations     => 10,
            -numParticles   => 1000,
            
            # 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);

README  view on Meta::CPAN

	representing the current particle position in the hyperspace is
	passed in. There is one value per hyperspace dimension.

      -inertia: positive or zero number, optional

	Determines what proportion of the previous velocity is carried
	forward to the next iteration. Defaults to 0.9

	See also -meWeight and -themWeight.

      -iterations: number, optional

	Number of optimization iterations to perform. Defaults to 1000.

      -meWeight: number, optional

	Coefficient determining the influence of the current local best
	position on the next iterations velocity. Defaults to 0.5.

	See also -inertia and -themWeight.

      -numNeighbors: positive number, optional

	Number of local particles considered to be part of the
	neighbourhood of the current particle. Defaults to the square root
	of the total number of particles.

      -numParticles: positive number, optional

README  view on Meta::CPAN


	Speed below which a particle is considered to be stalled and is
	repositioned to a new random location with a new initial speed.

	By default -stallSpeed is undefined but particles with a speed of 0
	will be repositioned.

      -themWeight: number, optional

	Coefficient determining the influence of the neighbourhod best
	position on the next iterations velocity. Defaults to 0.5.

	See also -inertia and -meWeight.

      -exitPlateau: boolean, optional

	Set true to have the optimization check for plateaus (regions where
	the fit hasn't improved much for a while) during the search. The
	optimization ends when a suitable plateau is detected following the
	burn in period.

README  view on Meta::CPAN


	Defaults to 10.

      -exitPlateauWindow: number, optional

	Specify the size of the window used to calculate the mean for
	comparison to the current output of the fitness function.
	Correlates to the minimum size of a plateau needed to end the
	optimization.

	Defaults to 10% of the number of iterations (-iterations).

      -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

README  view on Meta::CPAN


    getParticleBestPos ($particleNum)

      Returns a list containing the best value of the fit and the vector of
      its point in hyper space.

          my ($fit, @vector) = $pso->getParticleBestPos (3)

    getIterationCount ()

      Return the number of iterations performed. This may be useful when
      the -exitFit criteria has been met or where multiple calls to
      optimize have been made.

BUGS

    None... I hope.

    If any: A small script which yields the problem will probably be of
    help.

example/PSOTest-MultiCore.pl  view on Meta::CPAN

    return $sum;
}
#=======================================================================
++$|;
#-----------------------------------------------------------------------
#my $pso = AI::ParticleSwarmOptimization::Pmap->new(		# Multi-core	
my $pso = AI::ParticleSwarmOptimization::MCE->new(		# Multi-core	
#my $pso = AI::ParticleSwarmOptimization->new(			# Single-core
    -fitFunc    	=> \&calcFit,
    -dimensions 	=> 10,
    -iterations 	=> 10,
    -numParticles	=> 1000,
    
    # only for many-core version # the best if == $#cores of your system
    # selecting best value if undefined
    -workers		=> 4,							
);


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 $self;
}
#=======================================================================
sub _init_tpl {
	my ( $self, $params ) = @_;
	
	my $cln = clone( $params );
	delete $cln->{ $_ } for qw( 
		-iterCount
		-iterations	
		-numParticles 
		-workers
		
		_pop 
		_tpl 
		_wrk 
	);
	
	$self->_tpl( $cln );
	

lib/AI/ParticleSwarmOptimization/MCE.pm  view on Meta::CPAN


AI::ParticleSwarmOptimization::MCE - Particle Swarm Optimization (object oriented) with support for multi-core processing

=head1 SYNOPSIS

    use AI::ParticleSwarmOptimization::MCE;

    my $pso = AI::ParticleSwarmOptimization::MCE->new (
        -fitFunc        => \&calcFit,
        -dimensions     => 3,
        -iterations     => 10,
        -numParticles   => 1000,
        
        # 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);

lib/AI/ParticleSwarmOptimization/MCE.pm  view on Meta::CPAN

current particle position in the hyperspace is passed in. There is one value per
hyperspace dimension.

=item I<-inertia>: positive or zero number, optional

Determines what proportion of the previous velocity is carried forward to the
next iteration. Defaults to 0.9

See also I<-meWeight> and I<-themWeight>.

=item I<-iterations>: number, optional

Number of optimization iterations to perform. Defaults to 1000.

=item I<-meWeight>: number, optional

Coefficient determining the influence of the current local best position on the
next iterations velocity. Defaults to 0.5.

See also I<-inertia> and I<-themWeight>.

=item I<-numNeighbors>: positive number, optional

Number of local particles considered to be part of the neighbourhood of the
current particle. Defaults to the square root of the total number of particles.

=item I<-numParticles>: positive number, optional

lib/AI/ParticleSwarmOptimization/MCE.pm  view on Meta::CPAN


Speed below which a particle is considered to be stalled and is repositioned to
a new random location with a new initial speed.

By default I<-stallSpeed> is undefined but particles with a speed of 0 will be
repositioned.

=item I<-themWeight>: number, optional

Coefficient determining the influence of the neighbourhod best position on the
next iterations velocity. Defaults to 0.5.

See also I<-inertia> and I<-meWeight>.

=item I<-exitPlateau>: boolean, optional

Set true to have the optimization check for plateaus (regions where the fit
hasn't improved much for a while) during the search. The optimization ends when
a suitable plateau is detected following the burn in period.

Defaults to undefined (option disabled).

lib/AI/ParticleSwarmOptimization/MCE.pm  view on Meta::CPAN

function value and the mean of the previous I<-exitPlateauWindow> values.

Defaults to 10.

=item I<-exitPlateauWindow>: number, optional

Specify the size of the window used to calculate the mean for comparison to
the current output of the fitness function.  Correlates to the minimum size of a
plateau needed to end the optimization.

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

lib/AI/ParticleSwarmOptimization/MCE.pm  view on Meta::CPAN


=item B<getParticleBestPos ($particleNum)>

Returns a list containing the best value of the fit and the vector of its point
in hyper space.

    my ($fit, @vector) = $pso->getParticleBestPos (3)

=item B<getIterationCount ()>

Return the number of iterations performed. This may be useful when the
I<-exitFit> criteria has been met or where multiple calls to I<optimize> have
been made.

=back

=head1 BUGS

None... I hope.

If any: A small script which yields the problem will probably be of help.

t/01_pso_multi.t  view on Meta::CPAN

Test AI::ParticleSwarmOptimization::MCE

=cut

plan (tests => 1);

# Calculation tests.
my $pso = AI::ParticleSwarmOptimization::MCE->new (
    -fitFunc        => \&calcFit,
    -dimensions     => 10,
    -iterations     => 10,
    -numParticles   => 1000,

    # only for many-core version # the best if == $#cores of your system
    # selecting best value if undefined
    -workers        => 4,
);

$pso->init();

my $fitValue         = $pso->optimize ();



( run in 1.704 second using v1.01-cache-2.11-cpan-71847e10f99 )