public static void main(String[l args) {l
int TRAINING_SIZE = 300;
int TESTING_SIZE = 100;
Perceptron p = new Perceptron(;
25262728
34353637383948
4142
// Generate random numbers between 0 and 255 (8 bits)
Random r = new Random ;
for (int i = 0; i ‹ TRAINING_SIZE; i++) {
Digit d = new Digit( r.nextInt(0, 255) );
p. train( d.getBinary(), d.getLabel() );
}
// Testing Phase
// Generate more random numbers and evaluate the Perceptron’s trained model.
int correct = 0;
for (int i = 0; i ‹ TESTING_SIZE; i++) {
Digit d = new Digit( r.nextInt(0, 255) );
if ( d. getLabel () == p. guess ( d. getBinary () ))
correct++;
}
// Output the percent of times the Perceptron correctly identified whether
// a number was odd or even.
System.out.printf(“Percent Correct: %.2f%%\n”, (correct/(TESTING_SIZE*1.0))*100);
System.out.print(“Final Perceptron Weights: “);
printArray ( p. getWeights () );
Percent Correct: 96.00%
Final Perceptron Weights: [-0.0030, 0.0250, 0.0150, 0.0250, 0.0250, 0.0130, 0.0070, -0.09101]
GIPHY App Key not set. Please check settings