-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
378 lines (327 loc) · 18.2 KB
/
index.html
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<!DOCTYPE html>
<html class="data_viz">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lets Visualize some Neural Networks</title>
<head>
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="css/normalize.css" />
<script src="scripts/modernizr.custom.js"></script>
<script src="scripts/d3.v3.min.js"></script>
<script src="scripts/sankey.js"></script>
<script src="scripts/queue.v1.min.js"></script>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/jquery.dropotron.min.js"></script>
<script src="scripts/skel.min.js"></script>
<script src="scripts/util.js"></script>
<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
<script src="scripts/main.js"></script>
</head>
<style>
#chart {
widht: 960px;
height: 800px;
}
.node rect {
cursor: move;
fill-opacity: .9;
shape-rendering: crispEdges;
}
.node circle {
cursor: move;
fill-opacity: .9;
}
.node text {
//pointer-events: none;
//text-shadow: 0 1px 0 #fff;
}
.link {
//fill: none;
//stroke: #000;
//stroke-opacity: .2;
}
.link:hover {
stroke-opacity: .5;
}
</style>
<body>
<div id="header-wrapper">
<div id="header" class="container">
<span>CSE 512</span>
<h1>Neural Network Behavior</h1>
<h3>Visualizing Neuron Co-activation to Reveal Structure</h3>
<h4>Kendall Lowrey, Tam Nguyen</h4>
<!-- Nav -->
<nav id="nav">
<ul>
<li>
<a id="xor" href="#">XOR Network</a>
<ul>
<li><a id="xor_u" href="#">Big XOR Untrained</a></li>
<li><a id="xor_t" href="#">Big XOR Trained</a></li>
<li><a id="xor_s" href="#">Small Xor Trained</a></li>
</ul>
</li>
<li>
<a id="mnist" href="#">MNIST_network</a>
<ul>
<li><a id="mnist_s" href="#">Big MNIST</a></li>
</ul>
</li>
<li>
<a id="robot" href="#">Robotics Policy Network</a>
<ul>
<li><a id="robot_h" href="#">Biped Walker</a></li>
<li><a id="robot_s" href="#">Biped Runner</a></li>
</ul>
</li>
<!--
<li>
<a id="save" href="#">Save Image</a>
</li>
-->
</ul>
</nav>
</div>
</div>
<div class="wrapper">
<div class="container">
<div class="row 150%">
<div class="12u 12u(narrower)">
<!-- Content -->
<article id="content">
<header>
<h2 id="network_title">Network Name</h2>
</header>
<p id="chart"></p>
</article>
</div>
</div>
<div class="row 150%">
<div class="12u 12u(narrower)">
<article id="content">
<section>
<header>
<h3 id="network_info">Network Info</h3>
</header>
</section>
<section>
<header>
<h3>Abstract</h3>
</header>
<p>Artificial Neural Networks have traditionally been treated as black boxes, both in their development and in their use. We present a method to discover the internal structure of neural networks by visualizing activation properties of the network with respect to input data: co-activations of multiple neurons. Our method combines statistical analysis techniques with a modified Sankey Diagram to show flow of data through neural networks unlike previous visualizations methods. Implications for this technique beyond behavioral and structural visualization include the optimization of an artificial neural network through parameter reduction and further understanding of their processing.</p>
<p>
<a id="paper" href="https://github.com/CSE512-15S/fp-klowrey-nttam15/raw/gh-pages/final/paper-klowrey-nttam15.pdf">PAPER</a>
<a id="paper" href="https://github.com/CSE512-15S/fp-klowrey-nttam15/raw/gh-pages/final/poster-klowrey-nttam15.pdf">POSTER</a>
</p>
<h3 id="run_code">Run the Code</h3>
<p>
While our visualization method runs in the browser, it depends on proper data collection. scripts/sankey.js does most of the heavily lifting of actual rendering, depeding on json data representing the nodes and links, along with some meta data.</p>
<p>The easiest way to generate this data is to run "nodejs tsne_xor.js". This script generates three neural networks (the XOR networks above), trians them, collects the activation data, processes it with tSNE, and generates the data structure needed by the rendering script in the browser. Other network data required external software support; the collected activation data has been included in the repository, but the neural network software was not.
</p>
</section>
</article>
</div>
</div>
<!--
<div class="row 150%">
<div class="12u 12u(narrower)">
<article id="svgdataurl">
</article>
</div>
</div>
</div>
-->
</div>
</div>
<script>
var filename_arr=[], title_arr=[], text_block=[];
filename_arr.push("data/xor_sankey.json"); // 0
title_arr.push("Trained XOR Network");
text_block.push("We trained a neural network with two fully connected layers of 16 neurons each on a 3-input XOR problem. XOR is a classic example for neural networks: as the inputs are not linearly separable (without data transformation), a non-linear neural network can learn how to predict the output of the XOR function. In this example, we can see groupings form in the middle columns; these are the network's hidden layers.");
filename_arr.push("data/xor_notrain_sankey.json"); // 1
title_arr.push("Untrained XOR Network");
text_block.push("In this untrained XOR neural network, the groupings within and between layers are less distinct. As the network is untrained, the neuron activations are random, leading to no co-activating behavior, and thus no groupings in the visualization.");
filename_arr.push("data/xor_smaller_sankey.json"); // 2
title_arr.push("Minimized Xor Network");
text_block.push("\"Neurons that fire together wire together\" -- this phrase describes how biological neural networks make connections. Taking the larger trained XOR network, we reduce the number of neurons based on the groupings we see with this visualization to create 6 neuron layer and 5 neuron layer network. Numerically, these two networks feature similar behavior (same order of magnitude loss function), but the smaller network features less than half of the original network's neurons.");
filename_arr.push("data/mnist_sankey_v2.json"); // 3
title_arr.push("MNIST Network");
text_block.push("The Mixed National Institute of Standards and Technology (MNIST) database is a standard dataset used to benchmark machine learning techniques by recognizing handwritten numbers. For neural networks the input is a 24x24 binary image (which we condense into one spot in the visualization) with a softmax output predicting which class (of 10 possible) the image fits. We use a 64-, 32-, 32-neuron 3-layer network. To make the image less busy and increase performance, we threshold the amount of links between layers to show only the strongest connections. Future work of this visualization technique includes highlighting the strongest groupings and connections for specific inputs: this would reveal structure of the network with respect to input features such as horizontal or vertical lines in the MNIST inputs.");
//filename_arr.push("data/mnist_sankey_v2.json");
//title_arr.push("MNIST Network");
filename_arr.push("data/mnist_sankey.json"); //4
title_arr.push("MNIST Convolutional Network???");
text_block.push("none...");
filename_arr.push("data/humanoid.json"); // 5
title_arr.push("Walker Robot Control Network");
text_block.push("Neural Networks are also used for complex control algorithms. Recent work has utilized large neural networks to approximate behavior policies for robot control. A network is trained on hundreds of walking examples to generalize the behavior. The visualization represents the policy which is inherently crowded due to it operating on continuous inputs. However, a noticeable trend is the split in the third layer that we suspect is due to the symmetry of walking. The network is 76x250x250x250 4-layer fully connected.");
filename_arr.push("data/biped_all.json"); // 6
title_arr.push("Runner Robot Control Network");
text_block.push("Similar to the walking robot's control network, this network represents a robot trained on running data. The split in the third layer is not apparent here, but this technique will be applied to a robot with different morphology. Hopefully, a four legged robot's control policy should exhibit some difference in structure.");
function update_sankey(index) {
console.log("loading file: "+filename_arr[index]);
queue()
.defer(d3.json, filename_arr[index])
.await(ready);
$('#network_title').html(title_arr[index]);
$('#network_info').html(text_block[index]);
}
$('#xor').click(function(){ update_sankey(0); return false; });
$('#xor_u').click(function(){ update_sankey(1); return false; });
$('#xor_t').click(function(){ update_sankey(0); return false; });
$('#xor_s').click(function(){ update_sankey(2); return false; });
$('#mnist').click(function(){ update_sankey(3); return false; });
$('#mnist_s').click(function(){ update_sankey(3); return false; });
$('#mnist_c').click(function(){ update_sankey(4); return false; });
$('#robot').click(function(){ update_sankey(5); return false; });
$('#robot_h').click(function(){ update_sankey(5); return false; });
$('#robot_s').click(function(){ update_sankey(6); return false; });
var m_width = 960;
var m_height = 800;
var margin = {top: 30, right: 30, bottom: 30, left: 30};
var width = m_width - margin.left - margin.right;
var height = m_height - margin.top - margin.bottom;
var formatNumber = d3.format(",.3f");
var format = function(d) { return formatNumber(d); };
var color = d3.scale.category20();
//console.log([width, height]);
var sankey = d3.sankey()
.nodeWidth(24)
.nodePadding(8)
.size([width, height]);
var mapRange = function(from, to, s) {
return to[0] + (s - from[0]) * (to[1] - to[0]) / (from[1] - from[0]);
};
var svg = d3.select("#chart").append("svg")
.attr("width", m_width)
.attr("height", m_height)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
/* for generating images
d3.select("#save").on("click", function(){
var html = d3.select("svg")
.attr("version", 1.1)
.attr("xmlns", "http://www.w3.org/2000/svg")
.node().parentNode.innerHTML;
//console.log(html);
var imgsrc = 'data:image/svg+xml;base64,'+ btoa(unescape(encodeURIComponent(html)));
var img = '<img src="'+imgsrc+'">';
d3.select("#svgdataurl").html(img);
});
*/
// Initialize with the simple xor network
update_sankey(2);
function ready(error, data_s) {
d3.select("svg")
.remove();
var svg = d3.select("#chart").append("svg")
.attr("width", m_width)
.attr("height", m_height)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
console.log("nodes: "+data_s.nodes.length)
console.log("links: "+data_s.links.length)
console.log("meta: "+data_s.meta.length)
sankey
.nodes(data_s.nodes)
.links(data_s.links)
.nodeWidth(data_s.opt.nodeWidth)
.nodePadding(margin.top)
.layout(32);
// combine additional data into node strutures
for (var n=0; n<data_s.nodes.length; n++) {
data_s.nodes[n].size = data_s.meta[n].size;
if (data_s.meta[n].pos.length == 1) {
data_s.nodes[n].pos = [];
data_s.nodes[n].pos.push(mapRange([-1, 1], [0, height], data_s.meta[n].pos[0]));
console.log("before: "+data_s.meta[n].pos[0]+"mapped: " +data_s.nodes[n].pos[0]);
} else {
data_s.nodes[n].pos = data_s.meta[n].pos;
}
}
//console.log(sankey)
// TODO these options should probably be in the json files or
// somehow set to change depending on which network is currently visualized
var n_scale = data_s.opt.node_scale;
var l_scale = data_s.opt.link_scale;
var l_opcty = data_s.opt.link_opcty;
console.log(l_scale + " :: " + l_opcty);
svg.append("rect")
.attr("width", m_width)
.attr("height", m_height)
.attr("fill", "#f0f0f0");
var path = d3.svg.diagonal()
.source(function(d) {
return {
"x":d.source.dy,
"y":d.source.x + sankey.nodeWidth()/2};
})
.target(function(d) {
return {
"x":d.target.dy,
"y":d.target.x + sankey.nodeWidth()/2};
})
.projection(function(d) { return [d.y, d.x]; });
var link = svg.append("g").selectAll(".link")
.data(data_s.links)
.enter().append("path")
.attr("class", "link")
.attr("d", path)
.style("stroke-width", function(d) { return Math.min(3, l_scale*d.value); })
.sort(function(a, b) { return b.dy - a.dy; })
.style("fill", "none")
.style("stroke", "black")
.style("opacity", function(d) { return Math.max(0.1, d.value/l_opcty); });
link.append("title")
.text(function(d) {
return d.source.name+" → "+d.target.name+"\n"
+format(d.v1)+" → "+format(d.v2)+"\n"
+format(d.value);
});
var node = svg.append("g").selectAll(".node")
.data(data_s.nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) {
//return "translate(" + d.x + "," + d.y + ")";
return "translate(" + d.x + "," + d.dy + ")";
})
//////////////////////////////////////////////
// circular sankey nodes
// size is weights of neurons; get min and max and scale between
var node_max = d3.max(data_s.meta, function(d) {return d.size;});
var node_min = d3.min(data_s.meta, function(d) {return d.size;});
console.log("min max " + node_min+" "+node_max);
node.append("circle")
.attr("cx", sankey.nodeWidth()/2)
//.attr("cx", function (d) {return d.x+sankey.nodeWidth()/2;})
//.attr("cy", function (d) { return d.y; })
.attr("cy", 0)
.attr("r", function (d) {
return 10;
})
.style("opacity", 0.6)
.append("title")
.text(function(d) { return d.name + "\n"
+ "Val: "+format(d.value)+ "\n"
+ "L: "+d.layer+ "\n"
+ format(d.y) + "\n"
+ format(d.dy); });
node.append("text")
.attr("x", 8)
.attr("y", 0)
.attr("dy", ".35em")
.attr("text-anchor", "end")
.attr("transform", null)
.attr("font-family", "sans-serif")
.attr("font-size", "16px")
.text(function(d) { if (d.layer == 'softmax' ) { return d.name; }})
.filter(function(d) { return d.x < width / 2; })
.attr("x", 6 + sankey.nodeWidth())
.attr("text-anchor", "start");
}
</script>
</body>
</head>