Created by Scott Robert Ladd at Coyote Gulch Productions.
Tools for evolving real numbers. More...
#include <evoreal.h>
Public Member Functions | |
evoreal (float a_sign_weight=5.0F, float a_exponent_weight=5.0F, float a_mantissa_weight=90.0F) | |
Creation constructor. More... | |
evoreal (evoreal &a_source) | |
Copy constructor. More... | |
evoreal & | operator= (evoreal &a_source) |
Assignment. More... | |
float | mutate (float a_f) |
Mutation for float values. More... | |
double | mutate (double a_d) |
Mutation for double values. More... | |
float | crossover (float a_f1, float a_f2) |
Crossover for float values. More... | |
double | crossover (double a_d1, double a_d2) |
Crossover for double values. More... | |
Additional Inherited Members | |
![]() | |
static size_t | rand_index (size_t n) |
Static function to allow use of g_random function pointer in random_shuffle. | |
static void | set_seed (uint32_t a_seed) |
Set the seed for the random number generator. | |
static uint32_t | get_seed () |
Set the seed for the random number generator. | |
static std::string | version () |
Get version number. | |
![]() | |
static prng | g_random |
A shared random number generator. | |
static std::string | g_version |
Version number. | |
The majority of genetic algorithms work on pure bit strings, converting those strings to the desired types for fitness testing. In Lawrence Davis' book "Handbook of Genetic Algorithms," he transforms a 44-bit string into two floating point values via a series of operations. I've seen similar techniques elsewhere, and I find them a bit cumbersome.
In the purest sense, a GA should have no knowledge of the format of the data it is modifying; however, natural chromosomes do encode some structure in their sequence; for example, crossover appears to take place in specific positions along the chromosome. And while mutation doesn't care about a chromosome's structure, it does affect that structure. In context of a computer program, the structure of a chromosome isn't so important as the ability to logically modify its bits through crossover and mutation.
I built tools for the mutation and crossover of encoded floating-point values of types float and double. The code that follows assumes we are working with 32-bit floats and 64-bit IEEE-754 doubles, which, in my experience, the norm for many C and C++ compilers. Yes, I'm aware of the VAX and other systems; this code is explicitly non-portable outside implementations of IEC 60559/IEEE-754.
libevocosm::evoreal::evoreal | ( | float | a_sign_weight = 5.0F , |
float | a_exponent_weight = 5.0F , |
||
float | a_mantissa_weight = 90.0F |
||
) |
Creates a new evoreal object based on a set of weights that define the chance of mutation in various components of a floating-point value. The default weights have worked well in a variety of applications, but are (of course) settable for specific application and experimentation.
Each weight is a percentage of the total of all three weights; for example, if the three weights add to 100 (as they do by efault), and a_sign_weight is 12, the chance of a mutation in the sign bit is 12%. The default weights were chosen based on experience in using these tools in a variety of applications.
a_sign_weight | - Weight assigned to changes in sign |
a_exponent_weight | - Weight assigned to changes in the exponent |
a_mantissa_weight | - Weight assigned to changes in the mantissa |
libevocosm::evoreal::evoreal | ( | evoreal & | a_source | ) |
Creates a new evoreal with the same states as an existing one.
a_source | - The source object |
float libevocosm::evoreal::crossover | ( | float | a_f1, |
float | a_f2 | ||
) |
Creates a new float by combining two values through a real-specialized form of crossover.
a_f1 | - First parent number |
a_f2 | - Second parent number |
double libevocosm::evoreal::crossover | ( | double | a_d1, |
double | a_d2 | ||
) |
Creates a new double by combining two values through a real-specialized form of crossover.
a_d1 | - First parent number |
a_d2 | - Second parent number |
float libevocosm::evoreal::mutate | ( | float | a_f | ) |
Returns a new float that is a mutated version of the argument.
a_f | - Number to be cloned; the result is then mutated |
double libevocosm::evoreal::mutate | ( | double | a_d | ) |
Returns a new float that is a mutated version of the argument.
a_d | - Number to be cloned; the result is then mutated |
Assigns the state of one evoreal to another.
a_source | - The source object |
© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.