-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nuron.java
69 lines (58 loc) · 1.53 KB
/
Nuron.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Back;
/**
*
* @author Sachin
*/
public class Nuron {
//weights
private double w1;
private double w2;
private double w3;
private double w4;
//inputs
private int x1;
private int x2;
private int x3;
private int x4;
private double output;
private double error;
public Nuron(double w1, double w2, double w3, double w4) {
this.w1 = w1;
this.w2 = w2;
this.w3 = w3;
this.w4 = w4;
}
public void setInput(int x1, int x2, int x3, int x4) {
this.x1 = x1;
this.x2 = x3;
this.x3 = x3;
this.x4 = x4;
}
public double getOutput() {
double z;
z = x1 * w1 + x2 * w2 + x3 * w3 + x4 * w4;
output = 1 / (1 + Math.exp(-z ));
return output;
}
public void setWeight(int tr) {
double o = getOutput();
double dw1 = (tr - o) * (1 - o) * o * x1;
double dw2 = (tr - o) * (1 - o) * o * x2;
double dw3 = (tr - o) * (1 - o) * o * x3;
double dw4 = (tr - o) * (1 - o) * o * x4;
w1 = w1 + dw1;
w2 = w2 + dw2;
w3 = w3 + dw3;
w4 = w4 + dw4;
}
public double error(int tr) {
double o = getOutput();
error = 0.5 * (tr - o) * (tr - o);
return error;
}
}