GaStatistics
class keeps track of statistical information about populations, groups of populations or algorithms. It contains information about previous and current statistics, and provides information about progress of statistical values.
More...
#include <D:/Temp/vs/gal/source/Statistics.h>
Public Member Functions | |
GaStatistics (const GaFitnessComparator *comarator) | |
Default constructor initializes all statistical values to zeros and restart generation counter. | |
GAL_API void GACALL | Clear () |
Clear method clears all statistical information and restarts generation counter. | |
GAL_API void GACALL | NextGeneration () |
NextGeneration method prepares statistical values for next generation (shifts current values to previous) and increments generation counter. | |
GAL_API void GACALL | CopyFrom (const GaStatistics &stats, bool previous, bool current, bool currentGeneration) |
CopyFrom method copies statistical information and/or generation counter from another object. | |
int GACALL | GetCurrentGeneration () const |
This method is not thread-safe. | |
GAL_API float GACALL | GetValueProgress (GaStatValueType value, bool percent) const |
GetValueProgress method calculates progress of statistical value between previous and current generation. | |
GAL_API void GACALL | ChangeValue (GaStatValueType type, float value, bool relative) |
The method changes statistical value of current generation, change can be absolute or a relative offset to the current value. If GSV_TOTAL_FITNESS , GSV_TOTAL_FITNESS_SCALED or GSV_POPULATION_SIZE values are changed, GSV_AVG_FITNESS and GSV_AVG_FITNESS_SCALED values are updated automatically. | |
const GaFloatStatValue &GACALL | GetValue (GaStatValueType value) const |
This method is not thread-safe. | |
const GaFitnessComparator *GACALL | GetFitnessComarator () const |
This method is not thread-safe. | |
void GACALL | SetFitnessComparator (const GaFitnessComparator *comparator) |
SetFitnessComparator method sets fitness comparator which is going to be used to compare statistical values. | |
GaStatistics GACALL | operator+ (const GaStatistics &rhs) |
This operator produce new object by combining two instances of GaStatistic class. For detailed description of combining statistical values see operator += operator. | |
GAL_API GaStatistics &GACALL | operator+= (const GaStatistics &rhs) |
This operator combines statistical values of two instances of GaStatistics class. Result of combining is stored in this object. Combining is done in fallowing way: 1. Better value between two GSV_BEST_FITNESS values is chosen for new GSV_BEST_FITNESS value. 2. Worse value between two GSV_WORST_FITNESS values is chosen for new GSV_WORST_FITNESS . 3. Two GSV_TOTAL_FITNESS values are summed and the sum becomes new GSV_TOTAL_FITNESS value. 4. Two GSV_POPULATION_SIZE values are summed and the sum becomes new GSV_POPULATION_SIZE . 5. GSV_AVG_FITNES is calculated as: GSV_TOTAL_FITNESS/GSV_POPULATION_SIZE , where GSV_TOTAL_FITNESS and GSV_POPULATION_SIZE have new values. 6. All scaled fitness values are restarted to zeros. These values cannot be combined because they are calculated differently for different populations. | |
Private Attributes | |
int | _currentGeneration |
Generation counter keeps track of current generation of a population or an algorithm. | |
GaFloatStatValue | _values [GaNumberOfStatValueTypes] |
Array of statistical information. All statistical values are single precision floating-point numbers. | |
const GaFitnessComparator * | _fitnessComparator |
Fitness comparator used to compare statistical values. |
GaStatistics
class keeps track of statistical information about populations, groups of populations or algorithms. It contains information about previous and current statistics, and provides information about progress of statistical values.
This class has no built-in synchronizator, so LOCK_OBJECT
and LOCK_THIS_OBJECT
macros cannot be used with instances of this class. No public or private methods are thread-safe.
Common::GaStatistics::GaStatistics | ( | const GaFitnessComparator * | comarator | ) | [inline] |
Default constructor initializes all statistical values to zeros and restart generation counter.
comarator | fitness comparator used to compare statistical values. |
void Common::GaStatistics::Clear | ( | ) |
Clear
method clears all statistical information and restarts generation counter.
This method is not thread-safe.
void Common::GaStatistics::NextGeneration | ( | ) |
NextGeneration
method prepares statistical values for next generation (shifts current values to previous) and increments generation counter.
This method is not thread-safe
void Common::GaStatistics::CopyFrom | ( | const GaStatistics & | stats, | |
bool | previous, | |||
bool | current, | |||
bool | currentGeneration | |||
) |
CopyFrom
method copies statistical information and/or generation counter from another object.
This method is not thread-safe.
stats | object form which information is going to be copied. | |
previous | if it is set to true , then statistical information form previous generation is copied. | |
current | if it is set to true , then statistical information from current generation is copied. | |
currentGeneration | if it is set to true , then generation counter is copied. |
int GACALL Common::GaStatistics::GetCurrentGeneration | ( | ) | const [inline] |
This method is not thread-safe.
float Common::GaStatistics::GetValueProgress | ( | GaStatValueType | value, | |
bool | percent | |||
) | const |
GetValueProgress
method calculates progress of statistical value between previous and current generation.
This method is not thread-safe.
value | statistical value which progress is queried. | |
percent | if it is set to true , the method returns progress of the value in percents, otherwise it returns absolute progress. |
true
, the method return progress in percents, otherwise it returns absolute progress.void Common::GaStatistics::ChangeValue | ( | GaStatValueType | type, | |
float | value, | |||
bool | relative | |||
) |
The method changes statistical value of current generation, change can be absolute or a relative offset to the current value. If GSV_TOTAL_FITNESS
, GSV_TOTAL_FITNESS_SCALED
or GSV_POPULATION_SIZE
values are changed, GSV_AVG_FITNESS
and GSV_AVG_FITNESS_SCALED
values are updated automatically.
This method is not thread-safe.
type | statistical value which is going to be changed. | |
value | new value or relative offset to the current value. | |
relative | if is set to true , value parameter is interpreted as relative offset to the current value, if it is set to false , value parameter is interpreted as new value. |
const GaFloatStatValue& GACALL Common::GaStatistics::GetValue | ( | GaStatValueType | value | ) | const [inline] |
This method is not thread-safe.
value | statistical value which is queried. |
const GaFitnessComparator* GACALL Common::GaStatistics::GetFitnessComarator | ( | ) | const [inline] |
This method is not thread-safe.
void GACALL Common::GaStatistics::SetFitnessComparator | ( | const GaFitnessComparator * | comparator | ) | [inline] |
SetFitnessComparator
method sets fitness comparator which is going to be used to compare statistical values.
This method is not thread-safe.
comparator | fitness comparator. |
GaStatistics GACALL Common::GaStatistics::operator+ | ( | const GaStatistics & | rhs | ) | [inline] |
This operator produce new object by combining two instances of GaStatistic
class. For detailed description of combining statistical values see operator += operator.
This operator is not thread-safe.
rhs | reference to the second instance of GaStatistic , the first instance is this object. |
GaStatistics & Common::GaStatistics::operator+= | ( | const GaStatistics & | rhs | ) |
This operator combines statistical values of two instances of GaStatistics
class. Result of combining is stored in this object. Combining is done in fallowing way:
1. Better value between two GSV_BEST_FITNESS
values is chosen for new GSV_BEST_FITNESS
value.
2. Worse value between two GSV_WORST_FITNESS
values is chosen for new GSV_WORST_FITNESS
.
3. Two GSV_TOTAL_FITNESS
values are summed and the sum becomes new GSV_TOTAL_FITNESS
value.
4. Two GSV_POPULATION_SIZE
values are summed and the sum becomes new GSV_POPULATION_SIZE
.
5. GSV_AVG_FITNES
is calculated as: GSV_TOTAL_FITNESS/GSV_POPULATION_SIZE
, where GSV_TOTAL_FITNESS
and GSV_POPULATION_SIZE
have new values.
6. All scaled fitness values are restarted to zeros. These values cannot be combined because they are calculated differently for different populations.
This operation is not thread-safe.
rhs | reference to the instance of class GaStatistics which is used for combining result statistical values of this object. |
this
object.
int Common::GaStatistics::_currentGeneration [private] |
Generation counter keeps track of current generation of a population or an algorithm.
Array of statistical information. All statistical values are single precision floating-point numbers.
const GaFitnessComparator* Common::GaStatistics::_fitnessComparator [private] |
Fitness comparator used to compare statistical values.