var script document createElement script script type text javascript script src https cdnjs cloudflare com ajax libs synaptic 1 1 4 synaptic js document head appendChild script document body style height 400pt var script2 document createElement script script2 src https cdn plot ly plotly 2 1 0 min js document head appendChild script2 let cdiv document createElement div document body appendChild cdiv script onload function let graphDiv document createElement div graphDiv id myDiv document body appendChild graphDiv console log synaptic use a pre fab setup var myNetwork new synaptic Architect Perceptron 1 17 17 1 var myNetwork new synaptic Architect LSTM 1 3 3 1 option to convert the activation for a pre fab setup let jj myNetwork toJSON for let kk 0 kk jj neurons length kk jj neurons kk squash RELU myNetwork synaptic Network fromJSON jj or wrap your own var inputLayer new synaptic Layer 1 var hiddenLayer1 new synaptic Layer 17 var hiddenLayer2 new synaptic Layer 17 var outputLayer new synaptic Layer 1 inputLayer set squash synaptic Neuron squash RELU bias 0 hiddenLayer1 set squash synaptic Neuron squash RELU bias 0 hiddenLayer2 set squash synaptic Neuron squash RELU bias 0 outputLayer set squash synaptic Neuron squash RELU bias 0 inputLayer project hiddenLayer1 hiddenLayer1 project hiddenLayer2 hiddenLayer2 project outputLayer var myNetwork new synaptic Network input inputLayer hidden hiddenLayer1 hiddenLayer2 output outputLayer var learningRate 0 01 var iteration 0 var trainer new synaptic Trainer myNetwork function iterate iteration cdiv innerHTML Iteration iteration var trace1 x y type scatter var trace2 x y type scatter var trainingSet for let ii 0 ii 100 ii let input ii 100 0 let output 0 5 Math sin Math PI 2 0 input 0 5 store all the in outs and train trainingSet push input input output output or use an iterative approach let predicted myNetwork activate input myNetwork propagate learningRate output if iteration 50 0 trace1 x push input trace1 y push output trace2 x push input trace2 y push predicted 0 end for trainer train trainingSet rate 0 01 iterations 1 error 005 shuffle true log 10000 cost synaptic Trainer cost CROSS_ENTROPY cost synaptic Trainer cost MSE if iteration 50 0 Plotly newPlot myDiv trace1 trace2 end if end iterate setInterval iterate 2 end onload
new synaptic Network input inputLayer hidden hiddenLayer1 hiddenLayer2 output outputLayer var learningRate 0 01 var iteration 0 var trainer new synaptic Trainer myNetwork function iterate iteration cdiv innerHTML Iteration iteration var trace1 x y type scatter var trace2 x y type scatter var trainingSet for let ii 0 ii 100 ii let input ii 100 0 let output 0 5 Math sin Math PI 2 0 input 0 5 store all the in outs and train trainingSet push input input output output or use an iterative approach let predicted myNetwork activate input myNetwork propagate learningRate output if iteration 50 0 trace1 x push input trace1 y push output trace2 x push input trace2 y push predicted 0 end for trainer train trainingSet rate 0 01 iterations 1 error 005 shuffle true log 10000 cost synaptic Trainer cost CROSS_ENTROPY cost synaptic Trainer cost MSE if iteration 50 0 Plotly newPlot myDiv trace1 trace2 end if end iterate setInterval iterate 2 end onload