Skip to content

Commit

Permalink
start on correlated mutations (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahiel committed Oct 10, 2017
1 parent 4ec7c14 commit d3fef45
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
36 changes: 34 additions & 2 deletions Individual.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import java.lang.Math;
import java.util.Random;

import org.apache.commons.math3.distribution.MultivariateNormalDistribution;


public class Individual
{
Expand All @@ -9,6 +11,7 @@ public class Individual
public double probability;
public int rank;
private double[] sigma;
private double[] alpha;
private final double UB = 5.0;
private final double LB = -UB;
private boolean evaluated;
Expand Down Expand Up @@ -104,8 +107,8 @@ private void uncorrelatedMutationWithOneStepSize(Random rnd)

private void uncorrelatedMutationWithNStepSizes(Random rnd)
{
double tau = 0.05; // local learning rate
double tau2 = 0.9; // global learning rate
double tau = 0.05; // local learning rate (τ)
double tau2 = 0.9; // global learning rate (τ')
double epsilon = 0.001;
double gamma = tau2 * rnd.nextGaussian();

Expand All @@ -119,7 +122,36 @@ private void uncorrelatedMutationWithNStepSizes(Random rnd)

private void correlatedMutation(Random rnd)
{
double beta = 5;
int n = value.length;
int sign;
double n_alpha = n * (n - 1) / 2;
double tau = 0.05; // local learning rate
double tau2 = 0.9; // global learning rate
double epsilon = 0.001;
double gamma = tau2 * rnd.nextGaussian();

alpha = new double[n_alpha];

for (int i = 0; i < n; i++) {
double g = rnd.nextGaussian();
sigma[i] *= Math.exp(gamma + tau * g);
sigma[i] = Math.max(sigma[i], epsilon);

for (int j = 0; j < n_alpha; j++) {
alpha[j] += beta * rnd.nextGaussian();
if (Math.abs(alpha[j]) > Math.PI) {
if (alpha[j] >= 0) {
sign = 1;
} else {
sign = -1;
}
alpha[j] = alpha[j] - 2 * Math.PI * sign;
}
}
// TODO: figure out the covariance matrix p. 61
value[i] = boundedAdd(value[i], sigma[i] * g);
}
}

// check to ensure v stays in domain of function
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

SHELL=/bin/bash
JC=javac
JCFLAGS=-cp contest.jar
JCFLAGS=-cp contest.jar:commons-math3-3.6.1.jar
PLAYER=player50

SOURCES=$(PLAYER).java $(filter-out $(PLAYER).java, $(wildcard *.java))
Expand Down
Binary file added commons-math3-3.6.1.jar
Binary file not shown.

0 comments on commit d3fef45

Please sign in to comment.