Skip to content

Instantly share code, notes, and snippets.

@torgeir
Created June 4, 2020 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torgeir/87fd1867cfb153379ccc4d8657149ab2 to your computer and use it in GitHub Desktop.
Save torgeir/87fd1867cfb153379ccc4d8657149ab2 to your computer and use it in GitHub Desktop.
Forecasting til elise notes with brain js, rendered example from https://github.com/torgeir/brainjs/blob/master/solutions/forecasting-til-elise.js
function anonymous(rawInput
) {
var input = rawInput;
var json = {"type":"LSTMTimeStep","options":{"inputSize":1,"hiddenLayers":[10,10],"outputSize":1,"decayRate":0.999,"smoothEps":1e-8,"regc":0.000001,"clipval":5},"hiddenLayers":[{"inputMatrix":{"rows":10,"columns":1,"weights":{"0":-0.14291851222515106,"1":0.3453339636325836,"2":0.2586001455783844,"3":-0.549615740776062,"4":0.3691498339176178,"5":0.3826494812965393,"6":-0.04879533872008324,"7":-0.037501029670238495,"8":-0.28100821375846863,"9":-0.3269386887550354}},"inputHidden":{"rows":10,"columns":10,"weights":{"0":3.026973009109497,"1":0.15415456891059875,"2":0.9622602462768555,"3":-0.043676845729351044,"4":-0.48500069975852966,"5":0.7144996523857117,"6":-0.5628131628036499,"7":1.1538690328598022,"8":-0.2921547293663025,"9":-0.02194361761212349,"10":-0.0001882951328298077,"11":0.02291523851454258,"12":0.07765365391969681,"13":0.04838552698493004,"14":-0.04904717579483986,"15":0.11924855411052704,"16":0.008335016667842865,"17":0.041437916457653046,"18":-0.13594819605350494,"19":0.04255189746618271,"20":-7.509152412414551,"21":0.06323446333408356,"22":-5.741835594177246,"23":0.027230393141508102,"24":9.871660232543945,"25":-1.2242465019226074,"26":9.04193115234375,"27":-16.537025451660156,"28":-0.12475945055484772,"29":-0.05209086090326309,"30":-0.19701246917247772,"31":0.23503947257995605,"32":-0.028694475069642067,"33":0.0771239697933197,"34":0.04762040823698044,"35":0.20223645865917206,"36":0.12413178384304047,"37":-0.005035380832850933,"38":-0.24982833862304688,"39":-0.034789059311151505,"40":-0.06403738260269165,"41":-0.022489452734589577,"42":-0.022977109998464584,"43":0.021744128316640854,"44":0.7954774498939514,"45":-0.006490790285170078,"46":-0.9457204937934875,"47":3.227797031402588,"48":-0.10166874527931213,"49":-0.034454621374607086,"50":0.06483910232782364,"51":0.016141265630722046,"52":0.024015720933675766,"53":-0.03853440284729004,"54":0.006772959604859352,"55":0.16040559113025665,"56":0.03878718242049217,"57":-0.03942185267806053,"58":-0.15917575359344482,"59":-0.03343937546014786,"60":-0.19152997434139252,"61":0.06245407089591026,"62":0.5214702486991882,"63":-0.05977758765220642,"64":-0.2836506962776184,"65":5.023475170135498,"66":-1.3711457252502441,"67":-2.206634283065796,"68":-0.046106815338134766,"69":-0.03780900686979294,"70":3.837799072265625,"71":0.3085331618785858,"72":1.6849132776260376,"73":0.021602774038910866,"74":0.18166378140449524,"75":12.085467338562012,"76":1.3430873155593872,"77":0.251433402299881,"78":-0.35666126012802124,"79":-0.1410059630870819,"80":0.02947958931326866,"81":-0.32302403450012207,"82":-0.23491458594799042,"83":-0.061980754137039185,"84":0.07771101593971252,"85":-0.31456032395362854,"86":-0.027483278885483742,"87":-0.21750329434871674,"88":0.2861253321170807,"89":0.11797912418842316,"90":-0.04971760883927345,"91":-0.24393877387046814,"92":-0.22343109548091888,"93":-0.08411326259374619,"94":0.07461365312337875,"95":-0.3380984663963318,"96":0.0031075000297278166,"97":-0.21300342679023743,"98":0.2474278211593628,"99":0.00536653958261013}},"inputBias":{"rows":10,"columns":1,"weights":{"0":6.67863655090332,"1":0.017536398023366928,"2":3.4902031421661377,"3":-0.15805299580097198,"4":1.6499403715133667,"5":0.11012221872806549,"6":2.3686413764953613,"7":1.3984676599502563,"8":-0.2849871516227722,"9":-0.2536981701850891}},"forgetMatrix":{"rows":10,"columns":1,"weights":{"0":-0.023770717903971672,"1":0.34050172567367554,"2":0.3896588683128357,"3":0.3123387098312378,"4":0.4733860492706299,"5":-0.11748165637254715,"6":0.02833583764731884,"7":0.44745469093322754,"8":-0.21871909499168396,"9":-0.2772855758666992}},"forgetHidden":{"rows":10,"columns":10,"weights":{"0":2.4738714694976807,"1":0.013109167106449604,"2":-1.4014054536819458,"3":0.048731353133916855,"4":-1.0016365051269531,"5":3.1409475803375244,"6":-0.9879004955291748,"7":2.0435283184051514,"8":-0.08070995658636093,"9":-0.04554562270641327,"10":-0.00987499114125967,"11":0.06478653848171234,"12":0.050751663744449615,"13":-0.011014668270945549,"14":-0.020538337528705597,"15":0.07510066777467728,"16":-0.03464117646217346,"17":-0.03368473798036575,"18":-0.027702875435352325,"19":-0.03563884645700455,"20":-0.002297865692526102,"21":0.04338551312685013,"22":0.0027146749198436737,"23":-0.0610479936003685,"24":-0.06408510357141495,"25":0.018841849640011787,"26":0.038649220019578934,"27":-0.05951906368136406,"28":-0.049136560410261154,"29":-0.01553028542548418,"30":0.06729687750339508,"31":0.11248184740543365,"32":0.005163560155779123,"33":-0.03759308531880379,"34":-0.027038585394620895,"35":0.09882332384586334,"36":-0.03552735969424248,"37":0.052484311163425446,"38":-0.12091276049613953,"39":-0.0760713443160057,"40":0.023518718779087067,"41":0.1491163820028305,"42":0.11237547546625137,"43":0.043433185666799545,"44":-0.10317730158567429,"45":0.13586443662643433,"46":-0.11140187084674835,"47":0.047351304441690445,"48":-0.004733437672257423,"49":-0.0036580911837518215,"50":-0.4543748199939728,"51":-0.0012553888373076916,"52":-0.3878886103630066,"53":-0.04243456572294235,"54":0.3538746237754822,"55":-0.29914388060569763,"56":0.2986484169960022,"57":-0.4102085530757904,"58":-0.06982053816318512,"59":-0.06546001136302948,"60":-1.0039697885513306,"61":-0.07975324243307114,"62":-0.6288756132125854,"63":0.10453850030899048,"64":1.923603892326355,"65":4.089285373687744,"66":0.837824285030365,"67":2.0477001667022705,"68":0.02293061651289463,"69":0.032243989408016205,"70":0.01139142457395792,"71":0.08008237928152084,"72":0.060887306928634644,"73":-0.06202433630824089,"74":-0.03496474772691727,"75":0.11840640008449554,"76":0.022548474371433258,"77":0.056371983140707016,"78":-0.19121955335140228,"79":0.014746267348527908,"80":0.027404092252254486,"81":0.013366243802011013,"82":-0.04335935041308403,"83":-0.004635565914213657,"84":0.06022524833679199,"85":-0.0066156028769910336,"86":-0.02207367867231369,"87":-0.013755309395492077,"88":0.0938468724489212,"89":0.016012031584978104,"90":0.053107306361198425,"91":-0.06528406590223312,"92":0.031027592718601227,"93":0.06466024369001389,"94":-0.060245998203754425,"95":-0.24264445900917053,"96":-0.022693663835525513,"97":-0.040935784578323364,"98":0.28490880131721497,"99":0.04169692099094391}},"forgetBias":{"rows":10,"columns":1,"weights":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0}},"outputMatrix":{"rows":10,"columns":1,"weights":{"0":0.39875373244285583,"1":-0.5439034700393677,"2":0.387065052986145,"3":0.3384949564933777,"4":-0.04658840224146843,"5":-0.215138778090477,"6":0.4459802806377411,"7":-0.009831061586737633,"8":-0.24754278361797333,"9":-0.29322341084480286}},"outputHidden":{"rows":10,"columns":10,"weights":{"0":-0.017383147031068802,"1":-0.05166752636432648,"2":-0.4121589958667755,"3":-0.00044157705269753933,"4":-0.058884404599666595,"5":-0.5330020785331726,"6":-0.34192612767219543,"7":0.5434070825576782,"8":-0.08809620887041092,"9":-0.01557594258338213,"10":0.25822409987449646,"11":0.5635818839073181,"12":0.4279966354370117,"13":0.36536142230033875,"14":-0.3951645791530609,"15":0.25468069314956665,"16":-0.2312953919172287,"17":0.5322455167770386,"18":-0.34078270196914673,"19":-0.17105257511138916,"20":-0.02965116873383522,"21":0.26805296540260315,"22":0.5444827675819397,"23":-0.012865622527897358,"24":-0.34074053168296814,"25":0.5941224694252014,"26":0.05155811458826065,"27":0.18370962142944336,"28":-0.2927640974521637,"29":-0.07054249197244644,"30":-0.0595853328704834,"31":0.22927093505859375,"32":0.0634147897362709,"33":-0.017249174416065216,"34":0.022240756079554558,"35":0.22056105732917786,"36":-0.05096535012125969,"37":0.03516764938831329,"38":-0.27492889761924744,"39":-0.09116704016923904,"40":0.42432570457458496,"41":0.3272692561149597,"42":1.1630610227584839,"43":-0.005760864354670048,"44":-1.5183769464492798,"45":3.4368317127227783,"46":-0.22553011775016785,"47":-1.6396024227142334,"48":-0.3553692400455475,"49":0.009739620611071587,"50":1.9999326467514038,"51":0.1860385537147522,"52":2.4422519207000732,"53":0.05143548548221588,"54":-2.5651066303253174,"55":3.3742854595184326,"56":-2.7379653453826904,"57":2.459275722503662,"58":-0.24622568488121033,"59":0.0521177239716053,"60":-0.041603948920965195,"61":0.03164331614971161,"62":-0.12904776632785797,"63":-0.045250628143548965,"64":0.4187449812889099,"65":-0.14468474686145782,"66":-0.679008424282074,"67":-1.812821626663208,"68":0.003673580242320895,"69":0.00854131206870079,"70":1.8837696313858032,"71":0.2376226782798767,"72":-0.14309458434581757,"73":0.13809727132320404,"74":0.10981391370296478,"75":10.132774353027344,"76":-0.8791309595108032,"77":1.6597392559051514,"78":-0.3239176273345947,"79":-0.17003922164440155,"80":-0.06197385862469673,"81":-0.20577049255371094,"82":-0.13585291802883148,"83":-0.02090541273355484,"84":-0.02817508950829506,"85":-0.2631819248199463,"86":0.05001521483063698,"87":-0.045181334018707275,"88":0.2509610652923584,"89":0.023592377081513405,"90":0.05446917191147804,"91":-0.30807048082351685,"92":-0.14463181793689728,"93":-0.040979497134685516,"94":0.0649748221039772,"95":-0.3391067385673523,"96":0.07384622097015381,"97":-0.11385004967451096,"98":0.2911340296268463,"99":0.026551706716418266}},"outputBias":{"rows":10,"columns":1,"weights":{"0":0.017023824155330658,"1":0.47568076848983765,"2":-0.037852637469768524,"3":0.12949800491333008,"4":2.71398663520813,"5":-0.21841584146022797,"6":4.763872146606445,"7":2.2534403800964355,"8":-0.1864534318447113,"9":-0.22093068063259125}},"cellActivationMatrix":{"rows":10,"columns":1,"weights":{"0":0.34374791383743286,"1":0.331052303314209,"2":0.32043027877807617,"3":0.30866092443466187,"4":-0.2822912931442261,"5":0.22314675152301788,"6":-0.3062632977962494,"7":0.3175785541534424,"8":0.23390983045101166,"9":0.03537409007549286}},"cellActivationHidden":{"rows":10,"columns":10,"weights":{"0":0.04260201379656792,"1":0.016630373895168304,"2":0.06892560422420502,"3":0.05204637721180916,"4":-0.004582292400300503,"5":-0.01690453104674816,"6":0.05180870741605759,"7":-0.0607154443860054,"8":0.008664052002131939,"9":0.015348333865404129,"10":0.04979377239942551,"11":-0.046576127409935,"12":0.016074031591415405,"13":0.010112743824720383,"14":0.02524285763502121,"15":0.0018837035167962313,"16":0.04565279930830002,"17":0.06054989993572235,"18":0.03969588503241539,"19":-0.06694924086332321,"20":-0.009862195700407028,"21":-0.0037828576751053333,"22":0.0034186900593340397,"23":0.024723617359995842,"24":0.004405881743878126,"25":0.0383935421705246,"26":0.011594532057642937,"27":-0.027063746005296707,"28":-0.07875735312700272,"29":-0.0060639516450464725,"30":0.05181751772761345,"31":0.0034302256535738707,"32":0.009164252318441868,"33":0.03760545700788498,"34":0.0026996128726750612,"35":0.170018270611763,"36":0.005847908090800047,"37":-0.03186068311333656,"38":-0.15081283450126648,"39":-0.05353393033146858,"40":-0.024863583967089653,"41":0.03957054018974304,"42":0.06800976395606995,"43":-0.05575961992144585,"44":-0.0032203576993197203,"45":0.038903966546058655,"46":-0.011703587137162685,"47":0.03690645471215248,"48":0.06041334569454193,"49":-0.07145965099334717,"50":0.049631692469120026,"51":0.03862046077847481,"52":0.05473954230546951,"53":-0.039466992020606995,"54":0.06896243989467621,"55":0.04201676324009895,"56":-0.029859457165002823,"57":0.03383437916636467,"58":-0.0609709769487381,"59":0.009075688198208809,"60":-0.05407703295350075,"61":-0.034858155995607376,"62":-0.04282470420002937,"63":0.055616192519664764,"64":0.04710986092686653,"65":-0.03424625098705292,"66":0.00044607208110392094,"67":-0.005352225620299578,"68":-0.0486464723944664,"69":-0.016301048919558525,"70":-0.01683785952627659,"71":0.007059569004923105,"72":0.05031591281294823,"73":0.07167109102010727,"74":0.03240160644054413,"75":0.1390117108821869,"76":0.014746464788913727,"77":0.00172339694108814,"78":-0.14587828516960144,"79":-0.07124986499547958,"80":-0.055919099599123,"81":0.03112192265689373,"82":0.07301633805036545,"83":-0.03389963507652283,"84":-0.03901137411594391,"85":0.044811952859163284,"86":-0.05233137682080269,"87":0.004546802025288343,"88":-0.06417589634656906,"89":-0.051080331206321716,"90":-0.052155982702970505,"91":-0.04665859043598175,"92":0.03961830958724022,"93":-0.004369210917502642,"94":0.039037562906742096,"95":-0.06990496814250946,"96":-0.017172781750559807,"97":-0.005705040413886309,"98":-0.044904232025146484,"99":-0.04753367230296135}},"cellActivationBias":{"rows":10,"columns":1,"weights":{"0":0.010272993706166744,"1":0.0020876554772257805,"2":0.0031780286226421595,"3":0.030588947236537933,"4":-0.0004922650405205786,"5":0.0010892762802541256,"6":-0.007843549363315105,"7":0.026072446256875992,"8":0.00716465013101697,"9":0.00013000205217394978}}},{"inputMatrix":{"rows":10,"columns":10,"weights":{"0":1.3095223903656006,"1":1.943090796470642,"2":-3.4203717708587646,"3":2.132424831390381,"4":6.191369533538818,"5":-13.017166137695312,"6":7.367273807525635,"7":-4.135716915130615,"8":0.3519895374774933,"9":0.19709020853042603,"10":6.241041660308838,"11":2.134580612182617,"12":2.5609798431396484,"13":2.127599000930786,"14":3.2492587566375732,"15":2.3199212551116943,"16":3.9743454456329346,"17":0.01627451181411743,"18":0.3492550253868103,"19":0.21780046820640564,"20":5.998623371124268,"21":2.0307528972625732,"22":2.2298178672790527,"23":2.027395725250244,"24":-5.452606678009033,"25":-1.3995215892791748,"26":-5.8013014793396,"27":3.433424711227417,"28":-0.23608922958374023,"29":-0.20616623759269714,"30":12.414880752563477,"31":1.3388296365737915,"32":1.6000373363494873,"33":1.472996711730957,"34":1.5592585802078247,"35":-1.5626453161239624,"36":2.8533122539520264,"37":-6.7787370681762695,"38":0.30946099758148193,"39":0.008842715062201023,"40":0.5391622185707092,"41":1.4667487144470215,"42":1.775636911392212,"43":1.5575053691864014,"44":-1.9267594814300537,"45":0.204706072807312,"46":-1.9371254444122314,"47":0.5070620775222778,"48":0.2612215280532837,"49":0.00417430279776454,"50":1.1852363348007202,"51":1.5479795932769775,"52":7.089638710021973,"53":1.5258204936981201,"54":-3.911233425140381,"55":2.0370960235595703,"56":-3.4757332801818848,"57":2.057166337966919,"58":0.34123581647872925,"59":0.12026919424533844,"60":-0.4901389181613922,"61":1.8946962356567383,"62":1.2260667085647583,"63":2.0099680423736572,"64":4.458343029022217,"65":-9.831422805786133,"66":4.410534858703613,"67":-5.701304912567139,"68":0.3139857351779938,"69":0.25259941816329956,"70":2.265679359436035,"71":2.0740232467651367,"72":0.5571096539497375,"73":1.9199544191360474,"74":6.232171535491943,"75":-7.76853084564209,"76":7.570146083831787,"77":-4.486452579498291,"78":-0.28989315032958984,"79":-0.2061915099620819,"80":6.826392650604248,"81":2.092787027359009,"82":2.5453555583953857,"83":1.9135096073150635,"84":1.3497257232666016,"85":-0.36152705550193787,"86":1.2075974941253662,"87":0.22319340705871582,"88":-0.3543025851249695,"89":-0.18838030099868774,"90":-1.690462589263916,"91":1.7615739107131958,"92":1.8066954612731934,"93":1.4663786888122559,"94":5.4144086837768555,"95":-4.816118240356445,"96":8.611133575439453,"97":-8.0062255859375,"98":-0.2603089213371277,"99":-0.03868803381919861}},"inputHidden":{"rows":10,"columns":10,"weights":{"0":7.107485294342041,"1":0.7523351907730103,"2":2.604668140411377,"3":0.31053781509399414,"4":0.5916827321052551,"5":-1.7357006072998047,"6":-4.629075050354004,"7":-7.6247711181640625,"8":1.7662991285324097,"9":-5.731286525726318,"10":-4.237152099609375,"11":6.0128679275512695,"12":1.3850126266479492,"13":1.3482669591903687,"14":0.8184328079223633,"15":-2.4653890132904053,"16":1.8426870107650757,"17":9.129096031188965,"18":-5.530699729919434,"19":-1.4941774606704712,"20":-2.907557725906372,"21":2.320765256881714,"22":-4.487015247344971,"23":-0.9325949549674988,"24":0.35747599601745605,"25":0.005669841542840004,"26":-3.3572142124176025,"27":2.834737539291382,"28":-0.9040987491607666,"29":2.128628969192505,"30":-0.8048205971717834,"31":3.8137333393096924,"32":-1.7143102884292603,"33":4.1856794357299805,"34":2.76851224899292,"35":-9.043281555175781,"36":-2.4538156986236572,"37":-0.5059328079223633,"38":1.6457233428955078,"39":-3.4078779220581055,"40":1.5122718811035156,"41":2.4052417278289795,"42":0.4782022535800934,"43":0.3689427971839905,"44":0.11115498840808868,"45":-2.663266897201538,"46":-2.6147196292877197,"47":-1.6000553369522095,"48":1.6546707153320312,"49":-1.7387324571609497,"50":-0.2140512764453888,"51":2.3462276458740234,"52":-2.1333067417144775,"53":4.303236484527588,"54":4.374351978302002,"55":-4.124452590942383,"56":-2.737847328186035,"57":0.945078432559967,"58":-0.14557164907455444,"59":-3.3066246509552,"60":6.742399215698242,"61":1.2853758335113525,"62":3.7744715213775635,"63":-0.3728155493736267,"64":0.4489395320415497,"65":1.3766368627548218,"66":-10.989341735839844,"67":-6.956964015960693,"68":3.527987241744995,"69":-9.172257423400879,"70":3.8242552280426025,"71":0.7316394448280334,"72":-0.1088661253452301,"73":0.7650551199913025,"74":1.1982253789901733,"75":-1.039297103881836,"76":-3.491899013519287,"77":-4.833630084991455,"78":2.87563419342041,"79":5.02373743057251,"80":1.6551700830459595,"81":5.832190990447998,"82":-5.762627601623535,"83":-0.18253031373023987,"84":-0.6891084313392639,"85":-0.5870305299758911,"86":-9.222054481506348,"87":-7.8820648193359375,"88":10.3092622756958,"89":-2.783879518508911,"90":-1.7429044246673584,"91":2.302130699157715,"92":-3.799260377883911,"93":0.48029986023902893,"94":-0.4828950762748718,"95":-3.5957655906677246,"96":0.5257095694541931,"97":-3.520432472229004,"98":-2.805736541748047,"99":-4.813488006591797}},"inputBias":{"rows":10,"columns":1,"weights":{"0":4.815317153930664,"1":5.622940540313721,"2":3.9629509449005127,"3":8.202987670898438,"4":14.011276245117188,"5":8.432486534118652,"6":7.659708499908447,"7":0.6155846118927002,"8":0.3965849280357361,"9":3.15493106842041}},"forgetMatrix":{"rows":10,"columns":10,"weights":{"0":-2.28529953956604,"1":0.634941816329956,"2":2.2581748962402344,"3":-0.7969462275505066,"4":0.45547208189964294,"5":-12.38093090057373,"6":1.4020538330078125,"7":-2.6332437992095947,"8":0.31075993180274963,"9":0.03332117944955826,"10":-1.2544257640838623,"11":0.27472299337387085,"12":0.30565762519836426,"13":-0.9765614867210388,"14":1.3401296138763428,"15":1.270494818687439,"16":3.2240569591522217,"17":-2.406653642654419,"18":0.31708693504333496,"19":0.11004247516393661,"20":-1.5941307544708252,"21":0.7122229337692261,"22":3.456634759902954,"23":-1.12691068649292,"24":-4.212471961975098,"25":4.681552410125732,"26":-2.5271456241607666,"27":2.6155688762664795,"28":-0.3521801233291626,"29":-0.08146784454584122,"30":1.8947508335113525,"31":-0.1394193172454834,"32":0.0831112191081047,"33":-1.327505350112915,"34":-0.4054758846759796,"35":6.043362140655518,"36":1.225152850151062,"37":-2.318356990814209,"38":0.25256386399269104,"39":-0.006203425116837025,"40":1.520666241645813,"41":0.08394858241081238,"42":1.84476900100708,"43":-1.2619346380233765,"44":0.05650067329406738,"45":13.374556541442871,"46":1.0906533002853394,"47":0.061809372156858444,"48":0.28071606159210205,"49":0.03697102516889572,"50":-6.587985038757324,"51":0.2514001727104187,"52":-3.7787766456604004,"53":-1.2904857397079468,"54":3.6252150535583496,"55":3.014673948287964,"56":4.669000625610352,"57":5.874388217926025,"58":0.28079095482826233,"59":0.061948467046022415,"60":-0.8310995697975159,"61":0.1368047297000885,"62":0.09152223914861679,"63":-1.1634057760238647,"64":1.5692888498306274,"65":-12.65714168548584,"66":0.30847421288490295,"67":-0.9138410687446594,"68":0.240425243973732,"69":0.04521239176392555,"70":2.8272626399993896,"71":0.5881940126419067,"72":-0.2382936030626297,"73":-1.1768985986709595,"74":2.2793707847595215,"75":-1.2544647455215454,"76":3.3040289878845215,"77":-1.665697693824768,"78":-0.27290576696395874,"79":-0.1234973669052124,"80":-2.1828484535217285,"81":0.5467154383659363,"82":0.13149718940258026,"83":-1.1570535898208618,"84":2.9737672805786133,"85":7.032181262969971,"86":2.5319206714630127,"87":-4.0597991943359375,"88":-0.22452405095100403,"89":-0.14402993023395538,"90":2.304694652557373,"91":0.38563665747642517,"92":-1.3750520944595337,"93":-1.2900925874710083,"94":3.289670705795288,"95":-6.454377174377441,"96":2.9766907691955566,"97":-0.511162281036377,"98":-0.27458053827285767,"99":0.0525771826505661}},"forgetHidden":{"rows":10,"columns":10,"weights":{"0":1.031665325164795,"1":-2.3291211128234863,"2":-4.028607368469238,"3":3.1461281776428223,"4":3.8021438121795654,"5":-3.939532518386841,"6":-0.3365568518638611,"7":10.937434196472168,"8":-11.328117370605469,"9":-3.9450154304504395,"10":7.215024471282959,"11":-1.0333781242370605,"12":-9.566424369812012,"13":1.2337287664413452,"14":0.25163665413856506,"15":-1.0799161195755005,"16":-1.3317954540252686,"17":1.4287148714065552,"18":-4.742713928222656,"19":0.07075119018554688,"20":-5.65816068649292,"21":-7.628519535064697,"22":-4.524716377258301,"23":-1.562341570854187,"24":-1.699520230293274,"25":-3.9371066093444824,"26":1.363014817237854,"27":7.780106067657471,"28":1.6129603385925293,"29":11.39100170135498,"30":-3.3334827423095703,"31":6.241874694824219,"32":-7.007091522216797,"33":3.855642318725586,"34":3.166926860809326,"35":-4.574263095855713,"36":2.067986488342285,"37":8.808808326721191,"38":-6.745934009552002,"39":-0.8373534679412842,"40":2.0075786113739014,"41":21.155826568603516,"42":10.206195831298828,"43":3.1960995197296143,"44":0.34131669998168945,"45":-3.633465051651001,"46":-2.78922438621521,"47":9.930496215820312,"48":-4.65199613571167,"49":-3.5002036094665527,"50":0.6106136441230774,"51":13.287885665893555,"52":-1.6958396434783936,"53":0.8723315596580505,"54":-0.5626092553138733,"55":0.23505030572414398,"56":-5.873342514038086,"57":-10.748922348022461,"58":-5.476647853851318,"59":-15.105390548706055,"60":17.027814865112305,"61":1.4286991357803345,"62":-0.7903316617012024,"63":-0.6602847576141357,"64":0.6434434056282043,"65":0.29782038927078247,"66":0.00005286664963932708,"67":1.5666357278823853,"68":1.4720402956008911,"69":8.171562194824219,"70":-2.3766915798187256,"71":-1.278789758682251,"72":-0.5749138593673706,"73":-1.4026743173599243,"74":0.8136733174324036,"75":-3.1674611568450928,"76":-0.04387296363711357,"77":-7.310353755950928,"78":7.92842435836792,"79":0.9043824076652527,"80":-0.03996953368186951,"81":-0.6220892667770386,"82":0.6347506046295166,"83":1.4204504489898682,"84":-1.2624804973602295,"85":-4.232823848724365,"86":1.171608567237854,"87":-4.376074314117432,"88":1.5958935022354126,"89":-3.8980824947357178,"90":0.9443599581718445,"91":2.2163896560668945,"92":-0.9827396273612976,"93":-0.20416989922523499,"94":1.5220098495483398,"95":-1.2572633028030396,"96":-3.3609302043914795,"97":8.383264541625977,"98":-3.5535662174224854,"99":3.1718273162841797}},"forgetBias":{"rows":10,"columns":1,"weights":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0}},"outputMatrix":{"rows":10,"columns":10,"weights":{"0":2.321291208267212,"1":1.7364004850387573,"2":0.5440369248390198,"3":1.9307444095611572,"4":3.2647833824157715,"5":-17.152782440185547,"6":5.127710342407227,"7":-3.0467000007629395,"8":0.22881488502025604,"9":0.14785104990005493,"10":13.900742530822754,"11":1.9242572784423828,"12":4.980358600616455,"13":1.8939203023910522,"14":3.1093621253967285,"15":0.9118334054946899,"16":3.530733823776245,"17":4.267331123352051,"18":0.31865301728248596,"19":0.2216307371854782,"20":0.9004737734794617,"21":1.7531352043151855,"22":-0.7667370438575745,"23":1.5697535276412964,"24":-1.1332944631576538,"25":3.047121286392212,"26":-2.0700836181640625,"27":-5.811157703399658,"28":-0.3290497362613678,"29":-0.31872639060020447,"30":0.17686013877391815,"31":1.1014811992645264,"32":0.7105960845947266,"33":1.1883671283721924,"34":-1.7385623455047607,"35":-0.22805087268352509,"36":-1.5638313293457031,"37":0.7018072009086609,"38":0.22221431136131287,"39":0.09680331498384476,"40":18.251195907592773,"41":1.0288680791854858,"42":-0.12753991782665253,"43":1.2810211181640625,"44":3.133443593978882,"45":-1.37489652633667,"46":4.366850852966309,"47":0.04271682724356651,"48":0.3285137116909027,"49":-0.004071693401783705,"50":2.273137092590332,"51":1.381241798400879,"52":7.97281551361084,"53":1.4233813285827637,"54":-3.394113779067993,"55":1.58104407787323,"56":-3.092432737350464,"57":0.5919463038444519,"58":0.34157076478004456,"59":0.19426999986171722,"60":-0.53864586353302,"61":1.8281668424606323,"62":-0.7831876873970032,"63":1.6683605909347534,"64":6.589377403259277,"65":-9.238088607788086,"66":7.082867622375488,"67":-2.1327993869781494,"68":0.3295828700065613,"69":0.19464701414108276,"70":0.43168359994888306,"71":1.683140516281128,"72":-1.7868579626083374,"73":1.4285228252410889,"74":6.304558753967285,"75":-7.048821449279785,"76":4.156632423400879,"77":-5.586171627044678,"78":-0.30443891882896423,"79":-0.23674732446670532,"80":2.2009596824645996,"81":1.7008174657821655,"82":0.7977727651596069,"83":1.4262824058532715,"84":7.483044147491455,"85":-0.9640535712242126,"86":4.453894138336182,"87":2.9754700660705566,"88":-0.2465376853942871,"89":-0.31813672184944153,"90":0.8017577528953552,"91":1.402456283569336,"92":3.734222650527954,"93":1.1430402994155884,"94":-1.407244324684143,"95":-0.6123622059822083,"96":0.364644318819046,"97":5.5455002784729,"98":-0.3546661138534546,"99":0.02496921643614769}},"outputHidden":{"rows":10,"columns":10,"weights":{"0":7.258588790893555,"1":0.9114058613777161,"2":-1.7164241075515747,"3":2.21744704246521,"4":2.185615062713623,"5":-2.3496408462524414,"6":1.1277488470077515,"7":1.1643332242965698,"8":-4.566551685333252,"9":1.9360488653182983,"10":-2.0647940635681152,"11":1.4535086154937744,"12":-0.574030876159668,"13":2.4482600688934326,"14":2.283106565475464,"15":-3.9868369102478027,"16":-0.9149439334869385,"17":-5.5046916007995605,"18":-3.629305601119995,"19":-2.5021615028381348,"20":-7.84077262878418,"21":2.5207817554473877,"22":-10.810043334960938,"23":-2.814162015914917,"24":-0.5341741442680359,"25":1.8406684398651123,"26":-0.005653572268784046,"27":4.580265522003174,"28":-4.500970840454102,"29":7.3915324211120605,"30":1.4755085706710815,"31":2.724687337875366,"32":-1.0139808654785156,"33":-0.22823959589004517,"34":0.43983176350593567,"35":-2.937134265899658,"36":-3.050698757171631,"37":-1.436212420463562,"38":1.5975358486175537,"39":-1.4348288774490356,"40":-1.156494140625,"41":3.066143274307251,"42":-2.233931303024292,"43":4.35071325302124,"44":3.234807252883911,"45":-8.595220565795898,"46":-1.10177481174469,"47":0.753319263458252,"48":-0.30417776107788086,"49":-2.8798465728759766,"50":-1.6687344312667847,"51":2.4544878005981445,"52":-3.103393316268921,"53":4.39017915725708,"54":4.167747974395752,"55":-5.40269660949707,"56":-2.5506443977355957,"57":0.9235258102416992,"58":0.3235868215560913,"59":-3.767709493637085,"60":4.026076793670654,"61":4.493719100952148,"62":1.1447670459747314,"63":2.7787609100341797,"64":3.2481849193573,"65":-2.2429749965667725,"66":-5.372661113739014,"67":0.12155076116323471,"68":-3.2961459159851074,"69":-5.924631595611572,"70":-0.4773372411727905,"71":-1.2555838823318481,"72":-0.7177032232284546,"73":-0.12366250902414322,"74":-0.5828892588615417,"75":-1.0158549547195435,"76":-2.3805184364318848,"77":-1.3307658433914185,"78":-0.6501840949058533,"79":-1.0220999717712402,"80":-0.3967978358268738,"81":-0.3350769281387329,"82":1.3367348909378052,"83":-0.710413932800293,"84":-2.6453452110290527,"85":0.09704861044883728,"86":1.0985645055770874,"87":-23.965988159179688,"88":1.6835037469863892,"89":1.574048638343811,"90":4.421099662780762,"91":3.252802848815918,"92":5.065232276916504,"93":0.10273998975753784,"94":0.741520345211029,"95":-3.875079870223999,"96":-5.77454948425293,"97":-8.40023136138916,"98":4.128347873687744,"99":-8.196733474731445}},"outputBias":{"rows":10,"columns":1,"weights":{"0":3.0839366912841797,"1":6.133158206939697,"2":11.805830001831055,"3":15.453643798828125,"4":7.533968925476074,"5":8.03875732421875,"6":2.261145830154419,"7":8.465453147888184,"8":7.534668922424316,"9":7.325540065765381}},"cellActivationMatrix":{"rows":10,"columns":10,"weights":{"0":0.7191573977470398,"1":0.3932143449783325,"2":-0.025583231821656227,"3":1.6326940059661865,"4":-0.39805686473846436,"5":7.593294143676758,"6":-4.848240375518799,"7":-1.8113338947296143,"8":-0.18287354707717896,"9":-0.2240370810031891,"10":2.5657155513763428,"11":0.3772284984588623,"12":0.1524338722229004,"13":1.7447245121002197,"14":-2.9513845443725586,"15":11.226088523864746,"16":-5.542431354522705,"17":0.3077843189239502,"18":-0.2657475173473358,"19":-0.23629415035247803,"20":-2.4213340282440186,"21":-0.44749608635902405,"22":-1.3177956342697144,"23":-1.6955748796463013,"24":1.8268853425979614,"25":0.6082886457443237,"26":2.0592782497406006,"27":-0.33667370676994324,"28":0.30430081486701965,"29":0.24053293466567993,"30":0.31087547540664673,"31":0.5112341046333313,"32":-1.036217212677002,"33":1.2492749691009521,"34":-0.8502957820892334,"35":6.045202732086182,"36":-0.936873733997345,"37":-0.11396417766809464,"38":0.3150613605976105,"39":0.30791419744491577,"40":8.32589340209961,"41":0.47352275252342224,"42":-1.9188843965530396,"43":1.3515141010284424,"44":-2.754976272583008,"45":2.8911542892456055,"46":-2.0683822631835938,"47":-1.4221222400665283,"48":0.2510184347629547,"49":0.24937090277671814,"50":-6.0790839195251465,"51":-0.3402538597583771,"52":-0.08728060126304626,"53":-1.5920748710632324,"54":0.34758561849594116,"55":-1.6477267742156982,"56":3.3410840034484863,"57":-2.5678210258483887,"58":0.2592853605747223,"59":0.25491198897361755,"60":-1.124485969543457,"61":-0.3229120075702667,"62":0.13944530487060547,"63":-1.6447277069091797,"64":0.9750833511352539,"65":13.778406143188477,"66":1.2643589973449707,"67":0.5804961323738098,"68":0.08928054571151733,"69":0.2971378564834595,"70":1.0989259481430054,"71":-0.5350832939147949,"72":-0.022723287343978882,"73":-1.3061257600784302,"74":0.9240126013755798,"75":-9.121136665344238,"76":0.8973737359046936,"77":0.09983672201633453,"78":0.07989216595888138,"79":0.22634035348892212,"80":3.0577657222747803,"81":0.4935096502304077,"82":1.6711130142211914,"83":1.4388599395751953,"84":-1.4811574220657349,"85":12.298669815063477,"86":-1.4517204761505127,"87":0.08249450474977493,"88":-0.11013371497392654,"89":-0.24685949087142944,"90":-0.7881948947906494,"91":-0.8531959056854248,"92":-3.328956127166748,"93":-0.3374745845794678,"94":2.899678945541382,"95":-0.5832717418670654,"96":2.445373058319092,"97":-2.04313063621521,"98":0.29872578382492065,"99":0.34532687067985535}},"cellActivationHidden":{"rows":10,"columns":10,"weights":{"0":-2.7339460849761963,"1":-1.8768761157989502,"2":1.3249763250350952,"3":0.2684552073478699,"4":-0.2172783464193344,"5":-0.0854388028383255,"6":1.6716119050979614,"7":3.9363696575164795,"8":-1.7296134233474731,"9":3.4922852516174316,"10":-2.6147494316101074,"11":-0.9610380530357361,"12":-0.02085547149181366,"13":-0.33014631271362305,"14":-0.26700061559677124,"15":0.33977067470550537,"16":3.0130419731140137,"17":0.8603442907333374,"18":-0.7384302020072937,"19":2.242258310317993,"20":3.595763921737671,"21":5.059907913208008,"22":0.4368404448032379,"23":-0.3724168539047241,"24":-0.24289049208164215,"25":-0.11947804689407349,"26":-2.9514997005462646,"27":-8.195229530334473,"28":1.0430551767349243,"29":-1.1289567947387695,"30":-0.0607910230755806,"31":3.8479385375976562,"32":-2.721027374267578,"33":-0.32011979818344116,"34":-0.9255940318107605,"35":0.14060328900814056,"36":1.0969215631484985,"37":2.9939181804656982,"38":-0.7413846850395203,"39":1.5288307666778564,"40":2.496692657470703,"41":-0.4795607924461365,"42":0.6409103870391846,"43":0.06486240029335022,"44":-1.5745468139648438,"45":0.6396698355674744,"46":-4.955456256866455,"47":-12.933869361877441,"48":-0.597680926322937,"49":-0.3065277338027954,"50":-0.7633152008056641,"51":-0.6015927791595459,"52":1.764341115951538,"53":-2.301504611968994,"54":-1.9905869960784912,"55":1.1498459577560425,"56":0.4781780242919922,"57":0.6589425802230835,"58":-0.9499701261520386,"59":1.2837296724319458,"60":1.5640367269515991,"61":0.9227778315544128,"62":0.18500110507011414,"63":-0.330699622631073,"64":0.045436423271894455,"65":-0.18810664117336273,"66":-1.206076741218567,"67":-2.0444939136505127,"68":0.12441488355398178,"69":1.6432186365127563,"70":1.6939631700515747,"71":1.0726603269577026,"72":3.974792718887329,"73":0.7294965386390686,"74":0.9985246658325195,"75":-1.4708843231201172,"76":-2.3629467487335205,"77":-0.5125780701637268,"78":0.49301737546920776,"79":0.36362746357917786,"80":-1.487631916999817,"81":-1.220715880393982,"82":-0.7532594203948975,"83":-0.3086014986038208,"84":-0.20236656069755554,"85":1.0702420473098755,"86":0.20269158482551575,"87":-1.5288113355636597,"88":-1.8228977918624878,"89":-1.7422488927841187,"90":-0.12410015612840652,"91":-0.1759231835603714,"92":1.00491201877594,"93":-0.7285945415496826,"94":-0.7352412343025208,"95":0.13602808117866516,"96":-0.018572701141238213,"97":0.795587956905365,"98":-0.9121976494789124,"99":0.8112156987190247}},"cellActivationBias":{"rows":10,"columns":1,"weights":{"0":5.666567325592041,"1":-1.1622247695922852,"2":-2.3220534324645996,"3":3.8908936977386475,"4":0.6848836541175842,"5":-0.5648518204689026,"6":-0.3140695095062256,"7":-4.902627944946289,"8":-0.27275151014328003,"9":-4.980154514312744}}}],"outputConnector":{"rows":1,"columns":10,"weights":{"0":11.36241340637207,"1":-3.7287819385528564,"2":2.2021946907043457,"3":-7.022632598876953,"4":-10.390512466430664,"5":8.150146484375,"6":-11.4092378616333,"7":-16.732629776000977,"8":-14.796433448791504,"9":-9.624754905700684}},"output":{"rows":1,"columns":1,"weights":{"0":91.82943725585938}},"inputLookup":null,"inputLookupLength":null,"outputLookup":null,"outputLookupLength":null};
var output = [];
var states = [];
var prevStates;
var state;
var max = input.length;
for (var _i = 0; _i < max; _i++) {
prevStates = states;
states = [];
states[0] = {
name: 'forwardFn',
left: null,
right: null,
product: new Matrix(1, 1)
};
states[1] = {
name: 'multiply',
left: json.hiddenLayers[0].inputMatrix,
right: states[0].product,
product: new Matrix(10, 1)
};
states[2] = {
name: 'multiply',
left: json.hiddenLayers[0].inputHidden,
right: typeof prevStates[25] === 'object' ? prevStates[25].product : new Matrix(10, 1),
product: new Matrix(10, 1)
};
states[3] = {
name: 'add',
left: states[1].product,
right: states[2].product,
product: new Matrix(10, 1)
};
states[4] = {
name: 'add',
left: states[3].product,
right: json.hiddenLayers[0].inputBias,
product: new Matrix(10, 1)
};
states[5] = {
name: 'sigmoid',
left: states[4].product,
right: null,
product: new Matrix(10, 1)
};
states[6] = {
name: 'multiply',
left: json.hiddenLayers[0].forgetMatrix,
right: states[0].product,
product: new Matrix(10, 1)
};
states[7] = {
name: 'multiply',
left: json.hiddenLayers[0].forgetHidden,
right: states[2].right,
product: new Matrix(10, 1)
};
states[8] = {
name: 'add',
left: states[6].product,
right: states[7].product,
product: new Matrix(10, 1)
};
states[9] = {
name: 'add',
left: states[8].product,
right: json.hiddenLayers[0].forgetBias,
product: new Matrix(10, 1)
};
states[10] = {
name: 'sigmoid',
left: states[9].product,
right: null,
product: new Matrix(10, 1)
};
states[11] = {
name: 'multiply',
left: json.hiddenLayers[0].outputMatrix,
right: states[0].product,
product: new Matrix(10, 1)
};
states[12] = {
name: 'multiply',
left: json.hiddenLayers[0].outputHidden,
right: states[2].right,
product: new Matrix(10, 1)
};
states[13] = {
name: 'add',
left: states[11].product,
right: states[12].product,
product: new Matrix(10, 1)
};
states[14] = {
name: 'add',
left: states[13].product,
right: json.hiddenLayers[0].outputBias,
product: new Matrix(10, 1)
};
states[15] = {
name: 'sigmoid',
left: states[14].product,
right: null,
product: new Matrix(10, 1)
};
states[16] = {
name: 'multiply',
left: json.hiddenLayers[0].cellActivationMatrix,
right: states[0].product,
product: new Matrix(10, 1)
};
states[17] = {
name: 'multiply',
left: json.hiddenLayers[0].cellActivationHidden,
right: states[2].right,
product: new Matrix(10, 1)
};
states[18] = {
name: 'add',
left: states[16].product,
right: states[17].product,
product: new Matrix(10, 1)
};
states[19] = {
name: 'add',
left: states[18].product,
right: json.hiddenLayers[0].cellActivationBias,
product: new Matrix(10, 1)
};
states[20] = {
name: 'tanh',
left: states[19].product,
right: null,
product: new Matrix(10, 1)
};
states[21] = {
name: 'multiplyElement',
left: states[10].product,
right: states[2].right,
product: new Matrix(10, 1)
};
states[22] = {
name: 'multiplyElement',
left: states[5].product,
right: states[20].product,
product: new Matrix(10, 1)
};
states[23] = {
name: 'add',
left: states[21].product,
right: states[22].product,
product: new Matrix(10, 1)
};
states[24] = {
name: 'tanh',
left: states[23].product,
right: null,
product: new Matrix(10, 1)
};
states[25] = {
name: 'multiplyElement',
left: states[15].product,
right: states[24].product,
product: new Matrix(10, 1)
};
states[26] = {
name: 'multiply',
left: json.hiddenLayers[1].inputMatrix,
right: states[25].product,
product: new Matrix(10, 1)
};
states[27] = {
name: 'multiply',
left: json.hiddenLayers[1].inputHidden,
right: typeof prevStates[50] === 'object' ? prevStates[50].product : new Matrix(10, 1),
product: new Matrix(10, 1)
};
states[28] = {
name: 'add',
left: states[26].product,
right: states[27].product,
product: new Matrix(10, 1)
};
states[29] = {
name: 'add',
left: states[28].product,
right: json.hiddenLayers[1].inputBias,
product: new Matrix(10, 1)
};
states[30] = {
name: 'sigmoid',
left: states[29].product,
right: null,
product: new Matrix(10, 1)
};
states[31] = {
name: 'multiply',
left: json.hiddenLayers[1].forgetMatrix,
right: states[25].product,
product: new Matrix(10, 1)
};
states[32] = {
name: 'multiply',
left: json.hiddenLayers[1].forgetHidden,
right: states[27].right,
product: new Matrix(10, 1)
};
states[33] = {
name: 'add',
left: states[31].product,
right: states[32].product,
product: new Matrix(10, 1)
};
states[34] = {
name: 'add',
left: states[33].product,
right: json.hiddenLayers[1].forgetBias,
product: new Matrix(10, 1)
};
states[35] = {
name: 'sigmoid',
left: states[34].product,
right: null,
product: new Matrix(10, 1)
};
states[36] = {
name: 'multiply',
left: json.hiddenLayers[1].outputMatrix,
right: states[25].product,
product: new Matrix(10, 1)
};
states[37] = {
name: 'multiply',
left: json.hiddenLayers[1].outputHidden,
right: states[27].right,
product: new Matrix(10, 1)
};
states[38] = {
name: 'add',
left: states[36].product,
right: states[37].product,
product: new Matrix(10, 1)
};
states[39] = {
name: 'add',
left: states[38].product,
right: json.hiddenLayers[1].outputBias,
product: new Matrix(10, 1)
};
states[40] = {
name: 'sigmoid',
left: states[39].product,
right: null,
product: new Matrix(10, 1)
};
states[41] = {
name: 'multiply',
left: json.hiddenLayers[1].cellActivationMatrix,
right: states[25].product,
product: new Matrix(10, 1)
};
states[42] = {
name: 'multiply',
left: json.hiddenLayers[1].cellActivationHidden,
right: states[27].right,
product: new Matrix(10, 1)
};
states[43] = {
name: 'add',
left: states[41].product,
right: states[42].product,
product: new Matrix(10, 1)
};
states[44] = {
name: 'add',
left: states[43].product,
right: json.hiddenLayers[1].cellActivationBias,
product: new Matrix(10, 1)
};
states[45] = {
name: 'tanh',
left: states[44].product,
right: null,
product: new Matrix(10, 1)
};
states[46] = {
name: 'multiplyElement',
left: states[35].product,
right: states[27].right,
product: new Matrix(10, 1)
};
states[47] = {
name: 'multiplyElement',
left: states[30].product,
right: states[45].product,
product: new Matrix(10, 1)
};
states[48] = {
name: 'add',
left: states[46].product,
right: states[47].product,
product: new Matrix(10, 1)
};
states[49] = {
name: 'tanh',
left: states[48].product,
right: null,
product: new Matrix(10, 1)
};
states[50] = {
name: 'multiplyElement',
left: states[40].product,
right: states[49].product,
product: new Matrix(10, 1)
};
states[51] = {
name: 'multiply',
left: json.outputConnector,
right: states[50].product,
product: new Matrix(1, 1)
};
states[52] = {
name: 'add',
left: states[51].product,
right: json.output,
product: new Matrix(1, 1)
};
for (var stateIndex = 0, stateMax = 53; stateIndex < stateMax; stateIndex++) {
state = states[stateIndex];
var product = state.product;
var left = state.left;
var right = state.right;
switch (state.name) {
case 'forwardFn':
product.weights = _input.weights = _this.inputValue;
break;
case 'multiply': //compiled from src/recurrent/matrix/multiply.js
var leftRows = left.rows;
var leftColumns = left.columns;
var rightColumns = right.columns; // loop over rows of left
for (var leftRow = 0; leftRow < leftRows; leftRow++) {
var leftRowBase = leftColumns * leftRow;
var rightRowBase = rightColumns * leftRow; // loop over cols of right
for (var rightColumn = 0; rightColumn < rightColumns; rightColumn++) {
// dot product loop
var dot = 0; // loop over columns of left
for (var leftColumn = 0; leftColumn < leftColumns; leftColumn++) {
var rightColumnBase = rightColumns * leftColumn;
var leftIndex = leftRowBase + leftColumn;
var rightIndex = rightColumnBase + rightColumn;
dot += left.weights[leftIndex] * right.weights[rightIndex];
}
product.weights[rightRowBase + rightColumn] = dot;
}
}
break;
case 'add': //compiled from src/recurrent/matrix/add.js
for (var i = 0; i < left.weights.length; i++) {
product.weights[i] = left.weights[i] + right.weights[i];
}
break;
case 'sigmoid': //compiled from src/recurrent/matrix/sigmoid.js
// sigmoid nonlinearity
for (var i = 0; i < left.weights.length; i++) {
product.weights[i] = 1 / (1 + Math.exp(-left.weights[i]));
}
break;
case 'tanh': //compiled from src/recurrent/matrix/tanh.js
// tanh nonlinearity
for (var i = 0; i < left.weights.length; i++) {
product.weights[i] = Math.tanh(left.weights[i]);
}
break;
case 'multiplyElement': //compiled from src/recurrent/matrix/multiply-element.js
var weights = left.weights;
for (var i = 0; i < weights.length; i++) {
product.weights[i] = left.weights[i] * right.weights[i];
}
break;
}
}
output = state.product.weights;
}
return output[0];
function Matrix(rows, columns) {
this.rows = rows;
this.columns = columns;
this.weights = zeros(rows * columns);
}
function zeros(size) {
return new Float32Array(size);
}
function softmax(m) {
var result = new Matrix(m.rows, m.columns); // probability volume
var maxVal = -999999;
for (var i = 0; i < m.weights.length; i++) {
if (m.weights[i] > maxVal) {
maxVal = m.weights[i];
}
}
var s = 0;
for (var _i = 0; _i < m.weights.length; _i++) {
result.weights[_i] = Math.exp(m.weights[_i] - maxVal);
s += result.weights[_i];
}
for (var _i2 = 0; _i2 < m.weights.length; _i2++) {
result.weights[_i2] /= s;
} // no backward pass here needed
// since we will use the computed probabilities outside
// to set gradients directly on m
return result;
}
function randomFloat(a, b) {
return Math.random() * (b - a) + a;
}
function sampleI(m) {
// sample argmax from w, assuming w are
// probabilities that sum to one
var r = randomFloat(0, 1);
var x = 0;
var i = 0;
var w = m.weights;
while (true) {
x += w[i];
if (x > r) {
return i;
}
i++;
}
}
function maxI(m) {
// argmax of array w
var weights = m.weights;
var maxv = weights[0];
var maxix = 0;
for (var i = 1; i < weights.length; i++) {
var v = weights[i];
if (v < maxv) continue;
maxix = i;
maxv = v;
}
return maxix;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment