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
-
-
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
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleancanContinue()doublegetC1()Get the cognition coefficient (c1).doublegetC2()Get the social coefficient (c2).java.lang.StringgetDescription()Get a description of all the current settings.doublegetInertiaWeight()Get the inertia weight (w)doublegetMaxPosition()Get the boundary of the search space (Xmax)doublegetMaxVelocity()Get the maximum velocity (Vmax)MLMethodgetMethod()Get the current best machine learning method from the training.intgetPopulationSize()Returns the swarm size.booleanisMultiThreaded()Get the multi-threaded mode.voiditeration()Runs one PSO iteration over the whole population of networks.TrainingContinuationpause()Pause the training to continue later.voidresume(TrainingContinuation state)Resume training.voidsetC1(double c1)Sets the cognition coefficient (c1).voidsetC2(double c2)Set the social coefficient (c2).voidsetInertiaWeight(double inertiaWeight)Set the inertia weight (w)voidsetInitialPopulation(BasicNetwork[] initialPopulation)Keep a reference to the passed population of networks.voidsetMaxPosition(double maxPosition)Set the boundary of the search space (Xmax)voidsetMaxVelocity(double maxVelocity)Sets the maximum velocity.voidsetPopulationSize(int populationSize)Set the swarm size.-
Methods inherited from class org.encog.ml.train.BasicTraining
addStrategy, finishTraining, getError, getImplementationType, getIteration, getStrategies, getTraining, isTrainingDone, iteration, postIteration, preIteration, setError, setIteration, setTraining
-
-
-
-
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.
-
pause
public TrainingContinuation pause()
Description copied from interface:MLTrainPause 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:MLTrainResume training.- Parameters:
state- The training continuation object to use to continue.
-
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 java.lang.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:MLTrainGet the current best machine learning method from the training.- Returns:
- The best machine learning 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- the initial population of networks.
-
isMultiThreaded
public boolean isMultiThreaded()
Get the multi-threaded mode.- Returns:
- true if PSO works in multi-threaded mode
-
-
DMelt 3.0 © DataMelt by jWork.ORG