-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
64 lines (52 loc) · 1.33 KB
/
sketch.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
let nn;
let training_data = [{
inputs: [0, 0],
targets: [0]
}, {
inputs: [1, 0],
targets: [1]
}, {
inputs: [0, 1],
targets: [1]
}, {
inputs: [1, 1],
targets: [0]
}];
let lr_slider;
function setup() {
createCanvas(400, 400);
nn = new NeuralNetwork(2, 2, 1);
for (let i = 0; i < 50000; i++) {
let data = random(training_data);
nn.train(data.inputs, data.targets)
}
console.log(nn.feedforward([1,1]));
console.log(nn.feedforward([1,0]));
console.log(nn.feedforward([0,1]));
console.log(nn.feedforward([0,0]));
// lr_slider = createSlider(0.01, 0.1, 0.05, 0.01);
}
// function draw() {
// background(0);
// nn.learning_rate = lr_slider.value();
// for (let i = 0; i < 100; i++) {
// let data = random(training_data);
// nn.train(data.inputs, data.targets);
// }
// let resolution = 20;
// let cols = floor(width / resolution);
// let rows = floor(height / resolution);
// for (let i = 0; i < cols; i++) {
// for (let j = 0; j < rows; j++) {
// let x = i * resolution;
// let y = j * resolution;
// let input_1 = i / (cols - 1);
// let input_2 = j / (rows - 1);
// let output = nn.feedforward([input_1, input_2]);
// let col = output[0] * 255;
// fill(col);
// noStroke();
// rect(x, y, resolution, resolution);
// }
// }
// }