{"id":71802,"student_id":10,"content":"var a = createSprite(\"b.png\");\na.moveTo(100, 50);\n\nvar b = createSprite(\"b.png\");\nb.direction = 0;\nb.moveTo(40, 110);\n\nvar c = createSprite(\"b.png\");\nc.direction = 0;\nc.moveTo(160, 110);\n\nvar d = createSprite(\"b.png\");\nd.moveTo(100, 170);\n\nvar e = createSprite(\"b.png\");\ne.direction = 0;\ne.moveTo(40, 230);\n\nvar f = createSprite(\"b.png\");\nf.direction = 0;\nf.moveTo(160, 230);\n\nvar g = createSprite(\"b.png\");\ng.moveTo(100, 290);\n\nvar blocks = [a, b, c, d, e, f, g];\nvar inputs = [0, 0, 0, 0, 0, 0, 0];\nvar weights = [\n [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],\n [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],\n [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],\n [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],\n [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],\n [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],\n [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],\n [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],\n [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],\n [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],\n]\n\nblocks.forEach((b) =\u003e {\n b.on('click', () =\u003e {\n b.opacity = b.opacity == 1 ? 0.2: 1;\n });\n});\n\n\n\nforever(function() {\n var data = blocks.map((b) =\u003e {\n return b.opacity == 1 ? 1: 0;\n });\n inputs = data;\n\n var output = NN(data, weights);\n \n for (var i=0; i\u003c10; i++) {\n print(output[i], 400, 200 + 15*i);\n }\n print(output.indexOf(Math.max(...output)), 400, 400, 'red');\n});\n\n\nfunction NN (inputs, weights) {\n var i = inputs;\n var arr = weights.map((w) =\u003e {\n return i[0]*w[0] + i[1]*w[1] + i[2]*w[2] + i[3]*w[3] + i[4]*w[4] + i[5]*w[5] + i[6]*w[6];\n });\n return arr.map(sigmoid);\n}\n\n\nfunction train (inputs, target) {\n var output = NN(inputs, weights);\n \n for (var i=0; i\u003c10; i++) {\n var lose = target[i] - output[i];\n var error = lose*dsigmoid(output[i]);\n \n for (var j=0; j\u003c7; j++) {\n weights[i][j] = weights[i][j] + 0.2*inputs[j]*error;\n }\n }\n}\n\nvar d = [\n [[1, 1, 1, 0, 1, 1, 1], [1,-1,-1,-1,-1,-1,-1,-1,-1,-1]], // 0\n [[0, 0, 1, 0, 0, 1, 0], [-1,1,-1,-1,-1,-1,-1,-1,-1,-1]], // 1\n [[1, 0, 1, 1, 1, 0, 1], [-1,-1,1,-1,-1,-1,-1,-1,-1,-1]], // 2\n [[1, 0, 1, 1, 0, 1, 1], [-1,-1,-1,1,-1,-1,-1,-1,-1,-1]], // 3\n [[0, 1, 1, 1, 0, 1, 0], [-1,-1,-1,-1,1,-1,-1,-1,-1,-1]], // 4\n [[1, 1, 0, 1, 0, 1, 1], [-1,-1,-1,-1,-1,1,-1,-1,-1,-1]], // 5\n [[1, 1, 0, 1, 1, 1, 1], [-1,-1,-1,-1,-1,-1,1,-1,-1,-1]], // 6\n [[1, 1, 1, 0, 0, 1, 0], [-1,-1,-1,-1,-1,-1,-1,1,-1,-1]], // 7\n [[1, 1, 1, 1, 1, 1, 1], [-1,-1,-1,-1,-1,-1,-1,-1,1,-1]], // 8\n [[1, 1, 1, 1, 0, 1, 0], [-1,-1,-1,-1,-1,-1,-1,-1,-1,1]], // 9\n];\n\nfor (var i=0; i\u003c10; i++) {\n d.forEach((arr) =\u003e {\n train(arr[0], arr[1]);\n });\n}\n\n\n","created_at":"2019-06-12T18:37:49.224+08:00","updated_at":"2019-11-01T19:55:56.623+08:00","name":"七段顯示器辨識","language":"javascript","screenshot":{"url":"https://cdn7.koding.school/uploads/project/screenshot/71802/424817ca0ae4f0ce81adb16469a51ec2.jpg"},"parent_id":2,"plugin":"// sigmoid(x)=tanh(x)\nfunction sigmoid(x) {\n var tanh = (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x));\n return tanh; // 雙曲正切函數\n}\n\n// dsigmoid(x)=1-x^2;\n// 參考:http://pynopticon.googlecode.com/svn/trunk/src/vlfeat/toolbox/special/dsigmoid.m\n// 參考:http://en.wikipedia.org/wiki/Sigmoid_function\nfunction dsigmoid(x) {\n return 1.0 - x*x;\n}","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":326,"hashid":"yeysrj9g","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":1254144,"file_name":"b.png","project_id":71802,"asset_id":125966,"created_at":"2019-06-12T18:40:59.302+08:00","updated_at":"2019-06-12T18:41:40.269+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