Notebook - Welcome to Notebook

Contact/Report Bugs
You can contact me at: bkenwright@xbdev.net












Tensorflow JS About Simple tensorflowjs example Teach Neural Network to Play a Sound script src https cdn jsdelivr net npm tensorflow tfjs 0 11 2 script script src https cdnjs cloudflare com ajax libs plotly js 1 20 0 plotly min js script script A console assert which actually stop the exectution default console assert is a plain display such as console log or console error It doesnt stop the execution like assert is meant to do This is a little code to workaround this limitation Note you can fix asserts to cause a stop for Chrome set options but this is a general solution workaround in code console assert function cond text dontThrow if cond return if dontThrow debugger else throw new Error text Assertion failed script br br button onclick getData Start button Load Training Sound hello mp3 and Start Training Neural Network br br button onclick playOriginalSound Play Original Sound button button onclick playTrainedSound Play Trained Sound button br br Number of training iterations br div id counter Iteration div Error between ideal and trained version div id error Error div br br div id plot1 style width 90 height 250px div div id plot2 style width 90 height 250px div script let audioCtx null let sndData null let sndTrainedData null let iteration 0 function getData if window webkitAudioContext audioCtx new window webkitAudioContext else audioCtx new window AudioContext source audioCtx createBufferSource request new XMLHttpRequest request open GET https notebook xbdev net var resources hello3 mp3 true request responseType arraybuffer request onload function let audioData request response audioCtx decodeAudioData audioData function buffer sndData buffer console log num channels buffer numberOfChannels let data sndData getChannelData 0 get data console log length of data samples data length create neural network sound buffer const bufferSize data length sndTrainedData audioCtx createBuffer 1 bufferSize audioCtx sampleRate start training the neural network iterate setInterval iterate 1 startWorker function e Error with decoding audio data e error request send function playSoundData sdata var source audioCtx createBufferSource set the buffer in the AudioBufferSourceNode source buffer sdata connect the AudioBufferSourceNode to the destination so you can hear the sound source connect audioCtx destination start the source playing source start function getAmplitude dataBuffer t let dataArray dataBuffer getChannelData 0 get data return dataArray t function toBinary num let v 0 if num 0 v num toString 2 while v length 8 v 0 v convert char to int let arr for let i 0 i v length i arr push parseFloat v i return arr function playOriginalSound playSoundData sndData function playTrainedSound preview let noSamples sndTrainedData getChannelData 0 length let bdata sndTrainedData getChannelData 0 for let tt 0 tt noSamples tt 1 let amp perceptron activate tt noSamples let amp perceptron activate toBinary tt let out model predict tf tensor2d tt noSamples 1 1 let amp out dataSync let val amp 0 2 0 1 0 console assert val 1 val 1 bdata tt val playSoundData sndTrainedData var din var dout iteration starts once the data has been loaded async function iterate iteration if din undefined let noSamples sndData getChannelData 0 length console log setup training data var ii var oo for let tt 0 tt noSamples tt 1 learning rate A traditional default value for the learning rate is 0 1 or 0 01 and this may represent a good starting point on your problem An alternative to using a fixed learning rate is to instead vary the learning rate over the training process Simplest learning rate schedule is to decrease the learning rate linearly from a large initial value to a small value let dynamicRate 1 0 100 0 1 iteration add small bit of randomness to jiggle the search let dynamicRate 1 0 10 0 1 iteration Math random 0 1 let dynamicRate 01 1 00005 iteration let dynamicRate 0 3 0 3 0 01 iteration let amp getAmplitude sndData tt 1 to 1 let ampNormalized amp 1 0 0 5 0 to 1 let val perceptron activate tt noSamples let val perceptron activate toBinary tts console assert val 0 0 console assert val 0 1 ii push tt noSamples oo push ampNormalized perceptron propagate dynamicRate ampNormalized totalError totalError Math abs val 0 ampNormalized din tf tensor2d ii ii length 1 dout tf tensor2d oo oo length 1 await model fit dataset take 100 epochs 1 minimum workign example mwe ref https github com tensorflow tfjs issues 448 await model fit din dout batchSize 100 epochs 100 await model fit din dout epochs 1 let elem1 document getElementById counter elem1 innerHTML Iteration iteration let elem2 document getElementById error elem2 innerHTML Error totalError document title it iteration if iteration 10 0 only update graph every 5 iterations plotSounds requestAnimationFrame iterate function plotSounds plot trained data let noSamples sndTrainedData getChannelData 0 length let x let y for let tt 0 tt noSamples tt 1 let amp perceptron activate toBinary tt let out model predict tf tensor2d tt noSamples 1 1 let amp out dataSync let val amp 0 2 0 1 0 x push tt y push val let plot1 document getElementById plot1 Plotly newPlot plot1 x y margin t 0 showSendToCloud true plot original data let noSamples sndData getChannelData 0 length let bdata sndData getChannelData 0 let x let y for let tt 0 tt noSamples tt 1 let val bdata tt x push tt y push val let plot2 document getElementById plot2 Plotly newPlot plot2 x y margin t 0 showSendToCloud true deep neural network 8 time time index for input 15 15 hidden layers 1 amplitude var perceptron new synaptic Architect Perceptron 8 5 5 5 5 5 5 1 const model tf sequential const model tf sequential layers tf layers dense inputShape 784 units 32 activation relu tf layers dense units 10 activation softmax ref https js tensorflow org api 0 11 6 activation elu hardSigmoid linear relu relu6 selu sigmoid softmax softplus softsign tanh string ref https www tensorflow org js guide models and layers first layer in the model needs an inputShape input layer model add tf layers dense units 1 inputShape 1 hidden layers model add tf layers dense units 30 activation selu model add tf layers dense units 30 activation selu model add tf layers dense units 10 activation selu model add tf layers dense units 10 activation selu output layer model add tf layers dense units 1 model compile loss meanSquaredError optimizer sgd const LEARNING RATE 0 001 const optimizer tf train adam LEARNING RATE const optimizer tf train adam model compile optimizer optimizer optimizer sgd loss categoricalCrossentropy ref https js tensorflow org api latest Training Losses loss meanSquaredError metrics accuracy const LEARNING RATE 0 001 model compile optimizer tf train sgd LEARNING RATE loss meanSquaredError ref https jsfiddle net wagenaartje 1p6q0gw2 2 ref https github com cazala synaptic wiki Neurons Test with custom TANH Neuron squash TANH 2 function x derivate if derivate return 1 Math pow Math tanh x 2 return Math tanh x var network new Architect Perceptron 2 3 1 network setOptimize false var neurons network neurons for var i 0 i neurons length i neurons i neuron squash Neuron squash TANH 2 console log ready script

