SmartEngine
1.6.0
|
Trains a NeuronLayer / NeuralNetwork using a genetic algorithm. With each step, networks are sorted by loss. The top networks are left unchanged, while the bottom networks are replaced by new ones. The new networks are formed by mixing the weights of the top networks and randomly mutating weights / neurons. Lastly, the bottom percent of the networks can be replaced with completely random weights, adding some variability to the pool. More...
#include <GeneticTrainer.h>
Public Member Functions | |
virtual void | Initialize (const GeneticTrainerInitializationInfo &info)=0 |
Initializes the newtwork with a new population. Not necessary to call if deserializing from disk. More... | |
virtual void | Step ()=0 |
Steps the trainer, making the population learn through gene swapping and mutation. More... | |
virtual int | GetPopulationCount () const =0 |
Retrieves the total number of chromosomes (test subjects) in the population. More... | |
virtual void | SortPopulation ()=0 |
Sorts the population by loss in ascending order More... | |
virtual float | GetMutationStandardDeviation () const =0 |
Returns the current mutation standard deviation, taking into account adaptive behavior More... | |
virtual int | GetChromosomeLastIndex (int index) const =0 |
Debug method to help visualize how chromosomes are progressing through generations More... | |
virtual void | SetChromosome (int index)=0 |
Replaces the networks specified in the constructor with the specified chromosome index. Call this before evaluating a chromosome for its performance. More... | |
virtual void | SetBestChromosome ()=0 |
Sorts chromosomes by loss and then sets the networks specified in the constructor to the best chromosome. More... | |
virtual void | CopyOutChromosome (int index, IGraph *graph)=0 |
Copies out the specified chromosome to a graph. More... | |
virtual void | CopyOutBestChromosome (IGraph *graph)=0 |
Sorts chromosomes by loss and then copies out the best chromosome to the specified network list. More... | |
virtual void | CopyOutTopAverage (float count, IGraph *graph, bool weightedAverage)=0 |
Averages the top chromosome weights and copies the result to specified graph More... | |
virtual float | GetLoss (int index)=0 |
Returns the loss of the specified chromosome More... | |
virtual void | SetLoss (int index, float loss)=0 |
Sets the loss of the specified chromosome. This will replace the loss from the optionally specified Loss structure passed into the constructor. More... | |
virtual void | SetTrainingInfo (const GeneticTrainingInfo &info)=0 |
Sets the genetic parameters of the trainer. More... | |
virtual float | GetLoss ()=0 |
Returns the loss in the graph. More... | |
Public Member Functions inherited from SmartEngine::ILossTrainer | |
virtual void | SetTrainingMethod (const LossTrainingMethodInfo &info)=0 |
Sets the training method and associated parameters More... | |
virtual uint32 | GetGenerationCount () const =0 |
Returns the number of generations we have been training for. More... | |
Public Member Functions inherited from SmartEngine::IObject | |
virtual ObjectId | GetId () const =0 |
Returns the ID of this object. More... | |
virtual void | AddRef () const =0 |
Increments the internal reference count on this object. It is not common to use this method directly. More... | |
virtual void | Release () const =0 |
Decrements the internal reference count on this object. It is not common to use this method directly. More... | |
virtual int | GetRefCount () const =0 |
Returns the number of references to this object. More... | |
virtual void * | QueryInterface (ObjectClassId id)=0 |
Queries the object for an interface and returns a pointer to that interface if found. More... | |
void | operator= (IObject const &x)=delete |
Public Member Functions inherited from SmartEngine::IResource | |
virtual const char * | GetResourceName () const =0 |
Returns the name of this resource passed to the constructor. More... | |
virtual SerializationResult | GetLastLoadResult () const =0 |
Returns the result of the last call to Load(). Useful for checking loaded data state after creation. More... | |
virtual SerializationResult | Load (const char *appendName=nullptr)=0 |
Load this object from disk. More... | |
virtual SerializationResult | Save (const char *appendName=nullptr)=0 |
Save this object to disk. More... | |
Public Member Functions inherited from SmartEngine::ISerializable | |
virtual SerializationResult | Serialize (IMemoryBuffer *buffer)=0 |
Write the contents of this object to a buffer. More... | |
virtual SerializationResult | Deserialize (IMemoryBuffer *buffer)=0 |
Fill this object with contents from a buffer. More... | |
Additional Inherited Members | |
Public Attributes inherited from SmartEngine::IObject | |
private | |
__pad0__: IObject() {} IObject(IObject const&) = delete | |
Trains a NeuronLayer / NeuralNetwork using a genetic algorithm. With each step, networks are sorted by loss. The top networks are left unchanged, while the bottom networks are replaced by new ones. The new networks are formed by mixing the weights of the top networks and randomly mutating weights / neurons. Lastly, the bottom percent of the networks can be replaced with completely random weights, adding some variability to the pool.
Individual chromosome loss can either be set manually or pulled automatically from a Loss instance. Manually setting the loss is necessary when you don't know what the output of the network should be; you only know how the newtork performs relative to each other.
|
pure virtual |
Sorts chromosomes by loss and then copies out the best chromosome to the specified network list.
graph | The graph must be identical in structure and order to the one specified in the constructor |
|
pure virtual |
Copies out the specified chromosome to a graph.
index | |
graph | The graph must be identical in structure and order to the one specified in the constructor |
|
pure virtual |
Averages the top chromosome weights and copies the result to specified graph
count | (-Population Count, 1.0] If positive, the value acts as a percentage of the population. If negative, it acts as an exact integer value. |
weightedAverage | If true, the first nodes will have more weight than the last nodes averaged. |
|
pure virtual |
Debug method to help visualize how chromosomes are progressing through generations
index |
|
virtual |
Returns the loss in the graph.
Implements SmartEngine::ILossTrainer.
|
pure virtual |
Returns the loss of the specified chromosome
index |
|
pure virtual |
Returns the current mutation standard deviation, taking into account adaptive behavior
|
pure virtual |
Retrieves the total number of chromosomes (test subjects) in the population.
|
pure virtual |
Initializes the newtwork with a new population. Not necessary to call if deserializing from disk.
info |
|
pure virtual |
Sorts chromosomes by loss and then sets the networks specified in the constructor to the best chromosome.
|
pure virtual |
Replaces the networks specified in the constructor with the specified chromosome index. Call this before evaluating a chromosome for its performance.
Chromosomes are not sorted prior to being set.
index |
|
pure virtual |
Sets the loss of the specified chromosome. This will replace the loss from the optionally specified Loss structure passed into the constructor.
index | |
loss |
|
pure virtual |
Sets the genetic parameters of the trainer.
Not necessary to call when deserializing from disk
info |
|
pure virtual |
Sorts the population by loss in ascending order
|
pure virtual |
Steps the trainer, making the population learn through gene swapping and mutation.