Tried doing that, it seems as if the problem is related to the
NeuralNet.pde
class NeuralNet {
int iNodes, hNodes, oNodes, hLayers;
Matrix[] weights;
NeuralNet(int input, int hidden, int output, int hiddenLayers) {
iNodes = input;
hNodes = hidden;
oNodes = output;
hLayers = hiddenLayers;
weights = new Matrix[hLayers + 1];
weights[0] = new Matrix(hNodes, iNodes + 1);
for (int i = 1; i < hLayers; i++) {
weights[i] = new Matrix(hNodes, hNodes + 1);
}
weights[weights.length - 1] = new Matrix(oNodes, hNodes + 1);
for (Matrix w : weights) {
w.randomize();
}
}
void mutate(float mr) {
for (Matrix w : weights) {
w.mutate(mr);
}
}
float[] output(float[] inputsArr) {
Matrix inputs = weights[0].singleColumnMatrixFromArray(inputsArr);
Matrix curr_bias = inputs.addBias();
for (int i = 0; i < hLayers; i++) {
Matrix hidden_ip = weights[i].dot(curr_bias);
Matrix hidden_op = hidden_ip.activate();
curr_bias = hidden_op.addBias();
}
Matrix output_ip = weights[weights.length - 1].dot(curr_bias);
Matrix output = output_ip.activate();
return output.toArray();
}
NeuralNet crossover(NeuralNet partner) {
NeuralNet child = new NeuralNet(iNodes, hNodes, oNodes, hLayers);
for (int i = 0; i < weights.length; i++) {
child.weights[i] = weights[i].crossover(partner.weights[i]);
}
return child;
}
NeuralNet clone() {
NeuralNet clone = new NeuralNet(iNodes, hNodes, oNodes, hLayers);
for (int i = 0; i < weights.length; i++) {
clone.weights[i] = weights[i].clone();
}
return clone;
}
void show(float x, float y, float w, float h, float[] vision, float[] decision) {
float space = 5;
float nSize = (h - (space * (iNodes - 2))) / iNodes;
float nSpace = (w - (weights.length * nSize)) / weights.length;
float hBuff = (h - (space * (hNodes - 1)) - (nSize * hNodes)) / 2;
float oBuff = (h - (space * (oNodes - 1)) - (nSize * oNodes)) / 2;
int lc = 0; // Layer Count
// DRAW NODES
for (int i = 0; i < iNodes; i++) { // DRAW INPUTS
fill(vision[i] > 0 ? color(0, 255, 0) : color(255));
stroke(0);
ellipseMode(CORNER);
ellipse(x, y + (i * (nSize + space)), nSize, nSize);
}
lc++;
for (int a = 0; a < hLayers; a++) {
for (int i = 0; i < hNodes; i++) { // DRAW HIDDEN
fill(color(255));
stroke(0);
ellipseMode(CORNER);
ellipse(x + (lc * nSize) + (lc * nSpace), y + hBuff + (i * (nSize + space)), nSize, nSize);
}
lc++;
}
for (int i = 0; i < oNodes; i++) { // DRAW OUTPUTS
fill(decision[i] > 0 ? color(0, 255, 0) : color(255));
stroke(0);
ellipseMode(CORNER);
ellipse(x + (lc * nSpace) + (lc * nSize), y + oBuff + (i * (nSize + space)), nSize, nSize);
}
lc = 1;
// DRAW WEIGHTS
for (int i = 0; i < weights[0].rows; i++) { // INPUT TO HIDDEN
for (int j = 0; j < weights[0].cols - 1; j++) {
if (weights[0].matrix[i][j] < 0) {
stroke(255, 0, 0);
} else {
stroke(0, 0, 255);
}
line(x + nSize, y + (nSize / 2) + (j * (space + nSize)), x + nSize + nSpace, y + hBuff + (nSize / 2) + (i * (space + nSize)));
}
}
lc++;
for (int a = 1; a < hLayers; a++) {
for (int i = 0; i < weights[a].rows; i++) { // HIDDEN TO HIDDEN
for (int j = 0; j < weights[a].cols - 1; j++) {
if (weights[a].matrix[i][j] < 0) {
stroke(255, 0, 0);
} else {
stroke(0, 0, 255);
}
line(x + (lc * nSize) + ((lc - 1) * nSpace), y + hBuff + (nSize / 2) + (j * (space + nSize)), x + (lc * nSize) + (lc * nSpace), y + hBuff + (nSize / 2) + (i * (space + nSize)));
}
}
lc++;
}
for (int i = 0; i < weights[weights.length - 1].rows; i++) { // HIDDEN TO OUTPUT
for (int j = 0; j < weights[weights.length - 1].cols - 1; j++) {
if (weights[weights.length - 1].matrix[i][j] < 0) {
stroke(255, 0, 0);
} else {
stroke(0, 0, 255);
}
line(x + (lc * nSize) + ((lc - 1) * nSpace), y + hBuff + (nSize / 2) + (j * (space + nSize)), x + (lc * nSize) + (lc * nSpace), y + oBuff + (nSize / 2) + (i * (space + nSize)));
}
}
}
}
or the
NeuralNetworkWindow
class NeuralNetworkWindow extends PApplet {
OthelloGame parent;
AIPlayer aiPlayer;
NeuralNetworkWindow(OthelloGame parent, AIPlayer aiPlayer) {
this.parent = parent;
this.aiPlayer = aiPlayer;
}
public void settings() {
size(800, 800);
println("NeuralNetworkWindow settings initialized");
}
public void setup() {
background(255);
println("NeuralNetworkWindow setup completed");
}
public void draw() {
background(255);
drawNeuralNetwork();
println("Neural network visualization drawn in NeuralNetworkWindow");
}
void drawNeuralNetwork() {
float x = 50;
float y = 50;
float w = width - 100;
float h = height - 100;
float[] vision = new float[64]; // Example input data
float[] decision = aiPlayer.brain.output(vision); // Example output data
aiPlayer.brain.show(x, y, w, h, vision, decision);
}
void updateVisualization() {
redraw();
println("Neural network visualization updated in NeuralNetworkWindow");
}
}
i’m not sure what but when i use this code it causes the glitch, i can’d find exactly why