AI-ParticleSwarmOptimization-Pmap

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

{
   "abstract" : "Particle Swarm Optimization (object oriented) with support for multi-core processing",
   "author" : [
      "\u0141ukasz Strzelecki <lukasz@strzeleccy.eu>"
   ],
   "dynamic_config" : 0,
   "generated_by" : "Dist::Zilla version 6.017, CPAN::Meta::Converter version 2.150010",
   "license" : [
      "lgpl_2_1"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",

META.yml  view on Meta::CPAN

---
abstract: 'Particle Swarm Optimization (object oriented) with support for multi-core processing'
author:
  - 'Łukasz Strzelecki <lukasz@strzeleccy.eu>'
build_requires: {}
configure_requires:
  ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.017, CPAN::Meta::Converter version 2.150010'
license: lgpl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html

Makefile.PL  view on Meta::CPAN

# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.017.
use strict;
use warnings;



use ExtUtils::MakeMaker;

my %WriteMakefileArgs = (
  "ABSTRACT" => "Particle Swarm Optimization (object oriented) with support for multi-core processing",
  "AUTHOR" => "\x{141}ukasz Strzelecki <lukasz\@strzeleccy.eu>",
  "CONFIGURE_REQUIRES" => {
    "ExtUtils::MakeMaker" => 0
  },
  "DISTNAME" => "AI-ParticleSwarmOptimization-Pmap",
  "LICENSE" => "lgpl",
  "NAME" => "AI::ParticleSwarmOptimization::Pmap",
  "PREREQ_PM" => {
    "AI::ParticleSwarmOptimization" => "1.006",
    "List::Util" => 0,

README  view on Meta::CPAN

NAME

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

SYNOPSIS

        use AI::ParticleSwarmOptimization::Pmap;
    
        my $pso = AI::ParticleSwarmOptimization::Pmap->new (
            -fitFunc        => \&calcFit,
            -dimensions     => 3,
            -iterations     => 10,
            -numParticles   => 1000,

README  view on Meta::CPAN

        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 Pmap. 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

README  view on Meta::CPAN

    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

	If provided -exitFit allows early termination of optimize if the
	fitness value becomes equal or less than -exitFit.

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.

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

#use AI::ParticleSwarmOptimization;
#use AI::ParticleSwarmOptimization::MCE;
use AI::ParticleSwarmOptimization::Pmap;
use Data::Dumper; $::Data::Dumper::Sortkeys = 1;
#=======================================================================
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;
}
#=======================================================================
++$|;
#-----------------------------------------------------------------------
#my $pso = AI::ParticleSwarmOptimization->new(			# Single-core
#my $pso = AI::ParticleSwarmOptimization::MCE->new(		# Multi-core	
my $pso = AI::ParticleSwarmOptimization::Pmap->new(		# Multi-core	

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

		$prtcl;
	} @{ $self->{ prtcls } };
}
#=======================================================================
1;

__END__

=head1 NAME

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

=head1 SYNOPSIS

    use AI::ParticleSwarmOptimization::Pmap;

    my $pso = AI::ParticleSwarmOptimization::Pmap->new (
        -fitFunc        => \&calcFit,
        -dimensions     => 3,
        -iterations     => 10,
        -numParticles   => 1000,

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

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

=head1 Description

This module is enhancement of on original AI::ParticleSwarmOptimization to support 
multi-core processing with use of Pmap. 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

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

=over 4

=item new (%parameters)

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

=over 4

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

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

=item I<-dimensions>: positive number, required

The number of dimensions of the hypersurface being searched.

=item I<-exitFit>: number, optional

If provided I<-exitFit> allows early termination of optimize if the
fitness value becomes equal or less than I<-exitFit>.

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

=item B<init ()>

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

=item B<optimize ()>

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

B<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.

=item B<getParticleState ()>

Returns the vector of position

=item B<getBestParticles ([$n])>

Takes an optional count.



( run in 0.350 second using v1.01-cache-2.11-cpan-8d75d55dd25 )