-
Notifications
You must be signed in to change notification settings - Fork 2
/
NetworkShaper.js
90 lines (79 loc) · 2.13 KB
/
NetworkShaper.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
const Random = require('./Random');
class NetworkShaper {
// Random ball shape
// (neurons linked at random)
static ball (count, index) {
var target = Random.integer(0, count - 1);
if (target !== index) {
return target;
}
return undefined;
}
// Drum shape
static drum (count, index) {
const width = count / 3;
const forwardBias = Math.ceil(width * Math.random());
const target = index + forwardBias;
if (target < count) {
return target;
}
return undefined;
}
// Tube shape
static tube (count, index) {
const width = count / 5;
const forwardBias = Math.ceil(width * Math.random());
const target = index + forwardBias;
if (target < count) {
return target;
}
return undefined;
}
// Classic shape (number of layers depends on connections per neuron)
static classic (count, index, connectionCount, connectionIndex) {
const layers = Math.ceil(count / connectionCount);
const offset = Math.floor(count / layers);
const layer = Math.floor((index / count) * layers) + 1;
const target = offset * layer + connectionIndex;
if (target < count) {
return target;
}
return undefined;
}
// Snake shape
static snake (count, index) {
const width = count / 10;
const forwardBias = Math.ceil(width * Math.random());
const target = index + forwardBias;
if (target < count) {
return target;
}
return undefined;
}
// Forward-biased sausage shape
static sausage (count, index) {
const width = count / 4;
const forwardBias = Math.ceil(width * Math.random());
let target = index + forwardBias;
if (target < count) {
return target;
}
target = Random.integer(0, count - 1);
if (target !== index) {
return target;
}
return undefined;
}
// Ring shape
static ring (count, index) {
const width = count / 12;
const forwardBias = Math.ceil(width * Math.random());
const target = index + forwardBias;
if (target < count) {
return target;
}
return target - count; // link to beginning
}
}
module.exports = NetworkShaper;