-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathneurone.class.js
More file actions
83 lines (70 loc) · 1.65 KB
/
neurone.class.js
File metadata and controls
83 lines (70 loc) · 1.65 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class neurone{
constructor(params){
this.n=params.n;
this.activation=params.activation;
this.affectRandomValue("ceil",params);
this.affectRandomArrayValue("weights",params);
this.emptyArray("inputs",params);
}
affectRandomValue(prop,params){
if (params[prop]) {
this[prop]=params[prop];
} else {
this[prop]=Math.random();
}
}
affectRandomArrayValue(prop,params){
if (params[prop]) {
this[prop]=params[prop];
} else {
this[prop]=[];
for (var i=0; i<this.n; i++) {
this[prop].push(Math.random());
}
}
}
emptyArray(prop,params){
if (params[prop]) {
this[prop]=params[prop];
} else {
this[prop]=[];
for (var i=0; i<this.n; i++) {
this[prop].push(0);
}
}
}
setWeight(i,weight){
this.weights[i]=weight;
}
setInput(i,input){
this.inputs[i]=input;
}
setWeights(weights){
this.weights=weights;
}
setInputs(inputs){
this.inputs=inputs;
}
setCeil(ceil){
this.ceil=ceil;
}
integrate(){
this.output=0;
for (var i=0; i<this.n; i++) {
this.output+=this.weights[i]*this.inputs[i];
}
this.output-=this.ceil;
}
getOutput(){
this.integrate();
return this.activation(this.output);
}
getOutputLast(){
this.integrate();
return this.output;
}
getWeights(){
return this.weights
}
}
module.exports = neurone;