org.encog.neural.networks.training.pso

## Class NeuralPSO

- java.lang.Object
- - org.encog.ml.train.BasicTraining
  - - org.encog.neural.networks.training.pso.NeuralPSO

- All Implemented Interfaces:
    MLTrain

      public class NeuralPSO
      extends BasicTraining

  Iteratively trains a population of neural networks by applying particle swarm optimisation (PSO). Contributed by: Geoffroy Noel https://github.com/goffer-looney References: James Kennedy and Russell C. Eberhart, Particle swarm optimization, Proceedings of the IEEE International Conference on Neural Networks, 1995, pp. 1942-1948
  Author:
    Geoffroy Noel

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected double[]` | `m_bestErrors`
    `protected int` | `m_bestVectorIndex`
    `protected double[][]` | `m_bestVectors`
    `protected double` | `m_c1`
    `protected double` | `m_c2`
    `protected CalculateScore` | `m_calculateScore`
    `protected double` | `m_inertiaWeight`
    `protected double` | `m_maxPosition`
    `protected double` | `m_maxVelocity`
    `protected boolean` | `m_multiThreaded`
    `protected BasicNetwork[]` | `m_networks`
    `protected int` | `m_populationSize`
    `protected Randomizer` | `m_randomizer`
    `protected VectorAlgebra` | `m_va`
    `protected double[][]` | `m_velocities`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NeuralPSO(BasicNetwork network, MLDataSet trainingSet)` Construct a PSO using a training set score function, 20 particles and the NguyenWidrowRandomizer randomizer.
    `NeuralPSO(BasicNetwork network, Randomizer randomizer, CalculateScore calculateScore, int populationSize)` Constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `canContinue()`
    `double` | `getC1()` Get the cognition coefficient (c1).
    `double` | `getC2()` Get the social coefficient (c2).
    `String` | `getDescription()` Get a description of all the current settings.
    `double` | `getInertiaWeight()` Get the inertia weight (w)
    `double` | `getMaxPosition()` Get the boundary of the search space (Xmax)
    `double` | `getMaxVelocity()` Get the maximum velocity (Vmax)
    `MLMethod` | `getMethod()` Get the current best machine learning method from the training.
    `protected double[]` | `getNetworkState(int particleIndex)` Returns the state of a network in the swarm
    `int` | `getPopulationSize()` Returns the swarm size.
    `boolean` | `isMultiThreaded()` Get the multi-threaded mode.
    `void` | `iteration()` Runs one PSO iteration over the whole population of networks.
    `protected void` | `iterationPSO(boolean init)` Internal method for the iteration of the swarm.
    `TrainingContinuation` | `pause()` Pause the training to continue later.
    `void` | `resume(TrainingContinuation state)` Resume training.
    `void` | `setC1(double c1)` Sets the cognition coefficient (c1).
    `void` | `setC2(double c2)` Set the social coefficient (c2).
    `void` | `setInertiaWeight(double inertiaWeight)` Set the inertia weight (w)
    `void` | `setInitialPopulation(BasicNetwork[] initialPopulation)` Keep a reference to the passed population of networks.
    `void` | `setMaxPosition(double maxPosition)` Set the boundary of the search space (Xmax)
    `void` | `setMaxVelocity(double maxVelocity)` Sets the maximum velocity.
    `protected void` | `setNetworkState(int particleIndex, double[] state)` Sets the state of the networks in the swarm
    `void` | `setPopulationSize(int populationSize)` Set the swarm size.
    `protected void` | `updateGlobalBestPosition()` Update the swarm's best position
    `protected void` | `updateParticle(int particleIndex, boolean init)` Update the velocity, position and personal best position of a particle
    `protected void` | `updatePersonalBestPosition(int particleIndex, double[] particlePosition)` Update the personal best position of a particle.
    `protected void` | `updateVelocity(int particleIndex, double[] particlePosition)` Update the velocity of a particle

    - ### Methods inherited from class org.encog.ml.train.BasicTraining

      `addStrategy, finishTraining, getError, getImplementationType, getIteration, getStrategies, getTraining, isTrainingDone, iteration, postIteration, preIteration, setError, setIteration, setTraining`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### m_multiThreaded

          protected boolean m_multiThreaded

    - #### m_va

          protected VectorAlgebra m_va

    - #### m_calculateScore

          protected CalculateScore m_calculateScore

    - #### m_randomizer

          protected Randomizer m_randomizer

    - #### m_networks

          protected BasicNetwork[] m_networks

    - #### m_velocities

          protected double[][] m_velocities

    - #### m_bestVectors

          protected double[][] m_bestVectors

    - #### m_bestErrors

          protected double[] m_bestErrors

    - #### m_bestVectorIndex

          protected int m_bestVectorIndex

    - #### m_populationSize

          protected int m_populationSize

    - #### m_maxPosition

          protected double m_maxPosition

    - #### m_maxVelocity

          protected double m_maxVelocity

    - #### m_c1

          protected double m_c1

    - #### m_c2

          protected double m_c2

    - #### m_inertiaWeight

          protected double m_inertiaWeight

  - ### Constructor Detail

    - #### NeuralPSO

          public NeuralPSO(BasicNetwork network,
                   Randomizer randomizer,
                   CalculateScore calculateScore,
                   int populationSize)

      Constructor.
      Parameters:
        `network` - an initialised Encog network. The networks in the swarm will be created with the same topology as this network.
        `randomizer` - any type of Encog network weight initialisation object.
        `calculateScore` - any type of Encog network scoring/fitness object.
        `populationSize` - the swarm size.

    - #### NeuralPSO

          public NeuralPSO(BasicNetwork network,
                   MLDataSet trainingSet)

      Construct a PSO using a training set score function, 20 particles and the NguyenWidrowRandomizer randomizer.
      Parameters:
        `network` - The network to train. an initialised Encog network. The networks in the swarm will be created with the same topology as this network.
        `trainingSet` - The training set.

  - ### Method Detail

    - #### iteration

          public void iteration()

      Runs one PSO iteration over the whole population of networks.

    - #### iterationPSO

          protected void iterationPSO(boolean init)

      Internal method for the iteration of the swarm.
      Parameters:
        `init` - true if this is an initialisation iteration.

    - #### updateParticle

          protected void updateParticle(int particleIndex,
                            boolean init)

      Update the velocity, position and personal best position of a particle
      Parameters:
        `particleIndex` - index of the particle in the swarm
        `init` - if true, the position and velocity will be initialised.

    - #### updateVelocity

          protected void updateVelocity(int particleIndex,
                            double[] particlePosition)

      Update the velocity of a particle
      Parameters:
        `particleIndex` - index of the particle in the swarm
        `particlePosition` - the particle current position vector

    - #### updatePersonalBestPosition

          protected void updatePersonalBestPosition(int particleIndex,
                                        double[] particlePosition)

      Update the personal best position of a particle.
      Parameters:
        `particleIndex` - index of the particle in the swarm
        `particlePosition` - the particle current position vector

    - #### updateGlobalBestPosition

          protected void updateGlobalBestPosition()

      Update the swarm's best position

    - #### pause

          public TrainingContinuation pause()

      Description copied from interface: `MLTrain`
      Pause the training to continue later.
      Returns:
        A training continuation object.

    - #### canContinue

          public boolean canContinue()

      Returns:
        True if the training can be paused, and later continued.

    - #### resume

          public void resume(TrainingContinuation state)

      Description copied from interface: `MLTrain`
      Resume training.
      Parameters:
        `state` - The training continuation object to use to continue.

    - #### getNetworkState

          protected double[] getNetworkState(int particleIndex)

      Returns the state of a network in the swarm
      Parameters:
        `particleIndex` - index of the network in the swarm
      Returns:
        an array of weights and biases for the given network

    - #### setNetworkState

          protected void setNetworkState(int particleIndex,
                             double[] state)

      Sets the state of the networks in the swarm
      Parameters:
        `particleIndex` - index of the network in the swarm
        `state` - an array of weights and biases

    - #### setPopulationSize

          public void setPopulationSize(int populationSize)

      Set the swarm size.
      Parameters:
        `populationSize` - the swarm size

    - #### getPopulationSize

          public int getPopulationSize()

      Returns the swarm size.
      Returns:
        the swarm size.

    - #### setMaxVelocity

          public void setMaxVelocity(double maxVelocity)

      Sets the maximum velocity.
      Parameters:
        `maxVelocity` - Maximum velocity / Vmax

    - #### getMaxVelocity

          public double getMaxVelocity()

      Get the maximum velocity (Vmax)
      Returns:
        maximum velocity (Vmax)

    - #### setMaxPosition

          public void setMaxPosition(double maxPosition)

      Set the boundary of the search space (Xmax)
      Parameters:
        `maxPosition` - maximum value for a component (Xmax)

    - #### getMaxPosition

          public double getMaxPosition()

      Get the boundary of the search space (Xmax)
      Returns:
        the maximum value a component can take (Xmax)

    - #### setC1

          public void setC1(double c1)

      Sets the cognition coefficient (c1).
      Parameters:
        `c1` - cognition coefficient (c1)

    - #### getC1

          public double getC1()

      Get the cognition coefficient (c1).
      Returns:
        the cognition coefficient (c1)

    - #### setC2

          public void setC2(double c2)

      Set the social coefficient (c2).
      Parameters:
        `c2` - the social coefficient (c2)

    - #### getC2

          public double getC2()

      Get the social coefficient (c2).
      Returns:
        the social coefficient (c2)

    - #### setInertiaWeight

          public void setInertiaWeight(double inertiaWeight)

      Set the inertia weight (w)
      Parameters:
        `inertiaWeight` - the inertia weight (w)

    - #### getInertiaWeight

          public double getInertiaWeight()

      Get the inertia weight (w)
      Returns:
        the inertia weight (w)

    - #### getDescription

          public String getDescription()

      Get a description of all the current settings.
      Returns:
        a String describing all the current setting in a single line.

    - #### getMethod

          public MLMethod getMethod()

      Description copied from interface: `MLTrain`
      Get the current best machine learning method from the training.
      Returns:
        The best machine learningm method.

    - #### setInitialPopulation

          public void setInitialPopulation(BasicNetwork[] initialPopulation)

      Keep a reference to the passed population of networks. This population is not copied, it will evolve during training.
      Parameters:
        `initialPopulation` -

    - #### isMultiThreaded

          public boolean isMultiThreaded()

      Get the multi-threaded mode.
      Returns:
        true if PSO works in multi-threaded mode

Copyright © 2014. All Rights Reserved.