-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
289 lines (240 loc) · 8.14 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
width: 100%;
display: block;
}
.label {
font-weight: bold;
}
.tile, .zoom {
shape-rendering: crispEdges;
}
.zoom {
pointer-events: none;
stroke: #000;
stroke-width:2.5px;
}
#zoom_0 {
stroke: #D62728; <!-- Height -->
}
#zoom_1 {
stroke: #1F77B4; <!-- Potential -->
}
#zoom_2 {
stroke: #FF7F0E; <!-- Phase -->
}
#zoom_3 {
stroke: #2CA02C; <!-- Amplitude -->
}
.cell-hover {
stroke: #F00;
stroke-width:2.5px;
}
.title {
font-size: 14px;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
#inputs {
width: 78%;
float: right;
white-space: nowrap; <!-- keep everything on one line -->
vertical-align: top;
overflow: hidden;
text-align: center;
}
#interactions {
width: 18%;
float: left;
text-align: center;
}
#tree {
width: 59%;
float: left;
text-align: center;
}
#output {
width: 40%;
float: right;
text-align: center;
}
.node circle {
fill: #6D7B8D;
stroke: #6D7B8D;
//fill: #f1f1f1;
//stroke: #f1f1f1;
//stroke-width: 1px;
}
.node text { font: 12px sans-serif; }
.link {
fill: none;
stroke: #ccc;
//stroke-width: 2px; // use tree structure to set tree line width
}
.axis {
font: 10px sans-serif;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
.axis .domain {
fill: none;
stroke: #000;
stroke-opacity: .3;
stroke-width: 10px;
stroke-linecap: round;
}
.axis .halo {
fill: none;
stroke: #ddd;
stroke-width: 8px;
stroke-linecap: round;
}
.slider .handle {
fill: #fff;
stroke: #000;
stroke-opacity: .5;
stroke-width: 1.25px;
cursor: crosshair;
}
</style>
<link rel="stylesheet" href="css/d3.slider.css" />
<link rel="stylesheet" href="css/guiders.css" />
<script type="text/javascript" src="./d3/d3.js"></script>
<script type="text/javascript" src="./scripts/d3.slider.js"></script>
<script type="text/javascript" src="./scripts/d3-scale.v0.7.min.js"></script>
<script type="text/javascript" src="./scripts/tree_styling.js"></script>
<script type="text/javascript" src="./scripts/generate_images.js"></script>
<script type="text/javascript" src="./scripts/generate_tree.js"></script>
<script type="text/javascript" src="./scripts/slider.js"></script>
<script type="text/javascript" src="./scripts/jquery.min.js"></script>
<script type="text/javascript" src="./scripts/guiders.js"></script>
</head>
<body>
<div id="interactions"><h1>Parameters</h1>
Tree Depth<br></br>
<div class="depth_slider"></div>
<br></br>
Number of Trees in Forest<br></br>
<div class="forest_slider"></div>
</div>
<div id="inputs"><h1>Features</h1></div>
<div id="tree"><h1>Tree</h1></div>
<div id="output"><h1>Output: </h1><p class="title">Photoluminescence</p></div>
<script>
// ************** Generate Guiders *****************
guiders.createGuider({
buttons: [{name: "Next"}],
description: "To exit the tutorial hit the escape key. Otherwise hit next!",
id: "first",
next: "second",
overlay:true,
title: "Welcome to the Decision Forests online teaching tutorial!",
closeOnEscape: true,
onClose: guiders.hideAll()
}).show();
guiders.createGuider({
attachTo: inputs,
position: 6,
buttons: [{name: "Next"}],
description: "In this dataset are four atomic force microscopy images of a perovskite solar cell. We use these to predict the spatial mapping of the material’s photoluminescence. As you mouse over the pixels, your cursor highlights where this portion of material maps to the other images. The top portions of these images represent the training data, while the bottom portions are the pixels our learning algorithm will use to make a prediction.",
id: "second",
next: "third",
overlay: true,
highlight: true,
closeOnEscape: true,
title: "Inputs"
});
guiders.createGuider({
attachTo: interactions,
position: 6,
offset: { right: 100 , top: +100},
buttons: [{name: "Next"}],
description: "Random forests learning algorithms have two major parameters a user can specify: tree depth and the number of trees in the forest. Adjust the slide bars to see how they affect the algorithm’s performance.",
id: "third",
next: "fifth",
closeOnEscape: true,
overlay: true,
highlight: true,
title: "Random Forest Parameters"
});
guiders.createGuider({
attachTo: tree,
position: 2,
// offset: { left: -100, top: +200},
buttons: [{name: "Next"}],
description: "Here is one of the trees that are generated from the learning algorithm. In the event that you choose a single tree in the slider bar, that tree is representative of the entire mapping from input features to output! When multiple trees are generated, the prediction is the average of the ensemble of trees.",
id: "fifth",
next: "sixth",
overlay: true,
highlight: true,
closeOnEscape: true,
title: "Tree Structure"
});
guiders.createGuider({
attachTo: output,
position: 10,
// offset: {right: +100, top: +200},
buttons: [{name: "Close"}],
description: "Here are the results of the learning algorithm. As in the ‘features’ images, the top portion of the image represents the training data, while the bottom half of the image is the prediction.",
id: "sixth",
overlay: true,
highlight: true,
closeOnEscape: true,
title: "Predicted Image"
});
// ************** Generate the images *****************
outerWidth_input = (.78/4)*window.innerWidth; // 78% of the screen (div width) / 4 images = 1/5
outerHeight_input = outerWidth_input; // make a square image
outerWidth_output = outerWidth_input; // These have to be the same size still. Need to figure out how to account
outerHeight_output = outerHeight_input; // for different translations of the zoom rects if we want these to be different. - Matt
// Make the input and output images
show_image("data/Height.txt", outerWidth_input, outerHeight_input, "Height", "#inputs");
show_image("data/Potential.txt", outerWidth_input, outerHeight_input, "Potential", "#inputs");
show_image("data/Phase.txt", outerWidth_input, outerHeight_input, "Phase", "#inputs");
show_image("data/Amplitude.txt", outerWidth_input, outerHeight_input, "Amplitude", "#inputs");
show_output("data/Photoluminescence.txt", "python/results/4_depth_5_trees.txt", outerWidth_output, outerHeight_output, "(top:actual, bottom:predicted)", "#output");
show_output("data/Photoluminescence.txt", "data/Photoluminescence.txt", outerWidth_output, outerHeight_output, "(actual)", "#output");
// ************** Generate the default tree diagram *****************
generate_tree("python/results/4_depth_1_trees_1_estimator.json");
// ************** Generate the sliders *****************
depth_slider = d3.slider().scale(d3.scale.ordinal().domain([1,2,3,4,5]).rangePoints([0, 1], 0.5)).axis(d3.svg.axis()).snap(true).value(4);
forest_slider = d3.slider().scale(d3.scale.ordinal().domain([1,2,3,4,5]).rangePoints([0, 1], 0.5)).axis(d3.svg.axis()).snap(true).value(4);
d3.select('.depth_slider').call(depth_slider);
d3.select('.forest_slider').call(forest_slider);
depth_slider.on("slide", function(evt, value) {
update(value);
});
forest_slider.on("slide", function(evt, value) {
update_forest(value);
});
// Value is the value of the slider (i.e. the Tree Depth or # of Trees etc.)
function update(value) {
var dataset = "python/results/" + value + "_depth_" + forest_slider.value() + "_trees.txt";
var tree = value + "_depth_4_trees_1_estimator.json";
console.log(dataset);
update_output("data/Photoluminescence.txt", dataset, outerWidth_output, outerHeight_output, "Photoluminescence", "#output");
generate_tree("python/results/" + tree);
}
function update_forest(value) {
var dataset = "python/results/" + depth_slider.value() + "_depth_" + value + "_trees.txt";
console.log(dataset);
update_output(dataset, dataset, outerWidth_output, outerHeight_output, "Photoluminescence", "#output");
}
// The variable trees_drawn is used to
// determine whether draw_tree is drawing the first
// tree or re-drawing a new one.
// If it is a replacement tree, we want to delete the old one.
var trees_drawn = 1
</script>
</body>
</html>