class Visualizer{ static drawNetwork(ctx,network){ const margin=50; const left=margin; const top=margin; const width=ctx.canvas.width-margin*2; const height=ctx.canvas.height-margin*2; const levelHeight=height/network.levels.length; for(let i=network.levels.length-1;i>=0;i--){ const levelTop=top+ lerp( height-levelHeight, 0, network.levels.length==1 ?0.5 :i/(network.levels.length-1) ); Visualizer.drawLevel(ctx,network.levels[i], left,levelTop, width,levelHeight, i==network.levels.length-1 ?['Up','Left','Right','Down'] :[] ); } } static drawLevel(ctx,level,left,top,width,height,outputLabels){ const right=left+width; const bottom=top+height; const {inputs,outputs,weights,biases}=level; const nodeRadius=14; for(let i=0;i