tial value to a small value let dynamicRate 1 0 100 0 1 iteration add small bit of randomness to jiggle the search let dynamicRate 1 0 10 0 1 iteration Math random 0 1 let dynamicRate 01 1 00005 iteration let dynamicRate 0 3 0 3 0 01 iteration let amp getAmplitude sndData tt 1 to 1 let ampNormalized amp 1 0 0 5 0 to 1 let val perceptron activate tt noSamples let val perceptron activate toBinary tts console assert val 0 0 console assert val 0 1 ii push tt noSamples oo push ampNormalized perceptron propagate dynamicRate ampNormalized totalError totalError Math abs val 0 ampNormalized din tf tensor2d ii ii length 1 dout tf tensor2d oo oo length 1 await model fit dataset take 100 epochs 1 minimum workign example mwe ref https github com tensorflow tfjs issues 448 await model fit din dout batchSize 100 epochs 100 await model fit din dout epochs 1 let elem1 document getElementById counter elem1 innerHTML Iteration iteration let elem2 document getElementById error elem2 innerHTML Error totalError document title it iteration if iteration 10 0 only update graph every 5 iterations plotSounds requestAnimationFrame iterate function plotSounds plot trained data let noSamples sndTrainedData getChannelData 0 length let x let y for let tt 0 tt noSamples tt 1 let amp perceptron activate toBinary tt let out model predict tf tensor2d tt noSamples 1 1 let amp out dataSync let val amp 0 2 0 1 0 x push tt y push val let plot1 document getElementById plot1 Plotly newPlot plot1 x y margin t 0 showSendToCloud true plot original data let noSamples sndData getChannelData 0 length let bdata sndData getChannelData 0 let x let y for let tt 0 tt noSamples tt 1 let val bdata tt x push tt y push val let plot2 document getElementById plot2 Plotly newPlot plot2 x y margin t 0 showSendToCloud true deep neural network 8 time time index for input 15 15 hidden layers 1 amplitude var perceptron new synaptic Architect Perceptron 8 5 5 5 5 5 5 1 const model tf sequential const model tf sequential layers tf layers dense inputShape 784 units 32 activation relu tf layers dense units 10 activation softmax ref https js tensorflow org api 0 11 6 activation elu hardSigmoid linear relu relu6 selu sigmoid softmax softplus softsign tanh string ref https www tensorflow org js guide models and layers first layer in the model needs an inputShape input layer model add tf layers dense units 1 inputShape 1 hidden layers model add tf layers dense units 30 activation selu model add tf layers dense units 30 activation selu model add tf layers dense units 10 activation selu model add tf layers dense units 10 activation selu output layer model add tf layers dense units 1 model compile loss meanSquaredError optimizer sgd const LEARNING RATE 0 001 const optimizer tf train adam LEARNING RATE const optimizer tf train adam model compile optimizer optimizer optimizer sgd loss categoricalCrossentropy ref https js tensorflow org api latest Training Losses loss meanSquaredError metrics accuracy const LEARNING RATE 0 001 model compile optimizer tf train sgd LEARNING RATE loss meanSquaredError ref https jsfiddle net wagenaartje 1p6q0gw2 2 ref https github com cazala synaptic wiki Neurons Test with custom TANH Neuron squash TANH 2 function x derivate if derivate return 1 Math pow Math tanh x 2 return Math tanh x var network new Architect Perceptron 2 3 1 network setOptimize false var neurons network neurons for var i 0 i neurons length i neurons i neuron squash Neuron squash TANH 2 console log ready script

