diff options
Diffstat (limited to 'code/weightvis.js')
| -rw-r--r-- | code/weightvis.js | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/code/weightvis.js b/code/weightvis.js index 64d398c..e3cec42 100644 --- a/code/weightvis.js +++ b/code/weightvis.js @@ -33,9 +33,9 @@ var nodeHighlightColor = accentColor ; - /* network construction */ +// TODO make multiple bias layers at positions > 0 possible? var Network = (function() { function Network(layout) { this.layout = layout; @@ -499,9 +499,35 @@ var NetVisualizer = (function() { me.attr("data-highlight", "true"); } }); - this.reposition(); }; + NetVisualizer.prototype.activate = function(inputs) { + // assumes the sigmoid function is used as activation + function activation(x) { return 0.5 + x / Math.sqrt(1 + 4 * x * x); } + var weights = this.data[this.layout.data.batches-1][this.layout.data.epochs-1]; + var lastLayerOut = inputs; + var hasBias = false; + if (this.layout.net[0].isBias) { + for (bias=0; bias<inputs.length; bias++) { + lastLayerOut[bias] += weights[0][0][bias]; + } + hasBias = true; + } + for (layer=hasBias?1:0; layer<this.layout.net.layers-1; layer++) { + // manual vector matrix multiplication + var thisLayerOut = []; + for (tar=0; tar<this.layout.net[layer+1].size; tar++) { + thisLayerOut[tar] = 0; + for (src=0; src<this.layout.net[layer].size; src++) { + thisLayerOut[tar] += weights[layer][src][tar] * lastLayerOut[src]; + } + thisLayerOut[tar] = activation(thisLayerOut[tar]); + } + lastLayerOut = thisLayerOut; + } + return lastLayerOut; + }; + return NetVisualizer; })(); |
