Skip to content

Commit

Permalink
update autoencoders
Browse files Browse the repository at this point in the history
  • Loading branch information
retraigo committed Sep 24, 2024
1 parent 01e66b5 commit 4614222
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/autoencoders/decoded.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<table>
<thead><tr><th>idx</th><th>0</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>9</th><th>10</th></tr></thead><tr><td><strong>0</strong></td><td>7.55847692489624</td><td>0.6037468910217285</td><td>0.11795109510421753</td><td>1.9666798114776611</td><td>0.1065782904624939</td><td>10.064826011657715</td><td>34.21046829223633</td><td>0.9966872930526733</td><td>3.3553307056427</td><td>0.6890174150466919</td><td>9.519981384277344</td></tr><tr><td><strong>1</strong></td><td>7.881095886230469</td><td>0.5767951011657715</td><td>0.18734347820281982</td><td>2.6810266971588135</td><td>0.12046629190444946</td><td>20.419382095336914</td><td>68.4073257446289</td><td>0.9971261620521545</td><td>3.3022282123565674</td><td>0.7434358596801758</td><td>9.61740493774414</td></tr><tr><td><strong>2</strong></td><td>7.742885112762451</td><td>0.5883421897888184</td><td>0.15761566162109375</td><td>2.3749964237213135</td><td>0.1145172119140625</td><td>15.983437538146973</td><td>53.75722122192383</td><td>0.9969378113746643</td><td>3.324977397918701</td><td>0.7201226949691772</td><td>9.575666427612305</td></tr><tr><td><strong>3</strong></td><td>7.799614906311035</td><td>0.5836020112037659</td><td>0.16981801390647888</td><td>2.5006117820739746</td><td>0.11695808172225952</td><td>17.80423355102539</td><td>59.770565032958984</td><td>0.9970149397850037</td><td>3.3156394958496094</td><td>0.7296922206878662</td><td>9.592796325683594</td></tr><tr><td><strong>4</strong></td><td>7.55847692489624</td><td>0.6037468910217285</td><td>0.11795109510421753</td><td>1.9666798114776611</td><td>0.1065782904624939</td><td>10.064826011657715</td><td>34.21046829223633</td><td>0.9966872930526733</td><td>3.3553307056427</td><td>0.6890174150466919</td><td>9.519981384277344</td></tr><tr><td><strong>5</strong></td><td>7.615657329559326</td><td>0.5989702343940735</td><td>0.13024991750717163</td><td>2.093287229537964</td><td>0.10904103517532349</td><td>11.900023460388184</td><td>40.27137756347656</td><td>0.9967650771141052</td><td>3.345918655395508</td><td>0.6986624002456665</td><td>9.537246704101562</td></tr><tr><td><strong>6</strong></td><td>7.7856669425964355</td><td>0.5847676396369934</td><td>0.16681742668151855</td><td>2.469724655151367</td><td>0.1163589358329773</td><td>17.356531143188477</td><td>58.29198455810547</td><td>0.9969959259033203</td><td>3.3179354667663574</td><td>0.7273391485214233</td><td>9.588583946228027</td></tr><tr><td><strong>7</strong></td><td>7.4573211669921875</td><td>0.6121981739997864</td><td>0.09619349241256714</td><td>1.7426999807357788</td><td>0.10222429037094116</td><td>6.818210601806641</td><td>23.488229751586914</td><td>0.9965494871139526</td><td>3.371980667114258</td><td>0.671954870223999</td><td>9.489435195922852</td></tr><tr><td><strong>8</strong></td><td>7.416145324707031</td><td>0.6156381368637085</td><td>0.08733689785003662</td><td>1.651528239250183</td><td>0.10045129060745239</td><td>5.496661186218262</td><td>19.12369155883789</td><td>0.9964933395385742</td><td>3.378758430480957</td><td>0.6650094985961914</td><td>9.477001190185547</td></tr><tr><td><strong>9</strong></td><td>8.162923812866211</td><td>0.5532495975494385</td><td>0.2479609251022339</td><td>3.3050427436828613</td><td>0.1325981616973877</td><td>29.4645938873291</td><td>98.27996063232422</td><td>0.9975085854530334</td><td>3.2558419704437256</td><td>0.790972888469696</td><td>9.702510833740234</td></tr><tr><td><strong>10</strong></td><td>7.837402820587158</td><td>0.5804443955421448</td><td>0.17794525623321533</td><td>2.5842785835266113</td><td>0.11858469247817993</td><td>19.017019271850586</td><td>63.77589797973633</td><td>0.9970667362213135</td><td>3.309419870376587</td><td>0.736065685749054</td><td>9.604207992553711</td></tr><tr><td><strong>11</strong></td><td>8.162923812866211</td><td>0.5532495975494385</td><td>0.2479609251022339</td><td>3.3050427436828613</td><td>0.1325981616973877</td><td>29.4645938873291</td><td>98.27996063232422</td><td>0.9975085854530334</td><td>3.2558419704437256</td><td>0.790972888469696</td><td>9.702510833740234</td></tr><tr><td><strong>12</strong></td><td>7.787894248962402</td><td>0.5845809578895569</td><td>0.16729611158370972</td><td>2.474656105041504</td><td>0.11645263433456421</td><td>17.428016662597656</td><td>58.528072357177734</td><td>0.9969986081123352</td><td>3.3175694942474365</td><td>0.7277145385742188</td><td>9.589258193969727</td></tr><tr><td><strong>13</strong></td><td>7.510660648345947</td><td>0.6077421307563782</td><td>0.10766559839248657</td><td>1.86080002784729</td><td>0.10452044010162354</td><td>8.5300931930542</td><td>29.141878128051758</td><td>0.9966223239898682</td><td>3.36320161819458</td><td>0.6809513568878174</td><td>9.505542755126953</td></tr><tr><td><strong>14</strong></td><td>8.6254243850708</td><td>0.5146062970161438</td><td>0.34744104743003845</td><td>4.329127788543701</td><td>0.15250414609909058</td><td>44.3088264465332</td><td>147.3043670654297</td><td>0.9981393814086914</td><td>3.1797125339508057</td><td>0.8689867258071899</td><td>9.842171669006348</td></tr><tr><td><strong>15</strong></td><td>8.648824691772461</td><td>0.5126550197601318</td><td>0.3524749279022217</td><td>4.380934715270996</td><td>0.15351253747940063</td><td>45.05979919433594</td><td>149.78453063964844</td><td>0.9981704950332642</td><td>3.175861120223999</td><td>0.8729335069656372</td><td>9.849235534667969</td></tr><tr><td><strong>16</strong></td><td>8.21801471710205</td><td>0.5486437082290649</td><td>0.2598109543323517</td><td>3.4270362854003906</td><td>0.13496750593185425</td><td>31.232906341552734</td><td>104.11996459960938</td><td>0.9975836277008057</td><td>3.246772050857544</td><td>0.8002654314041138</td><td>9.719144821166992</td></tr><tr><td><strong>17</strong></td><td>7.7623491287231445</td><td>0.5867148041725159</td><td>0.1618022322654724</td><td>2.418093681335449</td><td>0.11535495519638062</td><td>16.608135223388672</td><td>55.820343017578125</td><td>0.996964156627655</td><td>3.3217735290527344</td><td>0.7234055995941162</td><td>9.581544876098633</td></tr><tr><td><strong>18</strong></td><td>7.503295421600342</td><td>0.6083576679229736</td><td>0.10608208179473877</td><td>1.844496250152588</td><td>0.10420334339141846</td><td>8.293763160705566</td><td>28.36137580871582</td><td>0.9966119527816772</td><td>3.3644134998321533</td><td>0.6797096133232117</td><td>9.503316879272461</td></tr><tr><td><strong>19</strong></td><td>7.7646636962890625</td><td>0.5865212678909302</td><td>0.16230028867721558</td><td>2.4232187271118164</td><td>0.11545407772064209</td><td>16.682422637939453</td><td>56.06568145751953</td><td>0.9969674348831177</td><td>3.321394205093384</td><td>0.7237967252731323</td><td>9.582244873046875</td></tr></table>
<thead><tr><DTh>idx</th><DTh>0</th><DTh>1</th><DTh>2</th><DTh>3</th><DTh>4</th><DTh>5</th><DTh>6</th><DTh>7</th><DTh>8</th><DTh>9</th><DTh>10</th></tr></thead><tr><td><strong>0</strong></td><td>7.283970832824707</td><td>0.6080970764160156</td><td>0.09878242015838623</td><td>2.999572277069092</td><td>0.07322776317596436</td><td>13.205937385559082</td><td>55.85588073730469</td><td>0.996724009513855</td><td>3.3934578895568848</td><td>0.5934497117996216</td><td>9.649285316467285</td></tr><tr><td><strong>1</strong></td><td>8.51345157623291</td><td>0.5254164934158325</td><td>0.2761821150779724</td><td>2.101888656616211</td><td>0.1593358963727951</td><td>23.790693283081055</td><td>68.28855895996094</td><td>1.0023800134658813</td><td>3.2120838165283203</td><td>0.898908793926239</td><td>9.709763526916504</td></tr><tr><td><strong>2</strong></td><td>7.325719833374023</td><td>0.6216638088226318</td><td>0.08386492729187012</td><td>2.8631138801574707</td><td>0.0653066337108612</td><td>13.201985359191895</td><td>54.19974136352539</td><td>1.0007377862930298</td><td>3.417975425720215</td><td>0.6265143752098083</td><td>9.65676212310791</td></tr><tr><td><strong>3</strong></td><td>8.441309928894043</td><td>0.5226936340332031</td><td>0.27888286113739014</td><td>1.879308819770813</td><td>0.16005785763263702</td><td>19.861663818359375</td><td>56.705780029296875</td><td>1.002282977104187</td><td>3.2176198959350586</td><td>0.9052612781524658</td><td>9.743077278137207</td></tr><tr><td><strong>4</strong></td><td>7.283970832824707</td><td>0.6080970764160156</td><td>0.09878242015838623</td><td>2.999572277069092</td><td>0.07322776317596436</td><td>13.205937385559082</td><td>55.85588073730469</td><td>0.996724009513855</td><td>3.3934578895568848</td><td>0.5934497117996216</td><td>9.649285316467285</td></tr><tr><td><strong>5</strong></td><td>7.5394463539123535</td><td>0.6927359104156494</td><td>0.008155465126037598</td><td>1.8375126123428345</td><td>0.041530102491378784</td><td>12.689216613769531</td><td>40.750614166259766</td><td>1.0118471384048462</td><td>3.5182597637176514</td><td>0.8267822265625</td><td>9.440389633178711</td></tr><tr><td><strong>6</strong></td><td>7.283970832824707</td><td>0.6080970764160156</td><td>0.09878242015838623</td><td>2.999572277069092</td><td>0.07322776317596436</td><td>13.205937385559082</td><td>55.85588073730469</td><td>0.996724009513855</td><td>3.3934578895568848</td><td>0.5934497117996216</td><td>9.649285316467285</td></tr><tr><td><strong>7</strong></td><td>8.244505882263184</td><td>0.5152651071548462</td><td>0.2862502336502075</td><td>1.272108554840088</td><td>0.16202840209007263</td><td>9.143200874328613</td><td>25.107738494873047</td><td>1.0020185708999634</td><td>3.2327258586883545</td><td>0.9225894212722778</td><td>9.833967208862305</td></tr><tr><td><strong>8</strong></td><td>7.283970832824707</td><td>0.6080970764160156</td><td>0.09878242015838623</td><td>2.999572277069092</td><td>0.07322776317596436</td><td>13.205937385559082</td><td>55.85588073730469</td><td>0.996724009513855</td><td>3.3934578895568848</td><td>0.5934497117996216</td><td>9.649285316467285</td></tr><tr><td><strong>9</strong></td><td>7.283970832824707</td><td>0.6080970764160156</td><td>0.09878242015838623</td><td>2.999572277069092</td><td>0.07322776317596436</td><td>13.205937385559082</td><td>55.85588073730469</td><td>0.996724009513855</td><td>3.3934578895568848</td><td>0.5934497117996216</td><td>9.649285316467285</td></tr><tr><td><strong>10</strong></td><td>7.283970832824707</td><td>0.6080970764160156</td><td>0.09878242015838623</td><td>2.999572277069092</td><td>0.07322776317596436</td><td>13.205937385559082</td><td>55.85588073730469</td><td>0.996724009513855</td><td>3.3934578895568848</td><td>0.5934497117996216</td><td>9.649285316467285</td></tr><tr><td><strong>11</strong></td><td>7.283970832824707</td><td>0.6080970764160156</td><td>0.09878242015838623</td><td>2.999572277069092</td><td>0.07322776317596436</td><td>13.205937385559082</td><td>55.85588073730469</td><td>0.996724009513855</td><td>3.3934578895568848</td><td>0.5934497117996216</td><td>9.649285316467285</td></tr><tr><td><strong>12</strong></td><td>7.283970832824707</td><td>0.6080970764160156</td><td>0.09878242015838623</td><td>2.999572277069092</td><td>0.07322776317596436</td><td>13.205937385559082</td><td>55.85588073730469</td><td>0.996724009513855</td><td>3.3934578895568848</td><td>0.5934497117996216</td><td>9.649285316467285</td></tr><tr><td><strong>13</strong></td><td>7.685879707336426</td><td>0.5709801912307739</td><td>0.22985637187957764</td><td>1.365044116973877</td><td>0.1827632337808609</td><td>9.859777450561523</td><td>29.22955894470215</td><td>0.9646010398864746</td><td>3.1961755752563477</td><td>0.8146190643310547</td><td>8.944458961486816</td></tr><tr><td><strong>14</strong></td><td>9.035935401916504</td><td>0.5451379418373108</td><td>0.2566196322441101</td><td>3.713893175125122</td><td>0.15410444140434265</td><td>52.24626922607422</td><td>152.17559814453125</td><td>1.0030827522277832</td><td>3.1719820499420166</td><td>0.8529068231582642</td><td>9.468478202819824</td></tr><tr><td><strong>15</strong></td><td>8.963213920593262</td><td>0.5423934459686279</td><td>0.2593427300453186</td><td>3.489549398422241</td><td>0.15483176708221436</td><td>48.28606033325195</td><td>140.50091552734375</td><td>1.0029853582382202</td><td>3.1775624752044678</td><td>0.8593087792396545</td><td>9.502055168151855</td></tr><tr><td><strong>16</strong></td><td>8.734748840332031</td><td>0.5337697863578796</td><td>0.2678978443145752</td><td>2.78464674949646</td><td>0.15712037682533264</td><td>35.842952728271484</td><td>103.8186264038086</td><td>1.0026774406433105</td><td>3.195098638534546</td><td>0.8794238567352295</td><td>9.607568740844727</td></tr><tr><td><strong>17</strong></td><td>8.397933006286621</td><td>0.5210561156272888</td><td>0.2805063724517822</td><td>1.7454839944839478</td><td>0.16049274802207947</td><td>17.499343872070312</td><td>49.74165725708008</td><td>1.0022245645523071</td><td>3.2209489345550537</td><td>0.9090796709060669</td><td>9.763108253479004</td></tr><tr><td><strong>18</strong></td><td>7.283970832824707</td><td>0.6080970764160156</td><td>0.09878242015838623</td><td>2.999572277069092</td><td>0.07322776317596436</td><td>13.205937385559082</td><td>55.85588073730469</td><td>0.996724009513855</td><td>3.3934578895568848</td><td>0.5934497117996216</td><td>9.649285316467285</td></tr><tr><td><strong>19</strong></td><td>8.45751667022705</td><td>0.5233052372932434</td><td>0.2782754898071289</td><td>1.9293084144592285</td><td>0.15989576280117035</td><td>20.744264602661133</td><td>59.30768585205078</td><td>1.0023049116134644</td><td>3.216377019882202</td><td>0.9038340449333191</td><td>9.735596656799316</td></tr></table>
2 changes: 1 addition & 1 deletion examples/autoencoders/encoded.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<table>
<thead><tr><th>idx</th><th>0</th><th>1</th></tr></thead><tr><td><strong>0</strong></td><td>2.5389764308929443</td><td>-8.392889976501465</td></tr><tr><td><strong>1</strong></td><td>4.668254852294922</td><td>-17.085620880126953</td></tr><tr><td><strong>2</strong></td><td>3.75606107711792</td><td>-13.361610412597656</td></tr><tr><td><strong>3</strong></td><td>4.130483627319336</td><td>-14.890182495117188</td></tr><tr><td><strong>4</strong></td><td>2.5389764308929443</td><td>-8.392889976501465</td></tr><tr><td><strong>5</strong></td><td>2.91636061668396</td><td>-9.933552742004395</td></tr><tr><td><strong>6</strong></td><td>4.038419723510742</td><td>-14.514333724975586</td></tr><tr><td><strong>7</strong></td><td>1.8713524341583252</td><td>-5.667331218719482</td></tr><tr><td><strong>8</strong></td><td>1.599593162536621</td><td>-4.55787992477417</td></tr><tr><td><strong>9</strong></td><td>6.528283596038818</td><td>-24.67914581298828</td></tr><tr><td><strong>10</strong></td><td>4.379877090454102</td><td>-15.908326148986816</td></tr><tr><td><strong>11</strong></td><td>6.528283596038818</td><td>-24.67914581298828</td></tr><tr><td><strong>12</strong></td><td>4.053119659423828</td><td>-14.574345588684082</td></tr><tr><td><strong>13</strong></td><td>2.2233786582946777</td><td>-7.104470252990723</td></tr><tr><td><strong>14</strong></td><td>9.580804824829102</td><td>-37.1409912109375</td></tr><tr><td><strong>15</strong></td><td>9.735233306884766</td><td>-37.77143859863281</td></tr><tr><td><strong>16</strong></td><td>6.891912937164307</td><td>-26.163654327392578</td></tr><tr><td><strong>17</strong></td><td>3.8845224380493164</td><td>-13.8860502243042</td></tr><tr><td><strong>18</strong></td><td>2.1747803688049316</td><td>-6.906069278717041</td></tr><tr><td><strong>19</strong></td><td>3.8997983932495117</td><td>-13.948413848876953</td></tr></table>
<thead><tr><DTh>idx</th><DTh>0</th><DTh>1</th></tr></thead><tr><td><strong>0</strong></td><td>-0.7835654616355896</td><td>0.6262750625610352</td></tr><tr><td><strong>1</strong></td><td>18.180845260620117</td><td>-15.350777626037598</td></tr><tr><td><strong>2</strong></td><td>-0.7429168224334717</td><td>0.5920295715332031</td></tr><tr><td><strong>3</strong></td><td>13.401049613952637</td><td>-11.3239164352417</td></tr><tr><td><strong>4</strong></td><td>-0.7835654616355896</td><td>0.6262750625610352</td></tr><tr><td><strong>5</strong></td><td>-0.3831104636192322</td><td>0.28890150785446167</td></tr><tr><td><strong>6</strong></td><td>-0.7835654616355896</td><td>0.6262750625610352</td></tr><tr><td><strong>7</strong></td><td>0.36166173219680786</td><td>-0.3385509252548218</td></tr><tr><td><strong>8</strong></td><td>-0.7835654616355896</td><td>0.6262750625610352</td></tr><tr><td><strong>9</strong></td><td>-0.7835654616355896</td><td>0.6262750625610352</td></tr><tr><td><strong>10</strong></td><td>-0.7835654616355896</td><td>0.6262750625610352</td></tr><tr><td><strong>11</strong></td><td>-0.7835654616355896</td><td>0.6262750625610352</td></tr><tr><td><strong>12</strong></td><td>-0.7835654616355896</td><td>0.6262750625610352</td></tr><tr><td><strong>13</strong></td><td>0.11124086380004883</td><td>-0.12757742404937744</td></tr><tr><td><strong>14</strong></td><td>52.79803466796875</td><td>-44.514915466308594</td></tr><tr><td><strong>15</strong></td><td>47.98031234741211</td><td>-40.45610046386719</td></tr><tr><td><strong>16</strong></td><td>32.84283447265625</td><td>-27.703144073486328</td></tr><tr><td><strong>17</strong></td><td>10.527204513549805</td><td>-8.902771949768066</td></tr><tr><td><strong>18</strong></td><td>-0.7835654616355896</td><td>0.6262750625610352</td></tr><tr><td><strong>19</strong></td><td>14.474761009216309</td><td>-12.22849178314209</td></tr></table>
11 changes: 4 additions & 7 deletions examples/autoencoders/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { parse } from "jsr:@std/[email protected]/parse";

