![]() |
Grail (C++)
1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
|
This class provides a functionality of assigning fitness values as averages from the previous evaluations.
It can be used to minimize the effects of variance when fitness calculation is non-deterministic.
Use 'AddSampleWithFitnessUpdate' method to store the current fitness and update it based on past evaluations.
More...
#include <FitnessRepository.h>
Public Member Functions | |
FitnessRepository (size_t maxSamplesPerIndividual=100) | |
Constructs a new FitnessRepository instance. More... | |
std::size_t | GetSampleCount (const Individual &individual) const |
Returns the number of fitness values currently stored for a given individual. More... | |
bool | TryGetFitness (const Individual &individual, double &fitness) const |
void | AddSampleWithFitnessUpdate (Individual &individual) |
void | Serialize (const std::string &filename) const |
Serializes contents of the FitnessRepository so it can be loaded in another session using Deserialize(). . More... | |
bool | Deserialize (const std::string &filename, const Individual &populationRepresentative) |
Loads previously saved contents of the FitnessRepository using the Serialize() method. . More... | |
This class provides a functionality of assigning fitness values as averages from the previous evaluations.
It can be used to minimize the effects of variance when fitness calculation is non-deterministic.
Use 'AddSampleWithFitnessUpdate' method to store the current fitness and update it based on past evaluations.
grail::evolution::FitnessRepository::FitnessRepository | ( | size_t | maxSamplesPerIndividual = 100 | ) |
Constructs a new FitnessRepository instance.
maxSamplesPerIndividual | - the number of fitness values to be stored per each individual. |
bool grail::evolution::FitnessRepository::Deserialize | ( | const std::string & | filename, |
const Individual & | populationRepresentative | ||
) |
Loads previously saved contents of the FitnessRepository using the Serialize() method.
.
filename | - the path where the state has been saved. |
populationRepresentative | - an individual with the same structure (exact derived type) as the ones saved. It will be used for cloning purposes. |
std::size_t grail::evolution::FitnessRepository::GetSampleCount | ( | const Individual & | individual | ) | const |
Returns the number of fitness values currently stored for a given individual.
individual | = the given individual. |
void grail::evolution::FitnessRepository::Serialize | ( | const std::string & | filename | ) | const |
Serializes contents of the FitnessRepository so it can be loaded in another session using Deserialize().
.
filename | - the path where the state will be saved. If the file exists, it will be overridden. |
bool grail::evolution::FitnessRepository::TryGetFitness | ( | const Individual & | individual, |
double & | fitness | ||
) | const |
Attempts to calculate the fitness value of an individual equal to the average value of the stored samples.
individual | - the individual for which the fitness should be returned. |
fitness | - the calculated fitness value or -1.0 if the method returns false. |