// This class implements a perceptron with two inputs and one output. // Please notice that this means the network has just one neuron. public class EngineeredPerceptron { private int trainingSetSize = 0; private int inputSize = 2; // Fixed for now. private double inputs[][]; private double desiredOutputs[]; private double[] weights; // Programmer determined for now. private double threshold; // Programmer determined for now. public void initNetwork(double[][] inputs, double[] desiredOutputs) { this.inputs = inputs; this.trainingSetSize = inputs.length; if (this.trainingSetSize == 0) { System.out.println("No training data."); System.exit(0); } this.desiredOutputs = desiredOutputs; this.weights = new double[inputSize]; //TODO: set the lowest weights using one decimal. this.weights[0] = 1; this.weights[1] = 1; //TODO: Set the threshold. Make this the minimum, again using one decimal. this.threshold = 1; } private double stepActivationFunction(double input){ if (input >= threshold) return 1; return 0; } public void testNetwork(){ for (int i = 0; i < trainingSetSize; i++){ double inputToNeuron = 0; for (int j = 0; j < inputSize; j++){ inputToNeuron += weights[j] * inputs[i][j]; } double activationOfNeuron = stepActivationFunction(inputToNeuron); if (activationOfNeuron != desiredOutputs[i]) System.out.println("Network did not learn item " + i); } System.out.println("\nDone testing."); } }