Skip to content

Commit

Permalink
Fixed errors with a change to how the mutation factors are calculated…
Browse files Browse the repository at this point in the history
… with regards to the maximum gene
  • Loading branch information
georgehtaylor1 committed Nov 9, 2016
1 parent 0451893 commit 2550e59
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
11 changes: 3 additions & 8 deletions src/Creature.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,7 @@ public void act() {
int percept = getPercept();
assert (state <= getParams().getState_count() && state >= 0);
assert (percept <= PERCEPT_COUNT && percept >= 0);
int gene = 0;
try {
gene = getGenes()[state][percept];
} catch (Exception e) {
System.out.println(e);
}
int gene = getGenes()[state][percept];
state = Math.floorDiv(gene, ACTION_COUNT);
if (state < 0) {
System.out.println("ERR");
Expand Down Expand Up @@ -199,8 +194,8 @@ public void act() {
public void mutate(int currRound) {
for (int i = 0; i < getParams().getState_count(); i++) {
for (int j = 0; j < PERCEPT_COUNT; j++) {
int mod = (int) Math.round(Utils.learnFunction(currRound, getParams().getLearning_stretch())
* Utils.modificationFunction(maxGene, getParams().getLearning_exponent()));
int mod = maxGene * (int) Math.round(Utils.learnFunction(currRound, getParams().getLearning_stretch())
* Utils.modificationFunction(getParams().getLearning_exponent()));
getGenes()[i][j] += mod;
getGenes()[i][j] = (getGenes()[i][j] + maxGene) % maxGene;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public static double learnFunction(int currRound, double stretch) {
return Math.pow(Math.E, -(currRound / stretch));
}

public static double modificationFunction(int maxGene, int exponent) {
public static double modificationFunction(int exponent) {
double r = rand.nextDouble() * 2 - 1;
return Math.pow(maxGene * r, exponent);
return Math.pow(r, exponent);
}

}

0 comments on commit 2550e59

Please sign in to comment.