xxxxxxxxxx
Perceptron(int n) {
weights = new float[n];
for (int i = 0; i < weights.length; i++) {
The weights are picked randomly to start.
weights[i] = random(-1,1);
}
}
float[] inputs = {12 , 4};
float[] weights = {0.5,-1};
float sum =0;
for(int i =0;i < inputs.length;i++)
{
sum += inputs[i] * weights[i];
}
float output = activate(sum);
int activate(float sum) {
// Return a 1 if positive, -1 if negative.
if (sum > 0) return 1;
else return -1;
} // End activate
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
}
function draw() {
// ellipse(mouseX, mouseY, 20, 20);
}