-PlayerModel classes, including a function to get the target score for a player's game and a neural network to predict a player's moves.

This commit is contained in:
Marshall
2012-04-19 21:05:59 -04:00
parent 10f43ee31c
commit f19c09b573
4 changed files with 223 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
package model.playerModel.node;
import java.util.Hashtable;
import model.playerModel.Node;
public class SigmoidNode implements Node {
// Training rate.
private final double A = .15;
private final Hashtable<Node, Double> dendrites = new Hashtable<Node, Double>();
private final double s = 1; // Slope paramater for the activation function.
// It's doing nothing right now, but I figured
// I'd implement it as a tweaking option.
private final double THRESHOLD = .5;
public void addNode(Node n, double weight) {
dendrites.put(n, weight);
}
@Override
public boolean axon() {
double sum = 0;
for (Node n : dendrites.keySet()) {
sum += n.axon() ? dendrites.get(n) : 0;
}
return (activation(sum) > THRESHOLD);
}
@Override
public void learn(boolean correct) {
for (Node n : dendrites.keySet()) {
if (correct && n.axon()) {
dendrites.put(n, dendrites.get(n) + A);
n.learn(correct);
}
}
}
private double activation(double sum) {
// Sigmoid function:
// 1/(1+(e^(-bt)))
double a = -1 * s * sum;
a = Math.exp(a);
a = 1 + a;
a = 1 / a;
return a;
}
}