{"id":73517,"student_id":10,"content":"\nsetBackdrop(\"black\");\n\nvar n1 = 625 + 1;\nvar n2 = 20 + 1;\nvar n3 = 3;\nvar a1 = [];\nvar a2 = [];\nvar a3 = [];\nvar w12 = [];\nvar w23 = [];\n\na1[625] = 1;\na2[10] = 1;\n\nfor (var i = 0; i \u003c n1; i++) {\n w12[i] = [];\n for (var j = 0; j \u003c n2; j++) {\n w12[i][j] = Math.random() - 0.5;\n }\n}\nfor (var i = 0; i \u003c n2; i++) {\n w23[i] = [];\n for (var j = 0; j \u003c n3; j++) {\n w23[i][j] = Math.random() - 0.5;\n }\n}\n\nfunction update () {\n for (var i = 0; i \u003c n2; i++) {\n var sum = 0;\n for (var j = 0; j \u003c n1; j++) {\n sum += w12[j][i]*a1[j];\n }\n a2[i] = sigmoid(sum);\n }\n for (var i = 0; i \u003c n3; i++) {\n var sum = 0;\n for (var j = 0; j \u003c n2; j++) {\n sum += w23[j][i]*a2[j];\n }\n a3[i] = sigmoid(sum);\n }\n}\nforever(update);\n\nfunction train (targets) {\n var rate = 0.2;\n var deltas3 = [];\n for (var k = 0; k \u003c n3; k++) {\n var error = targets[k]-a3[k];\n deltas3[k] = dsigmoid(a3[k])*error;\n }\n var deltas2 = [];\n for (var j = 0; j \u003c n2; j++) {\n var error = 0;\n for (var k = 0; k \u003c n3; k++) {\n error += deltas3[k]*w23[j][k];\n }\n deltas2[j] = dsigmoid(a2[j]) * error;\n }\n for (var j = 0; j \u003c n2; j++) {\n for (var k = 0; k \u003c n3; k++) {\n var change = deltas3[k]*a2[j];\n w23[j][k] += rate*change\n }\n }\n for (var j = 0; j \u003c n1; j++) {\n for (var k = 0; k \u003c n2; k++) {\n var change = deltas2[k]*a1[j];\n w12[j][k] += rate*change\n }\n }\n}\n\n\nforever(function() {\n\n // pen.size = 0;\n pen.color = '#fff';\n\n for (var x = 0; x \u003c 25; x++) {\n for (var y = 0; y \u003c 25; y++) {\n var deep = (a1[y*25 + x] + 1)*128;\n var posX = x*13 + 100;\n var posY = y*13 + 20;\n pen.fillColor = `rgb(${deep},${deep},0)`;\n pen.drawCircle(posX, posY, 7);\n\n if (cursor.isDown) {\n var d = Math.sqrt((cursor.x - posX)**2 + (cursor.y - posY)**2);\n var l = (30 - d)/15 - 1;\n if (d \u003c 30 \u0026\u0026 a1[y*25 + x] \u003c l) {\n a1[y*25 + x] = l;\n }\n }\n }\n }\n for (var x = 0; x \u003c n2; x++) {\n var deep = (a2[x] + 1)*128;\n var posX = x*13 + 100;\n var posY = 350;\n pen.fillColor = `rgb(${deep},${deep},0)`;\n pen.drawCircle(posX, posY, 7);\n }\n\n for (var x = 0; x \u003c n3; x++) {\n var deep = (a3[x] + 1)*128;\n var posX = x*13*3 + 100;\n var posY = 400;\n pen.fillColor = `rgb(${deep},${deep},0)`;\n pen.drawCircle(posX, posY, 7);\n }\n\n print(a3.indexOf(Math.max(...a3)))\n\n});\n\nvar data = [];\nwhen('keydown', 'a', () =\u003e {\n var inputs = a1.slice(0, a1.length);\n var target = [-1, -1, -1];\n target[prompt('0, 1, 2 ?')] = 1;\n data.push([inputs, target]);\n clear();\n});\n\nwhen('keydown', 't', () =\u003e {\n for (var c = 0; c \u003c 1; c++) {\n data.forEach((d) =\u003e {\n for (var i = 0; i \u003c n1; i++) {\n a1[i] = d[0][i];\n }\n update();\n train(d[1]);\n clear();\n });\n }\n});\n\nwhen('keydown', 'c', clear);\nfunction clear () {\n for (var i = 0; i \u003c 625; i++) {\n a1[i] = -1;\n }\n}\nclear();","created_at":"2019-06-21T17:59:46.313+08:00","updated_at":"2019-11-01T19:38:26.815+08:00","name":"影像辨識","language":"javascript","screenshot":{"url":"https://cdn6.koding.school/uploads/project/screenshot/73517/b27118095628728e830f56f178b1e2af.jpg"},"parent_id":2,"plugin":"function sigmoid(x) {\n return (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x));\n}\n\nfunction dsigmoid(x) {\n return 1.0 - x*x;\n}","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":306,"hashid":"p93smp69","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