Vous êtes sur la page 1sur 6

BACK PROPAGATION IN NEURAL NETWORK PROGRAM

/* and open the template in the editor. */

/** * * @author Admin */ public class Neural {

double x1, x2, x3, w14, w15, w24, w25, w34, w35, w46, w56, q4, q5, q6; double inode4, inode5, inode6; double onode4, onode5, onode6; double error6, error4, error5; double learningRate = 0.9;

public Neural(double x1, double x2, double x3, double w14, double w15, double w24, double w25, double w34, double w35, double w46, double w56, double q4, double q5, double q6) { this.x1 = x1; this.x2 = x2; this.x3 = x3; this.w14 = w14; this.w15 = w15; this.w24 = w24; this.w25 = w25; this.w34 = w34;

this.w35 = w35; this.w46 = w46; this.w56 = w56; this.q4 = q4; this.q5 = q5; this.q6 = q6; }

public void calculateInput() { inode4 = x1 * w14 + x2 * w24 + x3 * w34 + q4; inode5 = x1 * w15 + x2 * w25 + x3 * w35 + q5; System.out.println("input at node 4 " + inode4); System.out.println("input at node 5 " + inode5); }

public void calculateOutput() { onode4 = (1 / (1 + Math.exp(-inode4))); onode5 = (1 / (1 + Math.exp(-inode5))); System.out.println("output at node 4 " + onode4); System.out.println("output at node 5 " + onode5); }

public void calculateInputAndOutputAtNode6() { inode6 = w46 * onode4 + w56 * onode5 + q6; onode6 = (1 / (1 + Math.exp(-inode6))); System.out.println("input at node 6 " + inode6);

System.out.println("output at node 6 " + onode6); }

public void calculateError() { error6 = onode6 * (1 - onode6) * (1 - onode6); error4 = onode4 * (1 - onode4) * (error6 * w46); error5 = onode5 * (1 - onode5) * (error6 * w56); System.out.println("error at node 6 " + error6); System.out.println("error at node 4 " + error4); System.out.println("error at node 5 " + error5); }

public void calculateWeight() { w46 = w46 + (learningRate * error6) * (onode4); w56 = w56 + (learningRate * error6) * (onode5); w14 = w14 + (learningRate * error4) * (x1); w15 = w15 + (learningRate * error5) * (x1); w24 = w24 + (learningRate * error4) * (x2); w25 = w25 + (learningRate * error5) * (x2); w34 = w34 + (learningRate * error4) * (x3); w35 = w35 + (learningRate * error5) * (x3); System.out.println("weight after adjustment w56" + w56); System.out.println("weight after adjustment w14" + w14); System.out.println("weight after adjustment w15" + w15); System.out.println("weight after adjustment w24" + w24); System.out.println("weight after adjustment w25" + w25);

System.out.println("weight after adjustment w34" + w34); System.out.println("weight after adjustment w35" + w35); }

public void CalculateBias() { q6 = q6 + learningRate * error6; q5 = q5 + learningRate * error5; q4 = q4 + learningRate * error4; System.out.println("bias at node 6" + q6); System.out.println("bias at node 5" + q5); System.out.println("bias at node 4" + q4); }

public static void main(String args[]) { Neural neural = new Neural(1, 0, 1, 0.2, -0.3, 0.4, 0.1, -0.5, 0.2, -0.3, -0.2, -0.4, 0.2, 0.1); neural.calculateInput(); neural.calculateOutput(); neural.calculateInputAndOutputAtNode6(); neural.calculateError(); neural.calculateWeight(); neural.CalculateBias(); } }

OUTPUT input at node 4 -0.7 input at node 5 0.10000000000000003 output at node 4 0.3318122278318339 output at node 5 0.52497918747894 input at node 6 -0.10453950584533817 output at node 6 0.47388889882398544 error at node 6 0.1311690782143445 error at node 4 -0.008724561965433263 error at node 5 -0.006542085064168994 weight after adjustment w56-0.13802506750700472 weight after adjustment w140.19214789423111006 weight after adjustment w15-0.30588787655775207 weight after adjustment w240.4 weight after adjustment w250.1 weight after adjustment w34-0.50785210576889 weight after adjustment w350.19411212344224793 bias at node 60.21805217039291008 bias at node 50.19411212344224793 bias at node 4-0.40785210576888997 BUILD SUCCESSFUL (total time: 3 seconds)

DIAGRAM FOR NEURAL NETWORK

1 W14 W15 W24 2 W25 5 W34 3 w35 w56 4 W46 6

INPUT LAYER

HIDDEN LAYER

OUTPUT LAYER