use of utilities.RangeMapper in project SimpleAsteroids by ljialin.
the class GeneMeanModel method generate.
public int generate() {
double alpha = gainFactor / nValues;
// add the numbers to ...
StatSummary rangeStats = new StatSummary();
// find the range
// but ensure it's not too small
rangeStats.add(0);
rangeStats.add(1);
for (StatSummary ss : stats) {
if (ss.n() > 0) {
rangeStats.add(ss.mean());
}
}
// double range = rangeStats.max() - rangeStats.min();
// having got the range we now map these values in to the new range
// when computing the softmax function
RangeMapper map = new RangeMapper(rangeStats.min(), rangeStats.max(), 0, alpha);
// now put all the numbers through the map
double totExp = 0;
for (StatSummary ss : stats) {
totExp += Math.exp(map.map(safeMean(ss)));
// System.out.println("Summing exp denom: " + totExp + " <- " + map.map(safeMean(ss)));
}
// now pick one
// System.out.println("Tot exp = " + totExp);
double x = random.nextDouble() * totExp;
double tot = 0;
for (int i = 0; i < nValues; i++) {
tot += Math.exp(map.map(safeMean(i)));
if (x <= tot)
return i;
}
throw new RuntimeException("Failed to return a valid option in GenePairedModel");
}
Aggregations