const data = parse(
Deno.readTextFileSync("examples/autoencoders/winequality-red.csv"),
Deno.readTextFileSync("examples/autoencoders/winequality-red.csv")
);
data.shift();

Expand Down Expand Up @@ -49,7 +49,7 @@ const net = new Sequential({
const input = tensor(X);

const timeStart = performance.now();
net.train([{ inputs: input, outputs: input }], 10000, 1, 0.01);
net.train([{ inputs: input, outputs: tensor(Float32Array.from(input.data), input.shape) }], 10000, 1, 0.001);
console.log(`Trained in ${performance.now() - timeStart}ms`);

function saveTable(name: string, data: Matrix<"f32">) {
Expand All @@ -66,17 +66,14 @@ const output_mat = new Matrix<"f32">(output.data, output.shape as Shape2D);
saveTable("output", output_mat);

console.log("Running Encoder");
const encoded = await net.predict(input, [0, 5]);
const encoded = await net.predict(input, { layers: [0, 5] });

const encoded_mat = new Matrix<"f32">(encoded.data, encoded.shape as Shape2D);

saveTable("encoded", encoded_mat);

console.log("Running Decoder");
const decoded = await net.predict(tensor(encoded_mat), [
5,
10,
]);
const decoded = await net.predict(tensor(encoded_mat), { layers: [5, 10] });

const decoded_mat = new Matrix<"f32">(decoded.data, decoded.shape as Shape2D);

Expand Down
Loading

0 comments on commit 4614222

Please sign in to comment.