Quick Jump / Table of Contents

  1. Network.ts Methods

Networks are a CPU based implementation of a simple feed-forward / back-propagation Neural Network.

Network.ts Methods

network = new Oak.Neural.Network(); network.addLayer(4,2); network.addLayer(1); data = []; return network;

Let's use a common training data set, the XOR task. Our training data is formatted in a way such that [input array, output array]: This is important to know because our Network will expect the first layer to contain a number of input Neurons equal to the input length.

training_data = [ [[0,0],[0]], [[1,0],[1]], [[0,1],[1]], [[1,1],[0]] ]

A more complex dataset can be used here: We use a function to transform the data so that we can more easily map its transformation.,_validation,_and_test_sets

training_data = [] function fn(input){ return (Math.cos(input[0])*Math.sin(input[1])); } for (let i =0; i<=1; i+= 0.1){ for (let z =0; z<=1; z+= 0.1){ training_data.push([[i,z],[fn([i,z])]]); } } return training_data;

We are going to setup a dynamic table so that we can view the values of our network layers.

function train(){ if (epochs <= 0){return} epochs--; network.train(training_data, iterations); data.push({error:network.error}); if (data.length > 3000){ data.shift(); } rolled = (network.layers).map((a,layer)=>{return Object.assign({layer:(layer+1)+"",epochs},Oak.Utils.Object.rollup(a));}); mapped =>{ return Oak.Utils.Object.filterOnKeys(m, ['layer','epochs','bias','error','weights'], {'neurons.':'n.'}); }); Scrap.elements({class:'layers'},(i)=>{ i.innerHTML = ((Oak.Utils.HTML.arrayToTable( mapped, {class:"slim vertical",header:false}))) }); Scrap.elements({class:'net'},(i)=>{ i.innerHTML = Oak.Utils.HTML.arrayToTable([network],{class:"slim"}); }) Scrap.elements({class:'surface'},(i)=>{ surface.fill("#eee"); h = surface.getHeight(); len = surface.getWidth()/data.length; for (i=0; i<data.length-1;i++){ o=data[i]; p=data[i+1]; surface.getContext().beginPath(); surface.getContext().strokeStyle="red"; surface.getContext().moveTo(len*i, h-(o.error*h*0.95)); surface.getContext().lineTo(len*(i+1), h-(p.error*h*0.95)); surface.getContext().stroke(); } }) setTimeout(()=>{ train(); }, 10); } return Scrap.div({class:'net'})+Scrap.div({class:'layers'});
data = []; surface = new Oak.Rendering.Surface(); surface.setSize(960,200); = "100%"; surface.element.classList.add('surface');

Let's train the network for some number of epochs and iterations, in this starting case, 25 epochs consisting of 1,000 iterations each. Just below we will see a graph of the Networks error rate.

Scrap.print(surface.getElement()); epochs = 25 iterations = 1000; return train();

Let's tell the network to begin training.

We can view the sum of the errors for all the layers:

error = [] setInterval(()=>{ training_data.forEach((set,i)=>{ let input = set[0]; let expected = set[1]; let guess = Math.min(1,Math.max(0,network.process(input)[0])); let difference = Math.abs(expected - guess); let pass_fail = difference<0.05?'pass':'fail'; // 5% threshold error.unshift({input,expected,guess,difference:Math.floor(difference*100)+'%', pass_fail}); //error.push(print(`Training example ${i+1}: Expected ${expected}, got ${guess}, difference: ${Math.floor(difference*100)}%, ${pass_fail}`)); }); error = error.slice(0,20); Scrap.elements({class:'test'},(i)=>{ i.innerHTML = Oak.Utils.HTML.arrayToTable(error,{class:"slim"}); }) }, 250); return Scrap.div({class:'net'})+Scrap.div({class:'test'});
test = [1,1]; return Math.round(network.process(test)[0]);

All Pages in Oak Studio Documentation

    Oak Studio Documentation

    Simple to Embed and Integrate We designed OakFrame to be easy to extend in order to provide further integration...


    let graph_container = document.createElement("div"); = "graph-render-area";...


    Networks are a CPU based implementation of a simple feed-forward / back-propagation Neural Network. Network.ts...


    Cameras are a way to transformations when rendering images to a surface. It relies on the Projection class to...


    A SHIPP (Shift Pattern Properties) is a wrapper around 2-dimensional arrays so that they may be used in cases such...


    RoomObjects are entities that exist within a Room. They generally share behaviors with clones of themselves or...


    Sprites are used for loading images into the javascript context. Because animated GIFs are not native to javascript...


    Vec3 ( Vector3 ) is a scalar of 3 dimensions, x, y, and z. vec3 = new Oak.Math.Vec3(); return vec3; Vec3 Methods...


    Surfaces are an abstracted way to use the 2d context from within a single interface. Surfaces provide the...

Explore OakFrame

    Basic Programing with Javascript

    Welcome to the OakFrame Interactive Basic Programming with Javascript course. This course is provided through an...


    Play games in your browser for free, handcrafted by us here at OakFrame!

    Oak Studio Documentation

    Simple to Embed and Integrate We designed OakFrame to be easy to extend in order to provide further integration...

    Design Systems

    A complete, reliable, flexible, and cost-effective infrastructure is a fundamental requirement in modern companies....

    About OakFrame

    OakFrame is a design, development, and research firm located in Dallas, Texas, developing experiences for audiences...