3dplot
a4print
about
acejs
acejs2
acejs3
aessecurity
angularjs
animbackgroundimage
aseformat
assert
asteroidsjs
backgrounds01
backgrounds02
backgrounds03
barnsleyfern
base26
base64
bib
binary
bodypix
bouncy
box2dweb
breakoutjs
browserversion
buslanes
busybutton
bvhreader
calendar
canvas
canvas2
canvas3
canvasmandelbrot
canvasmandelbrot2
canvasnumbers
canvaszoom
capsule
changingimages
chatgptusingopenai
chatgptusingopenai2
chatgptusingopenai3
checkboxtoggle
chinesetiles
classes
classfeatures
clipboardbutton
clonenode
codedropdown
codemirror
codemirror2
collada
colorpick
columnresizer
contextmenu
convnet
cookiebanner
countdown
countdown2
countdown3
crop
css3dbarchart
css3dbarchart2
css3dbook
css3dscene
csscube
csscube2
csscube3
csscubevideos
cssfilelist
csshas
csspulse
cssresizeaspect
cssspin
csszooming
csvtoarray
customcheckbox
d3datamap
d3js
d3js10
d3js11
d3js2
d3js3
d3js4
d3js5
d3js6
d3js7
d3js8
d3js9
d3jsanimatedgrid
d3jsarctransition
d3jsarctransition2
d3jsaxis
d3jsaxischanging
d3jsbars
d3jsbrushing
d3jsbuslanes
d3jsbuslanes2
d3jscalendar
d3jscheat
d3jsclock
d3jscloudmap
d3jscogs
d3jscolors
d3jscovid
d3jscovid2
d3jscovid3
d3jsdashboard
d3jsdashboard2
d3jsdashboard3
d3jsdatakeyfunction
d3jsdensity
d3jsdragresizing
d3jsdragresizing2
d3jseach
d3jsease
d3jsevents
d3jsflower
d3jsforcegroups
d3jsforces
d3jsforces2
d3jsfractaltree
d3jsgeo
d3jsgroupbars
d3jsgroups
d3jsheatmap
d3jshex
d3jshierarchies
d3jshierarchies2
d3jshistogram
d3jshistogram2
d3jshistogram3
d3jshistogram4
d3jsinterpolate
d3jsjoin
d3jskmean
d3jskmean2
d3jsline
d3jsline2
d3jsline3
d3jsline4
d3jslinetransition
d3jslinetransition0
d3jslinetransition2
d3jsmaplocations
d3jsmaps
d3jsmaps2
d3jsmaps3
d3jsmisc
d3jsmisc2
d3jsmodule
d3jsmodulecolor
d3jsmultistyles
d3jsnobel
d3jsoverlappinggraphs
d3jspanel
d3jspie
d3jspieinterpolate
d3jssankey
d3jssankey2
d3jsscatter
d3jsshapes
d3jsslider
d3jsspending
d3jsspending2
d3jsspiralplot
d3jsspirograph
d3jssquare
d3jsstack
d3jsstackedbar
d3jsstackedbar2
d3jssunburst
d3jssunmoon
d3jssvglines
d3jssymbols
d3jstimelines
d3jsuk
d3jsvoronoi
d3scatterplot
d3timeline
d3timeline2
datalist
datamuse
date
dblclickhighlight
deviceorientation
dictionaryapi
dockermenu
doodlepad
downloadgif
dragdroplistitems
dragrotateresizediv
dragrotateresizediv2
dragrotateresizediv3
dragrotateresizediv4
dragrotateresizefontsize
dragselectbrush
drawlinesdiv
dropdown
dualquaternionimages
dynamicgrid
easefunctions
easeinterpolate3dplots
echart
echart2
echart3
encapsulation
epubviewer
errorstack
excalidraw
excalidraw2
excalidraw3
excalidraw5
expandable
faker
fetchplus
fileupload
fixedtopbar
fonts
fonts2
footerbar
fractalmaze
fractalmaze2
fractalnoiseimage
fractals
fractals2
fractaltree
freesvg
fresnel
froggerjs
gantt
gifgiphyapi
gifhex
gltffromscratch
gradients
griditems
griditems2
griditems3
griditems4
gridworms
heat
hexview
hexview2
highlight
icons
icons2
iframes
ik
imagetracertosvg
imgur
inputfile
invadersjs
ipynb
ipynb2
ipynb3
ipynb4
isbn13
isbn2
jpghex
jquery
jquery2
jqueryui
jqueryui2
jsdraganddrop
jslint
jsobfuscate
jsraytracer
jstree
jstree2
jszip
jszipimages
jszipread
keyframes
l2dwidget
lda
leftmenu
less
less2
lineargradientimage
linenumbers
loadimagefromfile
makepdf
maps
markdown
markdown2
markdownalerts
markdownalerts2
markdownbookmarks
markovimage
markovpixelblocks
mathjax
matrices
matsandvects
mazegamejs
md2tex
metrotiles
metrowindows
milestones
misc
misc2
modules
myipdetails
neataptic
networkstructures
networkstructures2
number
obj
objtojson
openaiimages
opencv
opencv2
opencv3
opencv4
opencv5
outline
p2
p5fractalleaf
p5fractalshape
p5js
p5js2
p5js3
p5jsanimatedcover
p5mengercube
p5snowflakes
palindrome
panel
parallax
paste
paste2
pasteimgfromurl
pdfjs
pdfjs2
pdfkit
pdfkit2
pdfkit3
pdfkit4
pdfkit5
pdfkit6
pdfmake
pdfmake2
pdfmake3
pdfmake4
pdfmake5
pdfmake6
perlin
perlin2
perlin3
perspective
pexels
playground
plotly
plotlynoise
plotlyranddist
plyloader
plyloader2
pngtxtencoder
pongjs
pptxgenjs
prettycode
prism
prn
problems
progress
pseudorandom
px2svg
python
quotes
racergame
random
randomprofilepatterns
randomstring
rating
rayambient
raymonte
raymonteprogressive
raymonteprogressive2
raymontewarmstart
reexpcross
reexpcross2
regex
regexbib
regexpfixbib
regexpmultiline
repeatwordsregexp
resizabletable
resizabletable2
revealjs
revealjs2
revealjsmulti
ritalanguage
ritalanguage2
ritalanguage3
rotateimg
rough
rsapublicprivatekeys
rss
rss2
sankey
scrappingsvg
scrolltext
scrolltext2
scrollwidth
sdfboxinboxtwist
sdfhollowbox
setintervalexception
shareurl
shuffle
sidecomment
similarity
simplehighlighter
simpleplatformgamejs
sinecanvas
sliderpopout
slides
smileys
snowfall
snowman
sound
soundsignal
sphererayintersection
springs
sqljs
steganography
stereogram
stringmatching
svg
svgchaos
svgdragresize
svgdragresize2
svgdragresize3
svgdragrotate
svgdrawing
svglines
svglines2
svglines3
svglines4
svglines5
svglinesmandelbrot
svgpathsdragrotate
svgpathsdragrotateresize
svgpie
svgpie2
svgpie3
svgpiepath
svgpiepath2
svgrandomfaces
symbols
synaptic
synaptic2
synonyms
tablerotatecells
tablerotatecells2
tablerotatecells3
tablerotatecells3b
tablerotatecells4
tables
tablezebra
tabularjs
tabularjs2
tabulatordownload
tagcanvas
tensorflowgan
tensorflowjs
tensorflowjsbasic
tensorflowjscnn
tensorflowjssinewave
tensorflowjssound
tensorflowmobilenet
tetrahedronfractal
tetrahedronfractalfolding
tetris
textarea
textareaauto
textareadiv
textareadiv2
textmaskimage
theirorthere
thesaurus
threejs
threejs2
threejs3
threejs4
threejsgltf
threejstokyo
tiles
toaster
tooltip
transition
transitionexpandabledropdown
treeview
treeview2
tricks
tshirt
tshirt2
tshirt3
turningpages
unsplash
urlblob
urlblob2
userdefinepoints
vector
videos
videos2
visualsort
vue
w2ui
w2uientertextdialog
webcam
webgl
webgl2
webgl3
webgl4
webgl5
webglbasic1
webglbasic2
webglcube
webglfov
webglfrustum
webgljson
webglleaves
webgllighting
webglorthographic
webglpoints1
webglpoints2
webglpoints3
webglsquare
webgltexture1
webgltexture2
webgltexture3
webgltransforms
webgltriangle
webgpu
webgpu10
webgpu11
webgpu12
webgpu13
webgpu14
webgpu15
webgpu16
webgpu17
webgpu2
webgpu3
webgpu4
webgpu5
webgpu6
webgpu7
webgpu8
webgpu9
webgpubars
webgpubuffers
webgpubuffers2
webgpucellnoise
webgpuclouds
webgpuclydescope
webgpucompute
webgpucubemap
webgpucubemap2
webgpudeferred
webgpudepth
webgpudof
webgpudrops
webgpuetha
webgpufire
webgpufractalcubes
webgpuglassrain
webgpugltf
webgpugltf2
webgpugrass
webgpugrid
webgpukernel
webgpukleinian
webgpulabupdates
webgpulighting
webgpumandelbrot
webgpumeta3d
webgpumetaballs
webgpumouse
webgpunoise
webgpunormalmapping
webgpuobj
webgpuparallax
webgpuparallax2
webgpuparallax3
webgpuparallaxshadow
webgpuparallaxshadow2
webgpupixel
webgpuquad
webgpuray1
webgpuraytracing
webgpuraytracing2
webgpushadowmaps
webgpushadowmaps2
webgpusierpinski2d
webgpusierpinski3d
webgpusinusoid
webgpussao
webgpustadiumobj
webgpuswirl
webgputestpipe3
webgputoon
webgputopology
webgputt
webgpuvolcloud
webgpuwater
webgpuwireframe
webgpuwireframe2
webpcanvas
webworkers
webxr
webxr2
wiggly
wikipedia