-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi.js
41 lines (38 loc) · 1.25 KB
/
multi.js
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
const SinglePerceptronLearner = require('./simple');
let nextWeight1, nextWeight2;
const initalWeight1 = 1;
const initalWeight2 = 2;
const thresholdThetha = 1;
const learningRate = 0.5;
const arrayX1 = [1, 1, -1, -1];
const arrayX2 = [1, -1, 1, -1];
const arrayDt = [1, -1, -1, -1];
let p;
for (let i = 0; i < arrayX1.length; i++) {
const x0 = arrayX1[i];
const x1 = arrayX2[i];
const dt = arrayDt[i];
console.log(`x0:${x0}, x1:${x1}, dt:${arrayDt}`);
// first iteration use inital wights
if (i === 0) {
p = new SinglePerceptronLearner(x0, x1, dt, threshold = thresholdThetha, learning_rate = learningRate, weight_one = initalWeight1, weight_second = initalWeight2);
p.calcYt();
p.initalWeights(1, 2);
p.calcWt();
nextWeight1 = p.nextWt0();
nextWeight2 = p.nextWt1();
p.current_accuracy();
p.display();
}
// rest of iteration will use nextWeight1, nextWeight2 coming from first iteration
else {
p = new SinglePerceptronLearner(x0, x1, dt, threshold = thresholdThetha, learning_rate = learningRate, weight_one = nextWeight1, weight_second = nextWeight2);
p.calcYt();
p.initalWeights(1, 2);
p.calcWt();
nextWeight1 = p.nextWt0();
nextWeight2 = p.nextWt1();
p.current_accuracy();
p.display();
}
}