org.encog.neural.networks.training.pso
public class NeuralPSO extends BasicTraining
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 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.
|
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
|
addStrategy, finishTraining, getError, getImplementationType, getIteration, getStrategies, getTraining, isTrainingDone, iteration, postIteration, preIteration, setError, setIteration, setTraining
protected boolean m_multiThreaded
protected VectorAlgebra m_va
protected CalculateScore m_calculateScore
protected Randomizer m_randomizer
protected BasicNetwork[] m_networks
protected double[][] m_velocities
protected double[][] m_bestVectors
protected double[] m_bestErrors
protected int m_bestVectorIndex
protected int m_populationSize
protected double m_maxPosition
protected double m_maxVelocity
protected double m_c1
protected double m_c2
protected double m_inertiaWeight
public NeuralPSO(BasicNetwork network, Randomizer randomizer, CalculateScore calculateScore, int populationSize)
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.public NeuralPSO(BasicNetwork network, MLDataSet trainingSet)
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.public void iteration()
protected void iterationPSO(boolean init)
init
- true if this is an initialisation iteration.protected void updateParticle(int particleIndex, boolean init)
particleIndex
- index of the particle in the swarminit
- if true, the position and velocity
will be initialised.protected void updateVelocity(int particleIndex, double[] particlePosition)
particleIndex
- index of the particle in the swarmparticlePosition
- the particle current position vectorprotected void updatePersonalBestPosition(int particleIndex, double[] particlePosition)
particleIndex
- index of the particle in the swarmparticlePosition
- the particle current position vectorprotected void updateGlobalBestPosition()
public TrainingContinuation pause()
MLTrain
public boolean canContinue()
public void resume(TrainingContinuation state)
MLTrain
state
- The training continuation object to use to continue.protected double[] getNetworkState(int particleIndex)
particleIndex
- index of the network in the swarmprotected void setNetworkState(int particleIndex, double[] state)
particleIndex
- index of the network in the swarmstate
- an array of weights and biasespublic void setPopulationSize(int populationSize)
populationSize
- the swarm sizepublic int getPopulationSize()
public void setMaxVelocity(double maxVelocity)
maxVelocity
- Maximum velocity / Vmaxpublic double getMaxVelocity()
public void setMaxPosition(double maxPosition)
maxPosition
- maximum value for a component (Xmax)public double getMaxPosition()
public void setC1(double c1)
c1
- cognition coefficient (c1)public double getC1()
public void setC2(double c2)
c2
- the social coefficient (c2)public double getC2()
public void setInertiaWeight(double inertiaWeight)
inertiaWeight
- the inertia weight (w)public double getInertiaWeight()
public String getDescription()
public MLMethod getMethod()
MLTrain
public void setInitialPopulation(BasicNetwork[] initialPopulation)
initialPopulation
- public boolean isMultiThreaded()
Copyright © 2014. All Rights Reserved.