{"id":73512,"student_id":10,"content":"// noprotect\nfunction sigmoid(x) {\n var tanh = (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x));\n return tanh; // 雙曲正切函數\n}\nfunction dsigmoid(x) {\n return 1.0 - x*x;\n}\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[20] = 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 j = 0; j \u003c n2; j++) {\n var sum = 0;\n for (var i = 0; i \u003c n1; i++) {\n sum += a1[i]*w12[i][j];\n }\n a2[j] = sigmoid(sum);\n }\n for (var j = 0; j \u003c n3; j++) {\n var sum = 0;\n for (var i = 0; i \u003c n2; i++) {\n sum += a2[i]*w23[i][j];\n }\n a3[j] = sigmoid(sum);\n }\n}\n\nfunction backPropagate(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\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(() =\u003e {\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},0,0)`;\n pen.drawCircle(posX, posY, 7);\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\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},0,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},0,0)`;\n pen.drawCircle(posX, posY, 7);\n }\n\n var max = Math.max(...a3);\n print('數字:' + a3.indexOf(max), 500, 350, 'red');\n});\n\nfunction clear () {\n for (var i = 0; i \u003c n1 - 1; i++) {\n a1[i] = -1;\n }\n}\nwhen('keydown', 'c', clear);\nclear();\nsetInterval(update, 1000);\n\nvar data = [];\nwhen('keydown', 'a', () =\u003e {\n var inputs = a1.slice(0, a1.length);\n var target = [-1, -1, -1];\n var n = Number(prompt('數字?'));\n target[n] = 1;\n data.push([inputs, target]);\n clear();\n});\n\nwhen('keydown', 't', function () {\n for (var i = 0; i \u003c 100; i++) {\n data.forEach((d) =\u003e {\n a1 = d[0].map((n) =\u003e n);\n update();\n backPropagate(d[1]);\n });\n }\n});","created_at":"2019-06-21T16:52:10.889+08:00","updated_at":"2019-11-01T13:34:39.977+08:00","name":"圖像手寫辨識","language":"javascript","screenshot":{"url":"https://cdn3.koding.school/uploads/project/screenshot/73512/311ace2cfd2fbfd6d9e4c0a299dbf3f5.jpg"},"parent_id":71800,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":326,"hashid":"rdvsmqyr","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
到這台電腦