summaryrefslogtreecommitdiff
path: root/code/weightviswrapper.js
diff options
context:
space:
mode:
Diffstat (limited to 'code/weightviswrapper.js')
-rw-r--r--code/weightviswrapper.js45
1 files changed, 37 insertions, 8 deletions
diff --git a/code/weightviswrapper.js b/code/weightviswrapper.js
index 1b3a91a..22bbe63 100644
--- a/code/weightviswrapper.js
+++ b/code/weightviswrapper.js
@@ -7,6 +7,7 @@ var WeightVisWrapper = (function() {
this.container = d3.select("body").append("div").remove();
this.svgContainer = this.container.append("div");
this.controlContainer = this.container.append("div");
+ this.controlBarAttached = false;
this.svg = this.svgContainer.append("svg");
this.netVisualizer = new NetVisualizer(this.svg);
this.resizeHooks = [];
@@ -62,7 +63,7 @@ var WeightVisWrapper = (function() {
WeightVisWrapper.prototype.mock = function(shape, callback) {
var self = this;
- this.controlContainer.style("display", "none");
+ this.hideControlBar;
this.netVisualizer.mock(shape, function() { self.loaded(callback); });
};
@@ -94,8 +95,8 @@ var WeightVisWrapper = (function() {
self.slider.node().MaterialSlider.change(0); // wrap at right end
}
});
- this.slider.attr("max", this.netVisualizer.getSteps() - 1);
- this.slider.node().addEventListener("input", function() { self.netVisualizer.showStep(self.value); });
+ this.slider.attr("max", this.steps()-1);
+ this.slider.node().addEventListener("input", function() { self.jumpTo(self.value); });
this.button.node().addEventListener("click", function toggle() {
if (self.button.attr("data-pressed") != "true") {
var step = self.slider.node().value;
@@ -139,15 +140,22 @@ var WeightVisWrapper = (function() {
el.appendChild(this.spinner.node().cloneNode(true));
};
- WeightVisWrapper.prototype.openIn = function(el) {
+ WeightVisWrapper.prototype.openIn = function(el, withControlbar) {
d3.select(el).select(".spinner").remove();
el.appendChild(this.svgContainer.node());
- el.appendChild(this.controlContainer.node());
+ if (withControlbar) {
+ el.appendChild(this.controlContainer.node());
+ this.controlBarAttached = true;
+ } else {
+ this.controlBarAttached = false;
+ }
this.reposition();
};
WeightVisWrapper.prototype.remove = function(el) {
- this.svgContainer.node().parentNode.removeChild(this.controlContainer.node());
+ if (this.controlBarAttached) {
+ this.svgContainer.node().parentNode.removeChild(this.controlContainer.node());
+ }
this.svgContainer.node().parentNode.appendChild(this.spinner.node().cloneNode(true));
this.svgContainer.node().parentNode.removeChild(this.svgContainer.node());
this.netVisualizer.stopAnimation();
@@ -169,9 +177,30 @@ var WeightVisWrapper = (function() {
this.button.select(".pause").style("display", "");
};
+ WeightVisWrapper.prototype.jumpTo = function(step) {
+ this.netVisualizer.showStep(step);
+ };
+
+ WeightVisWrapper.prototype.steps = function() {
+ return this.netVisualizer.getSteps();
+ };
+
+ WeightVisWrapper.prototype.calculate = function(inputs) {
+ // returns the final layer's outputs
+ return this.netVisualizer.activate(inputs).pop();
+ };
+
WeightVisWrapper.prototype.activate = function(inputs) {
- // TODO visualize this :)
- return this.netVisualizer.activate(inputs);
+ // TODO this should be in weightvis.js
+ // …this is rather a hack, I got lazy…
+ var activations = this.netVisualizer.activate(inputs);
+ var flatActivations = [].concat.apply([], activations);
+ var max = d3.max(flatActivations, Math.abs),
+ min = d3.min(flatActivations, Math.abs);
+ var node = this.svg.selectAll(".node");
+ node
+ .attr("r", function(d) { return 2 * d.r * (Math.abs(activations[d.layer][d.node]) - min) / (max-min); })
+ .style("fill", function(d) { return activations[d.layer][d.node]>0?nodeColor:nodeColorAlt; });
};
return WeightVisWrapper;