Open jherico opened 4 years ago
The new implementation does have one remaining flaw. If t_min
and t_max
are the same, when the scaling value will be NaN. Solving this would be as easy as adding a conditional on range == 0
, but the behavior would need to be specified. Reasonable options would include setting all the values to a_tr_min, or to a_tr_max, or to the midpoint between them, or to a random distribution between them.
https://github.com/peter-ch/MultiNEAT/blob/0dc93aa0e228e23eeb95371bdd3838c64f08fdae/src/Utils.cpp#L40
The existing
void Scale(vector<double>& a_Values, const double a_tr_min, const double a_tr_max)
function ignores the passeda_tr_min
anda_tr_max
.Delegating to the existing
Scale(double&...)
function is inefficient because it causes the intermediate range value to be recomputed every call.The
a_Values = t_ValuesScaled;
is inefficient because it invokes a vector copy requiring linear time, whereasa_Values.swap(t_ValuesScaled);
would be constant time as it only exchanges the pointers for each vector.The
t_ValuesScaled.push_back(t_ValueToBeScaled);
is inefficient because it can potentially trigger vector reallocation inside the loop. The final size oft_ValuesScaled
is known at the start, so there's no reason not to pre-allocate storage by usingvector::reserve
Here is an alternative implementation: