Skip to content

Commit

Permalink
Limit linear AI output and matrix values to finite values
Browse files Browse the repository at this point in the history
Memory used to quickly get to infinity and cause every other equation to
do so as well
  • Loading branch information
IgorYeremin committed Mar 15, 2017
1 parent 75f2c9c commit f94f834
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,21 @@ public void mutate(float adjustmentStrength) {
for (int v = 0; v < inputs.length; v++) {
// variables with stronger inputs are adjusted more
double strength = adjustmentStrength * Math.abs(inputs[v]);
data[v][eq] += simulator.getRandom().nextGaussian() * strength;
double x = data[v][eq] + simulator.getRandom().nextGaussian() * strength;
data[v][eq] = limitOutput(x);
}
}
}
}

// Do not allow values to reach infinity.
// The limit is arbitrary, probably big enough for any values users would have used in the past
private static double OUTPUT_VALUE_MAX = 100000;
private static final double limitOutput(double value) {
value = Math.max(-OUTPUT_VALUE_MAX, Math.min(OUTPUT_VALUE_MAX, value));
return value;
}


@Override
public void controlAgent(Agent theAgent, ControllerListener inputCallback) {
Expand Down Expand Up @@ -126,8 +135,9 @@ public void controlAgent(Agent theAgent, ControllerListener inputCallback) {
for (int eq = 0; eq < LinearWeightsControllerParams.OUTPUT_COUNT; eq++) {
double res = 0.0;
for (int v = 0; v < variables.length; v++) {
res += data[v][eq] * variables[v];
res += data[v][eq] * variables[v];
}
res = limitOutput(res);

if (eq == 0)
memout = res;
Expand Down

0 comments on commit f94f834

Please sign in to comment.