Published
Edited
Jun 2, 2019
1 fork
Insert cell
Insert cell
Insert cell
viewof timeButtonsNaive = {
const wtbar = html`<input type="range" id="wtbar" min="0" max = "10" value = "0" step="0.01">`;
const wtcut = html`<span>0</span>`;
wtbar.oninput = () => {
wtcut.innerHTML = wtbar.value;
d3.selectAll("line").attr("stroke-width", d => Math.abs(d.weight)>wtbar.value? Math.abs(d.weight)*2 : 0);
}
const view = html`
<div style="text-align: center; font-family: sans-serif">
Weight Cut-off = ${wtcut}
${wtbar}
</br>
</div>
`
return view;
}
Insert cell
md `## Graph Plot Setting`
Insert cell
height = 800
Insert cell
width =1000
Insert cell
maxLayer = 5
Insert cell
color = {
const scale = d3.scaleOrdinal(d3.schemeCategory10);
return d => scale(d.LayerNum);
}
Insert cell
drag = simulation => {
function dragstarted(d) {
if (!d3.event.active) simulation.alphaTarget(3).restart();
d.fx = d.x;
d.fy = d.y;
}
function dragged(d) {
d.fx = d3.event.x;
d.fy = d3.event.y;
}
function dragended(d) {
if (!d3.event.active) simulation.alphaTarget(0);
d.fx = null;
d.fy = null;
}
return d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
Insert cell
d3 = require("d3@5")
Insert cell
import {number} from "@jashkenas/inputs"
Insert cell
import {slider} from "@jashkenas/inputs"
Insert cell
viewof phi0= slider({
min: 0,
max: 100,
step: 1,
title: "phi0",
description: "input for phi0"
})
Insert cell
md `## Graph Generation`
Insert cell
NN = d3.json("https://raw.githubusercontent.com/cse512-19s/FP-Visualizing-neural-network-architecture/master/docs/FeedforwardNN.json?token=AHF5OJCHONQA7OTERXNXTCK47VYOQ")
Insert cell
function ComputeLayerValues(input){
var nodes = [];
var links = [];
for (let i=0; i<NN['weights'][0].length; i++){
var node = {'id': i, 'LayerNum': 0, 'NodeNum': i, 'value': input[i]}
nodes.push(node)
}
var currentLayer = input
for (let l=0; l<NN['weights'].length; l++){
var weight = NN['weights'][l]
var bias = NN['bias'][l]
var nextLayer = bias
for (let i=0; i<weight.length; i++){
for (let j=0; j<weight[i].length; j++){
nextLayer[j] += weight[i][j]*currentLayer[i]
var link = {'source': l*100+i, 'target': (l+1)*100+j, 'weight': weight[i][j]}
links.push(link)
}
}
for (let k=0; k<nextLayer.length; k++){
if (l !== NN['weights'].length-1){
nextLayer[k] = Math.tanh(nextLayer[k]) // apply activation function
}
var node = {'id': (l+1)*100+k, 'LayerNum': l+1, 'NodeNum': k, 'value': nextLayer[k]}
nodes.push(node)
}
currentLayer = nextLayer
}
return {"nodes": nodes, "links": links};
}
Insert cell
input = [1,1,1,1,1,1,1,1,1,1]
Insert cell
data = ComputeLayerValues(input)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more