Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class twoLayerNeuralNetwork
- {
- public static void main(String[] args)
- {
- double inputs[][] =
- {
- {0,0,1},
- {0,1,1},
- {1,0,1},
- {0,1,0},
- {1,0,0},
- {1,1,1},
- {0,0,0}
- };
- //patter: XOR for first two inputs- third input is irrelevant
- double neurons[] = {0.1,0.9,0.1,0.9};
- double outputs[] = {0,1,1,1,1,0,0};
- double weights1[][] =
- {
- {0.3,4.5,-6},
- {-8.75,0.2,-8.75},
- {6.2,4.4,0},
- {-0.5,0.08,-0.4}
- };
- double weights2[] =
- {0,0,0,0};
- for(int set=0; set<inputs.length; set++)
- {
- for(int neuron=0; neuron<weights1.length; neuron++)
- {System.out.println("set: "+set+" neuron: "+neuron+" "+sum(weights1[neuron],inputs[set]));}
- System.out.print("\n");}
- }
- public static double[] train(double inputs[][], double weights1[][], double neurons[], double weights2[], double outputs[])
- {
- }
- public static double sum(double w[], double i[])
- {
- double sum = 0;
- for(int p=0; p<w.length; p++)
- {sum+=w[p]*i[p];}
- return sum;
- }
- public static double sigmoid(double s)
- {
- return (1/(1+Math.exp(-1*s)));
- }
- public static double[] adjust(double inputs[], double outputs[], double weights[])
- {
- double testOutputs[] = new double[outputs.length];
- for(int n=0; n<outputs.length; n++)
- {testOutputs[n]=sigmoid(sum(weights,inputs));}
- for(int n=0; n<weights.length; n++)
- {
- double error = outputs[n]-testOutputs[n];
- weights[n]+=(error*inputs[n]*testOutputs[n]*(1-testOutputs[n]));
- }
- return weights;
- }
- }
Add Comment
Please, Sign In to add comment