7 #include "LossTrainer.h"
12 class IGeneticTrainer;
15 struct GeneticTrainerCInfo :
public LossTrainerCInfo
322 virtual void SetLoss(
int index,
float loss) = 0;
342 SMARTENGINE_EXPORT
void GeneticTrainer_Step(ObjPtr
object);
343 SMARTENGINE_EXPORT
void GeneticTrainer_SetTrainingInfo(ObjPtr
object,
const GeneticTrainingInfo& info);
344 SMARTENGINE_EXPORT
int GeneticTrainer_GetPopulationCount(ObjPtr
object);
345 SMARTENGINE_EXPORT
void GeneticTrainer_SortPopulation(ObjPtr
object);
346 SMARTENGINE_EXPORT
float GeneticTrainer_GetMutationStandardDeviation(ObjPtr
object);
347 SMARTENGINE_EXPORT
int GeneticTrainer_GetChromosomeLastIndex(ObjPtr
object,
int index);
348 SMARTENGINE_EXPORT
void GeneticTrainer_SetChromosome(ObjPtr
object,
int index);
349 SMARTENGINE_EXPORT
void GeneticTrainer_SetBestChromosome(ObjPtr
object);
350 SMARTENGINE_EXPORT
void GeneticTrainer_CopyOutChromosome(ObjPtr
object,
int index, ObjPtr graph);
351 SMARTENGINE_EXPORT
void GeneticTrainer_CopyOutBestChromosome(ObjPtr
object, ObjPtr graph);
352 SMARTENGINE_EXPORT
void GeneticTrainer_CopyOutTopAverage(ObjPtr
object,
float count, ObjPtr graph,
int weightedAverage);
353 SMARTENGINE_EXPORT
float GeneticTrainer_GetLoss(ObjPtr
object,
int index);
354 SMARTENGINE_EXPORT
void GeneticTrainer_SetLoss(ObjPtr
object,
int index,
float loss);
MutationTarget
Definition: GeneticTrainer.h:45
virtual void CopyOutBestChromosome(IGraph *graph)=0
Sorts chromosomes by loss and then copies out the best chromosome to the specified network list.
virtual float GetLoss(int index)=0
Returns the loss of the specified chromosome
SMARTENGINE_EXPORT ObjectPtr< IGeneticTrainer > CreateGeneticTrainer(const GeneticTrainerCInfo &cinfo)
Creates an instance of IGeneticTrainer
virtual int GetChromosomeLastIndex(int index) const =0
Debug method to help visualize how chromosomes are progressing through generations
Initializes the GeneticTrainer with a new population
Definition: GeneticTrainer.h:30
@ Auto
Chooses the default value depending on the node type.
float countToKeepUnchanged
How many of the top chromosomes should be left unchanged during each step.
Definition: GeneticTrainer.h:190
float countCrossover
The number of chromosome 2's weight will swap with chromosome 1
Definition: GeneticTrainer.h:158
int stepsUntilLowerStandardDeviation
The number of steps that the best network is in the top unchanged percent before we lower the mutatio...
Definition: GeneticTrainer.h:131
@ Weight
Swapping occurs at the individual weight level across all neurons.
float targetsToMutate
How many weights / neurons per node to mutate.
Definition: GeneticTrainer.h:104
float selectionStandardDeviation
Random parent chromosomes will be chosen to breed with this standard deviation. A lower random value ...
Definition: GeneticTrainer.h:165
virtual int GetPopulationCount() const =0
Retrieves the total number of chromosomes (test subjects) in the population.
GeneticTrainer mutation info
Definition: GeneticTrainer.h:79
virtual float GetMutationStandardDeviation() const =0
Returns the current mutation standard deviation, taking into account adaptive behavior
virtual void CopyOutChromosome(int index, IGraph *graph)=0
Copies out the specified chromosome to a graph.
virtual void SetTrainingInfo(const GeneticTrainingInfo &info)=0
Sets the genetic parameters of the trainer.
int stepsUntilRaiseStandardDeviation
The number of steps that the best network is not in the top unchanged percent before we raise the mut...
Definition: GeneticTrainer.h:138
Smart pointer to an IObject. Automatic ref counting.
Definition: ObjectPtr.h:16
GeneSwapTarget target
Specifies which weights will be swapped
Definition: GeneticTrainer.h:149
Trains a NeuronLayer / NeuralNetwork using a genetic algorithm. With each step, networks are sorted b...
Definition: GeneticTrainer.h:226
Definition: A2CTrainer.h:10
virtual void SortPopulation()=0
Sorts the population by loss in ascending order
ILoss * loss
Optional loss structure to train against a known set of outputs
Definition: GeneticTrainer.h:23
GeneSwapTarget
Definition: GeneticTrainer.h:63
int populationCount
Number of chromosomes in the population
Definition: GeneticTrainer.h:34
Base class for NeuralNetwork loss trainers
Definition: LossTrainer.h:81
MutationInfo mutation
Mutation info
Definition: GeneticTrainer.h:204
Data used to construct an IA2CTrainer instance
Definition: GeneticTrainer.h:19
float standardDeviation
A random value of this standard deviation will be added to each weight selected for mutation.
Definition: GeneticTrainer.h:110
virtual void Step()=0
Steps the trainer, making the population learn through gene swapping and mutation.
GeneticTrainer parameter info
Definition: GeneticTrainer.h:172
A graph is a collection of buffers and nodes that together form a neural network. The graph is create...
Definition: Graph.h:61
float countTopPerformers
How many of the top chromosomes are marked as top performers. The mutation standard deviation will be...
Definition: GeneticTrainer.h:181
virtual void Initialize(const GeneticTrainerInitializationInfo &info)=0
Initializes the newtwork with a new population. Not necessary to call if deserializing from disk.
virtual void CopyOutTopAverage(float count, IGraph *graph, bool weightedAverage)=0
Averages the top chromosome weights and copies the result to specified graph
float minStandardDeviation
The minimum standard deviation we are allowed to achieve when AdaptiveStandardDeviation is set to tru...
Definition: GeneticTrainer.h:116
bool randomizePopulation
True if we should randomize the population upon initialization. False if each staring chromosome is a...
Definition: GeneticTrainer.h:41
GeneSwapInfo geneSwap
Gene swap info
Definition: GeneticTrainer.h:209
float countToRandomize
How many of the bottom chromosomes should be completely randomized.
Definition: GeneticTrainer.h:199
virtual void SetBestChromosome()=0
Sorts chromosomes by loss and then sets the networks specified in the constructor to the best chromos...
The loss of a NeuralNetwork is computed using the formula (Expected Ouput - Actual Output)^2 The mean...
Definition: Loss.h:39
MutationTarget target
Specifies what weights to mutate.
Definition: GeneticTrainer.h:83
virtual void SetChromosome(int index)=0
Replaces the networks specified in the constructor with the specified chromosome index....
GeneticTrainer gene swap info
Definition: GeneticTrainer.h:145
float nodesToMutate
How many trainable nodes in the graph we should mutate
Definition: GeneticTrainer.h:94
virtual float GetLoss()=0
Returns the loss in the graph.
bool adaptiveStandardDeviation
If set to true, the standard deviation will change with the learning rate. If the network isn't learn...
Definition: GeneticTrainer.h:124
virtual void SetLoss(int index, float loss)=0
Sets the loss of the specified chromosome. This will replace the loss from the optionally specified L...