-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvis.html
More file actions
123 lines (107 loc) · 3.79 KB
/
Copy pathvis.html
File metadata and controls
123 lines (107 loc) · 3.79 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html lang="en">
<head>
<title>Vis Network | Data | Custom Scaling</title>
<style type="text/css">
html,
body {
font: 10pt arial;
}
#mynetwork {
width: 900px;
height: 900px;
border: 1px solid lightgray;
}
</style>
<script type="text/javascript" src="vis-network.min.js"></script>
<script type="text/javascript">
var nodes = null;
var edges = null;
var network = null;
function draw() {
var cachedBrain = JSON.parse(localStorage.getItem("reconnect"));
if (cachedBrain != null) {
nodes = [];
// //for (let layerIndex = 0; layerIndex < cachedBrain.length; layerIndex++) {
let layerIndex = 0;
let brainLen = cachedBrain[layerIndex].length;
for (let neuronIndex = 0; neuronIndex < brainLen; neuronIndex++) {
let groupLabel = "";
if (neuronIndex < 16) { groupLabel = "Input "; }
if (neuronIndex > 16 && neuronIndex < brainLen - 8) { groupLabel = "Hidden "; }
if (neuronIndex > brainLen - 8) { groupLabel = "Output "; }
let neuronLabel = "";
// if (layerIndex == 0 || layerIndex == 3) {
neuronLabel = cachedBrain[0][neuronIndex].label;
// }
neuronLabel += " (" + groupLabel + ") [" + layerIndex + "." + neuronIndex + "]"
nodes.push({ id: layerIndex + "." + neuronIndex, label: neuronLabel, group: groupLabel, font: { color: "white" } })
}
//}
edges = [];
//for (let layerIndex = 0; layerIndex < cachedBrain.length; layerIndex++) {
for (let neuronIndex = 14; neuronIndex < cachedBrain[layerIndex].length; neuronIndex++) {
for (let connectionIndex = 0; connectionIndex < cachedBrain[layerIndex][neuronIndex].connections.length; connectionIndex++) {
if (cachedBrain[layerIndex][neuronIndex].connections[connectionIndex][1] > 0) {
edges.push({ from: (layerIndex) + "." + connectionIndex, to: layerIndex + "." + neuronIndex, value: Math.abs(cachedBrain[layerIndex][neuronIndex].connections[connectionIndex][1]), arrows: "to" })
}
}
}
//}
// Instantiate our network object.
var container = document.getElementById("mynetwork");
var data = {
nodes: nodes,
edges: edges,
};
var options = {
nodes: {
shape: "dot",
size: 16
},
interaction: {
tooltipDelay: 200,
//hideEdgesOnDrag: true
},
edges: {
smooth: true
},
physics: {
forceAtlas2Based: {
theta: 0.5,
gravitationalConstant: -150,
centralGravity: 0.03,
springConstant: 0.04,
springLength: 100,
damping: 5,
avoidOverlap: 0
},
maxVelocity: 1046,
solver: "forceAtlas2Based",
timestep: 0.25,
stabilization: { iterations: 0 }
},
configure: {
filter: function (option, path) {
if (path.indexOf("physics") !== -1) {
return true;
}
if (path.indexOf("smooth") !== -1 || option === "smooth") {
return true;
}
return false;
},
container: document.getElementById("config")
}
};
network = new vis.Network(container, data, options);
}
}
</script>
</head>
<body onload="draw()">
<input type="button" value="redraw" onclick="draw()" />
<div id="mynetwork"></div>
<div id="config"></div>
</body>
</html>