I am working with the genetic algorithm in c++. In order to speed up evolution i am exponentiating fitness values in such a way that i use the entire range of long double. This makes the difference between scores greater and makes good scores much better than mediocre scores, such that the good scores are (exponentially) more likely to be chosen for reproduction.
Now, i would like to convert each score back to a double and scale it accordingly, so that i can do operations like averaging. The problem is, i cant seem to squash the range of a long double into that of a double using a typical scaling formula of the sort seen here, Mapping a numeric range onto another, nor can i think of another approach to do the conversion.
void DNA::fitnessFunction(const vector<double>& target){
//long double maxScore = pow((long double)8., (long double)5461.);
long double score = 0.;
for(int i = 0; i< numberOfGenes; i++){
int difference= abs (target[i] - genes[i]);
//if difference > 50: threshold
double distance = (double) (255.0 - difference) / 255.0;
score+= distance;
}
score = utilities::map(score, 0, genes.size(), 0.0, 5461.);
long double temp = pow((long double)8., score);
this->fitness = (double)utilities::map(temp, (long double) std::numeric_limits<long double>::min(), (long double)std::numeric_limits<long double>::max(), (long double)std::numeric_limits<double>::min(), (long double) std::numeric_limits<double>::max());
}