AI-ParticleSwarmOptimization-MCE

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

NAME

    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);
    
        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;
        }

Description

    This module is enhancement of on original AI::ParticleSwarmOptimization
    to support multi-core processing with use of MCE. Below you can find
    original documentation of that module, but with one difference. There
    is new parameter "-workers", which one can use to define of number of
    parallel processes that will be used during computations.

    The Particle Swarm Optimization technique uses communication of the
    current best position found between a number of particles moving over a
    hyper surface as a technique for locating the best location on the
    surface (where 'best' is the minimum of some fitness function). For a
    Wikipedia discussion of PSO see
    http://en.wikipedia.org/wiki/Particle_swarm_optimization.

    This pure Perl module is an implementation of the Particle Swarm
    Optimization technique for finding minima of hyper surfaces. It
    presents an object oriented interface that facilitates easy
    configuration of the optimization parameters and (in principle) allows
    the creation of derived classes to reimplement all aspects of the
    optimization engine (a future version will describe the replaceable
    engine components).

    This implementation allows communication of a local best point between
    a selected number of neighbours. It does not support a single global
    best position that is known to all particles in the swarm.

Methods

    AI::ParticleSwarmOptimization provides the following public methods.
    The parameter lists shown for the methods denote optional parameters by
    showing them in [].

    new (%parameters)

      Create an optimization object. The following parameters may be used:

      -workers: positive number, optional

	The number of workers (processes), that will be used during
	computations.

      -dimensions: positive number, required

	The number of dimensions of the hypersurface being searched.

      -exitFit: number, optional

README  view on Meta::CPAN


    init ()

      Reinitialize the optimization. init () will be called during the
      first call to optimize () if it hasn't already been called.

    optimize ()

      Runs the minimization optimization. Returns the fit value of the best
      fit found. The best possible fit is negative infinity.

      optimize () may be called repeatedly to continue the fitting process.
      The fit processing on each subsequent call will continue from where
      the last call left off.

    getParticleState ()

      Returns the vector of position

    getBestParticles ([$n])

      Takes an optional count.

      Returns a list containing the best $n particle numbers. If $n is not
      specified only the best particle number is returned.

    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.

SEE ALSO

    http://en.wikipedia.org/wiki/Particle_swarm_optimization

THANKS

    Mario Roy for suggestions about efficiency.

AUTHOR

    Strzelecki Lukasz <lukasz@strzeleccy.eu>

SEE ALSO

    AI::ParticleSwarmOptimization AI::ParticleSwarmOptimization::Pmap

COPYRIGHT

    Copyright (c) Strzelecki Lukasz. All rights reserved. This program is
    free software; you can redistribute it and/or modify it under the same
    terms as Perl itself.



( run in 0.931 second using v1.01-cache-2.11-cpan-39bf76dae61 )