AI::PSO::OO - Particle Swarm Optimization (object oriented)
use AI::PSO::OO; my $pso = AI::PSO::OO->new ( fitFunc => \&calcFit, dimensions => 3, ); 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; $sum += ($_ - $offset++) ** 2 for @values; return $sum; }
AI::PSO::OO provides the following public methods. The parameter lists shown for the methods denote optional parameters by showing them in [].
Create an optimization object. The following parameters may be used:
The number of dimensions of the hypersurface being searched.
If provided -exitFit specifies allows an early termination of optimize if the fitness value becomes equal or less than -exitFit.
-fitFunc is a reference to the fitness function used by the search. If extra parameters need to be passed to the fitness function and array ref may be used with the code ref as the first array element and parameters to be passed into the fitness function as following elements. User provided parameters are passed as the first parameters to the fitness function when it is called:
my $pso = AI::PSO::OO->new ( fitFunc => [\&calcFit, $context], dimensions => 3, ); ... sub calcFit { my ($context, @values) = @_; ... return $fitness; }
In addition to any user provided parameters the list of values representing the current particle position in the hyperspace is passed in. There is one value per hyperspace dimension.
Determines what proportion of the previous velocity is carried forward to the next iteration. Defaults to 0.9
See also -meWeight and -themWeight.
Number of optimization iterations to perform. Defaults to 1000.
Coefficient determining the influence of the current local best position on the next iterations velocity. Defaults to 0.5.
See also -inertia and -themWeight.
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.
Number of particles in the swarm. Defaults to 10 times the number of dimensions.
Maximum coordinate value for any dimension in the hyper space. Defaults to 100.
Minimum coordinate value for any dimension in the hyper space. Defaults to --posMax (if -posMax is negative -posMin should be set more negative).
Seed for the random number generator. Useful if you want to rerun an optimization, perhaps for benchmarking or test purposes.
Set true to initialize particles with a random velocity. Otherwise particle velocity is set to 0 on initalization.
A range based on 1/100th of --posMax - -posMin is used for the initial speed in each dimension of the velocity vector if a random start velocity is used.
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.
Coefficient determining the influence of the neighbourhod best position on the next iterations velocity. Defaults to 0.5.
See also -inertia and -meWeight.
If set to a non-zero value -verbose determines the level of diagnostic print reporting that is generated during optimization.
Set or change optimization parameters. See -new above for a description of the parameters that may be supplied.
Reinitialize the optimization. init () will be called during the first call to optimize () if it hasn't already been called.
Runs the minimization optimization. Returns the fit value of the best fit found. The best possible fit is negative infinity.
Returns the vector of position
Takes an optional count.
Returns a list containing the best $n prtcl numbers. If $n is not specified only the best prtcl number is returned.
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)
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.
Please report any bugs or feature requests to bug-AI-PSO-OO at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AI-PSO-OO. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-AI-PSO-OO at rt.cpan.org
This module is supported by the author through CPAN. The following links may be of assistance:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/AI-PSO-OO
CPAN Ratings
http://cpanratings.perl.org/d/AI-PSO-OO
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=AI-PSO-OO
Search CPAN
http://search.cpan.org/dist/AI-PSO-OO
http://en.wikipedia.org/wiki/Particle_swarm_optimization
This module is an evolution of the AI::PSO module created by Kyle Schlansker.
Peter Jaquiery CPAN ID: GRANDPA grandpa@cpan.org
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
To install AI::PSO::OO, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AI::PSO::OO
CPAN shell
perl -MCPAN -e shell install AI::PSO::OO
For more information on module installation, please visit the detailed CPAN module installation guide.