AI-PSO
view release on metacpan or search on metacpan
Revision history for Perl extension AI::PSO.
0.86 Tue Nov 21 20:41:23 2006
- updated documentation
- added support for original RE & JK algorithm
- abstracted initialization function
0.85 Wed Nov 15 22:30:47 2006
- corrected the fitness function in the test
- added perceptron c++ code that I wrote a long time ago ;)
- added an example (pso_ann.pl) for training a simple feed-forward neural network
- updated POD
0.82 Sat Nov 11 22:20:31 2006
- fixed POD to correctly 'use AI::PSO'
- fixed fitness function in PSO.t
- added research paper to package
- moved into a subversion repository
- removed requirement for perl 5.8.8
- removed printing of solution array in test
0.80 Sat Nov 11 14:22:27 2006
lib/AI/PSO.pm view on Meta::CPAN
# so in N-dimensional hyperspace, the size of the position vector is N
#
# A particle updates its position according the Euler integration equation for physical motion:
# Xi(t) = Xi(t-1) + Vi(t)
# The velocity portion of this contains the stochastic elements of PSO and is defined as:
# Vi(t) = Vi(t-1) + P1*[pi - Xi(t-1)] + P2*[pg - Xi(t-1)]
# where P1 and P2 add are two random values who's sum adds up to the PSO random range (4.0)
# and pi is the individual's best location
# and pg is the global (or neighborhoods) best position
#
# The velocity vector is obviously updated before the position vector...
#
#
my @particles = ();
my $user_fitness_function;
my @solution = ();
#---------- END GLOBAL DATA STRUCTURES --------
#---------- BEGIN EXPORTED SUBROUTINES ----------
lib/AI/PSO.pm view on Meta::CPAN
#
# initialize_particles
# - sets up internal data structures
# - initializes particle positions and velocities with an element of randomness
#
sub initialize_particles() {
for(my $p = 0; $p < $numParticles; $p++) {
$particles[$p] = {}; # each particle is a hash of arrays with the array sizes being the dimensionality of the problem space
$particles[$p]{nextPos} = []; # nextPos is the array of positions to move to on the next positional update
$particles[$p]{bestPos} = []; # bestPos is the position of that has yielded the best fitness for this particle (it gets updated when a better fitness is found)
$particles[$p]{currPos} = []; # currPos is the current position of this particle in the problem space
$particles[$p]{velocity} = []; # velocity ... come on ...
for(my $d = 0; $d < $dimensions; $d++) {
$particles[$p]{nextPos}[$d] = &random($deltaMin, $deltaMax);
$particles[$p]{currPos}[$d] = &random($deltaMin, $deltaMax);
$particles[$p]{bestPos}[$d] = &random($deltaMin, $deltaMax);
$particles[$p]{velocity}[$d] = &random($deltaMin, $deltaMax);
}
}
lib/AI/PSO.pm view on Meta::CPAN
} else {
if($verbose == 1) {
print "N:$iter:$p:$fitness\n"
}
if($verbose == 2) {
&dump_particle($p);
}
}
}
## at this point we've updated our position, but haven't reached the end of the search
## so we turn to our neighbors for help.
## (we see if they are doing any better than we are,
## and if so, we try to fly over closer to their position)
for(my $p = 0; $p < $numParticles; $p++) {
my $n = &get_index_of_best_fit_neighbor($p);
my @meDelta = (); # array of self position updates
my @themDelta = (); # array of neighbor position updates
for(my $d = 0; $d < $dimensions; $d++) {
if($useModifiedAlgorithm) { # this if shold be moved out much further, but i'm working on code refactoring first
( run in 0.427 second using v1.01-cache-2.11-cpan-05444aca049 )