Published
Edited
Jun 3, 2019
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
InputValues = [phi0, theta0, x99, y99, phi99, theta99, xdot0, ydot0, phidot0, thetadot0]
Insert cell
md `## Graph Plot Setting`
Insert cell
height = 500
Insert cell
width =1000
Insert cell
maxLayer =d3.max(data.nodes, d => d.LayerNum)
Insert cell
maxwt = d3.max(data.links, d => Math.abs(d.weight))
Insert cell
maxnode = d3.max(data.nodes, d => Math.abs(d.value))
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
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], 'valueScaled': 2*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++){
var v = nextLayer[k]
if (l !== NN['weights'].length-1){
v = Math.tanh(nextLayer[k]) // apply activation function
}
var node = {'id': (l+1)*100+k, 'LayerNum': l+1, 'NodeNum': k, 'value': v, 'valueScaled': Math.tanh(nextLayer[k])}
nodes.push(node)
nextLayer[k] = v
}
currentLayer = nextLayer
}
return {"nodes": nodes, "links": links};
}
Insert cell
data = ComputeLayerValues(InputValues)
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