-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:
58
src/model/playerModel/node/SigmoidNode.java
Normal file
58
src/model/playerModel/node/SigmoidNode.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user