org.encog.ml.genetic
Class MLMethodGeneticAlgorithm
- java.lang.Object
-
- org.encog.ml.train.BasicTraining
-
- org.encog.ml.genetic.MLMethodGeneticAlgorithm
-
- All Implemented Interfaces:
- MLTrain, MultiThreadable
public class MLMethodGeneticAlgorithm extends BasicTraining implements MultiThreadable
Implements a genetic algorithm that allows an MLMethod that is encodable (MLEncodable) to be trained. It works well with both BasicNetwork and FreeformNetwork class, as well as any MLEncodable class. There are essentially two ways you can make use of this class. Either way, you will need a score object. The score object tells the genetic algorithm how well suited a neural network is. If you would like to use genetic algorithms with a training set you should make use TrainingSetScore class. This score object uses a training set to score your neural network. If you would like to be more abstract, and not use a training set, you can create your own implementation of the CalculateScore method. This class can then score the networks any way that you like.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description classMLMethodGeneticAlgorithm.MLMethodGeneticAlgorithmHelperVery simple class that implements a genetic algorithm.
-
Constructor Summary
Constructors Constructor and Description MLMethodGeneticAlgorithm(MethodFactory phenotypeFactory, CalculateScore calculateScore, int populationSize)Construct a method genetic algorithm.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleancanContinue()voidfinishTraining()Should be called after training has completed and the iteration method will not be called any further.MLMethodGeneticAlgorithm.MLMethodGeneticAlgorithmHelpergetGenetic()MLMethodgetMethod()Get the current best machine learning method from the training.intgetThreadCount()voiditeration()Perform one training iteration.TrainingContinuationpause()Pause the training to continue later.voidresume(TrainingContinuation state)Resume training.voidsetGenetic(MLMethodGeneticAlgorithm.MLMethodGeneticAlgorithmHelper genetic)Set the genetic helper class.voidsetThreadCount(int numThreads)Set the number of threads to use.-
Methods inherited from class org.encog.ml.train.BasicTraining
addStrategy, getError, getImplementationType, getIteration, getStrategies, getTraining, isTrainingDone, iteration, postIteration, preIteration, setError, setIteration, setTraining
-
-
-
-
Constructor Detail
-
MLMethodGeneticAlgorithm
public MLMethodGeneticAlgorithm(MethodFactory phenotypeFactory, CalculateScore calculateScore, int populationSize)
Construct a method genetic algorithm.- Parameters:
phenotypeFactory- The phenotype factory.calculateScore- The score calculation object.populationSize- The population size.
-
-
Method Detail
-
canContinue
public boolean canContinue()
- Specified by:
canContinuein interfaceMLTrain- Returns:
- True if the training can be paused, and later continued.
-
getGenetic
public MLMethodGeneticAlgorithm.MLMethodGeneticAlgorithmHelper getGenetic()
- Returns:
- The genetic algorithm implementation.
-
getMethod
public MLMethod getMethod()
Get the current best machine learning method from the training.
-
getThreadCount
public int getThreadCount()
- Specified by:
getThreadCountin interfaceMultiThreadable- Returns:
- The number of threads to use, 0 to automatically determine based on core count.
-
iteration
public void iteration()
Perform one training iteration.
-
pause
public TrainingContinuation pause()
Pause the training to continue later.
-
resume
public void resume(TrainingContinuation state)
Resume training.
-
finishTraining
public void finishTraining()
Description copied from class:BasicTrainingShould be called after training has completed and the iteration method will not be called any further.- Specified by:
finishTrainingin interfaceMLTrain- Overrides:
finishTrainingin classBasicTraining
-
setGenetic
public void setGenetic(MLMethodGeneticAlgorithm.MLMethodGeneticAlgorithmHelper genetic)
Set the genetic helper class.- Parameters:
genetic- The genetic helper class.
-
setThreadCount
public void setThreadCount(int numThreads)
Description copied from interface:MultiThreadableSet the number of threads to use.- Specified by:
setThreadCountin interfaceMultiThreadable- Parameters:
numThreads- The number of threads to use, or zero to automatically determine based on core count.
-
-
DMelt 3.0 © DataMelt by jWork.ORG