ããã®ããããªãã€ãæªèª¿æ»ã®ããšã¯ä»ã«ããããããã£ãŠãäžäŸã ã䜿çšããããœã³ã³ã«ãã£ãŠãèšç®çµæãéãã®ã ãåãããœã³ã³ã䜿ã£ãŠããéãåçŸæ§ã¯æºãããããªãã®ã ããçŸåšä¿æããŠããDELL17ã€ã³ãããŒããœãšLenovo15ã€ã³ãããŒããœã§çµæã«å·®ãåºããããããããã 64bit Windows10 Home ãªã®ã ããå éšè¡šçŸãéãã®ã Anaconda ã®ããŒãžã§ã³ãéãã®ãâŠããã¯èª¿æ»ããã°ãããããšã ãšæãããã
éã¿ã®åæå€ãããããå€ããŠè©ŠããŠããããããã³ã°ããã¹ãã ããããå€æ°ãå€ããç¯å²ãšå»ã¿ãã©ããããçã®æ¹éããŸã 決ãŸã£ãŠããªãã
ã¬ãŠã¹ååžä¹±æ°ã§ããã€ãè©ŠããŠããšããããã³ãªçµæãåºãæ°å€äŸããä»åã¯è²Œã£ãŠããã
ããã®ïŒãã®ã#ã³ãŒã4-0ãã®1å±€éã¿ W1 ãš2å±€éã¿ W2 ãã次ã®ããã«å€æŽãããnumpy ã®ã¬ãŠã¹ååžä¹±æ°ã¡ãœãã random.randn() ã§çæããçŽåŸã«ãã³ãããå€ãããã®ãŸãŸã³ãŒãã«çœ®ãæããã®ã ã
W1 = np.array([
[-0.00420782, -0.04331233, 0.12136818],
[-0.00953556, 0.01987206, 0.02593997]])
W2 = np.array([
[ 0.08212653, -0.04860534],
[-0.17150817, -0.30326033],
[-0.003902 , -0.0539731 ]])
ãã®åæå€ã䜿çšãããšãæ£ççã100%ã«ãªããªããæ倱é¢æ°ã®å€ããŒãè¿ãã«åæããªããã€ãŸãæä»çè«çåEORãå®çŸããã®ã«å€±æãããšããããšã ããšãã©ãããããããšãããã
ããã®ïŒãã#ã³ãŒã4-2ãã§äœæããæ£è§£çaccãšæ倱é¢æ°ã®å€lossã®ã°ã©ãã¯ããããªæãã«ãªãã
以äžããã€ãã®ããã«ããã®ïŒãã«èŒããã³ãŒãã§äœæããã°ã©ãã貌ã£ãŠããã
å·ŠïŒã#ã³ãŒã4-3ãã«ããW1ã®3Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-4ãã«ããW1ã®3é¢2Då±éå³é¢šã°ã©ãã
å·ŠïŒã#ã³ãŒã4-5ãã«ããb1ã®3Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-6ãã«ããb1ã®3é¢2Då±éå³é¢šã°ã©ãã
å·ŠïŒã#ã³ãŒã4-7ãã«ããW2ã®3Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-8ãã«ããW2ã®3é¢2Då±éå³é¢šã°ã©ãã
å·ŠïŒã#ã³ãŒã4-9ãã«ãããã€ã¢ã¹b2ã®2Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-2ãã«ããæ£è§£çãšæ倱é¢æ°ã®å€ã®ã°ã©ããåæ²ïŒã°ã©ãã®å€§ãããåãããããïŒã
ååèšäºããã®ïŒãã§ããããã£ãŠããªãã®ã«ãã¢ãã©ã¯ã¿ãŒããšããçšèªã䜿ããããªã£ãã®ã¯ãäžæ²ã°ã©ããšãããW1ã®3Dæãç·ã°ã©ããåšåè»éã«äŒŒãåãã瀺ããŠããããšãäžå ã§ããããã ãæ£è§£ç100%ã«ãªããªãã°ã©ããå¿ ããããã®ãããªåšåè»éãã©ãã®åããããããã§ã¯ãªãããããå調ãªåãã瀺ãããšãå€ããå®äŸã¯åŸæ¥ç€ºãããã
ã°ã©ãæç»åŸããªãã¡åŠç¿ã100åç¹°ãè¿ããåŸã§ãã³ãããW1ãb1ãW2ãb2ã®å€ã¯ã次ã®éãã ã£ãã
>>> W1
array([[1.71176211, 1.40439772, 5.15937839],
[1.71143204, 1.40486592, 5.15880418]])
>>> b1
array([5.35940066, 5.61089252, 1.85192825])
>>> W2
array([[-17.59943793, 17.63295912],
[-18.21478118, 17.74001268],
[-20.42315653, 20.36528143]])
>>> b2
array([ 55.77585749, -55.77585749])
ããã®æ°åã ãã§ã¯æå³ããšãã¥ããã®ã§ãååããã®ïŒããšåæ§ã®æ€ç®ãè©Šã¿ãããã ã Microsoft Mathematics ã¯ããžã¥ã¢ã«ããããŠãæäœãé¢åãªã®ã§ãPython 察話ã¢ãŒãã«æ°åŒãå ¥åããŠèšç®ãããããšã«ããã
ãã¥ãŒã©ã«ãããã¯ãŒã¯1å±€ç®ã®æŒç®çµæããã¥ãŒã©ã«ãããã¯ãŒã¯ã«é¢ããŠã¯ããã€ãã®ã¿ãæ¬ æè€åº·æ¯ ããŒãããäœãDeep Learningã(O'REILLY) 3ç« ã4ç« åç §ã
>>> np.dot(x_e,W1) + b1
array([[ 5.35940066, 5.61089252, 1.85192825],
[ 7.07116277, 7.01529024, 7.01130664],
[ 7.0708327 , 7.01575844, 7.01073243],
[ 8.78259481, 8.42015616, 12.17011081]])
ããã§ããããã«ããã®ã§ãã·ã°ã¢ã€ãé¢æ°ãåãŸããŠå°æ°ç¹ä»¥äž1æ¡ãŸã§äžžããŠã¿ããã·ã°ã¢ã€ãé¢æ°ã¯ããŒãããäœãDeep LearningãP45åç §ã
>>> Z1 = sigmoid(np.dot(x_e,W1) + b1)
>>> Z1
array([[0.9953183 , 0.99635553, 0.86435334],
[0.99915148, 0.99910276, 0.99909918],
[0.9991512 , 0.99910318, 0.99909867],
[0.99984664, 0.99977967, 0.99999482]])
>>> np.round(Z1,decimals=1)
array([[1. , 1. , 0.9],
[1. , 1. , 1. ],
[1. , 1. , 1. ],
[1. , 1. , 1. ]])
ãã®1å±€åºåããã©ãæãåããŠãEORã¯å®çŸã§ãããã«ãªãã
ã°ã©ããæç»ããããã°ã©ã ã§ã¯ãZ1ããã¥ãŒã©ã«ãããã¯ãŒã¯2å±€ç®ã«å ¥åããŠããã«ãœããããã¯ã¹é¢æ°ãåãŸããŠããããœããããã¯ã¹é¢æ°ã¯ããŒãããäœãDeep LearningãP66åç §ã
ãããã®æŒç®çµæã瀺ãã
>>> np.dot(Z1,W2) + b2
array([[ 2.45759337, -2.94729187],
[-0.41184405, -0.08682869],
[-0.41183621, -0.08683671],
[-0.45470003, -0.04432262]])
>>> softmax(np.dot(Z1,W2) + b2)
array([[0.99552554, 0.00447446],
[0.41945396, 0.58054604],
[0.41945782, 0.58054218],
[0.39882163, 0.60117837]])
äžåºŠããã argmax() ãåãŸããçµæã衚瀺ããŠã¿ãããã¡ãã£ãšã¯ãããããããªããªãã ãããïŒ
>>> y = softmax(np.dot(Z1,W2) + b2)
>>> np.argmax(y, axis=1)
array([0, 1, 1, 1], dtype=int64)
æ£ãã㯠[0, 1, 1, 0] ãšè¡šç€ºãããªããã°ãªããªãã
ä»åã¯åæããªãã£ãããçµæãã¯ã±ããããªããã次ããã¯ããããªãã§ããªãçµæãåºãŠããã®ã§ãé·ã ãšæžããã®ã¯æ¯èŒçšã§ããã
ãŒãããäœãDeep Learning âPythonã§åŠã¶ãã£ãŒãã©ãŒãã³ã°ã®çè«ãšå®è£
- äœè :æè€ åº·æ¯
- çºå£²æ¥: 2016/09/24
- ã¡ãã£ã¢: åè¡æ¬ïŒãœããã«ããŒïŒ
ç¶ããŠããã®åæå€ãå°æ°ç¹ä»¥äž7æ¡ã«äžžããŠã¿ãã
>>> W1 = np.round(W1, decimals=7)
>>> W2 = np.round(W2, decimals=7)
>>>
>>> W1
array([[-0.0042078, -0.0433123, 0.1213682],
[-0.0095356, 0.0198721, 0.02594 ]])
>>> W2
array([[ 0.0821265, -0.0486053],
[-0.1715082, -0.3032603],
[-0.003902 , -0.0539731]])
ãããããšããªããšæ£è§£ç100%ãè©äŸ¡é¢æ°ã®å€ãŒãä»è¿ã«åæããŠããŸãã®ã ïŒ
å·ŠïŒã#ã³ãŒã4-3ãã«ããW1ã®3Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-4ãã«ããW1ã®3é¢2Då±éå³é¢šã°ã©ãã
å·ŠïŒã#ã³ãŒã4-5ãã«ããb1ã®3Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-6ãã«ããb1ã®3é¢2Då±éå³é¢šã°ã©ãã
å·ŠïŒã#ã³ãŒã4-7ãã«ããW2ã®3Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-8ãã«ããW2ã®3é¢2Då±éå³é¢šã°ã©ãã
å·ŠïŒã#ã³ãŒã4-9ãã«ãããã€ã¢ã¹b2ã®2Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-2ãã«ããæ£è§£çãšæ倱é¢æ°ã®å€ã®ã°ã©ãã
ã芧ã®éãåæå€ã®å°æ°ç¹ä»¥äž8æ¡ç®ãäžžããã ãã§ãæ£è§£ç100%æ倱é¢æ°ã®å€ãŒãä»è¿ã«åæãããšããåçãªå€åãèŠãããäžžããªãã£ãå Žåãšã®å·®ã¯äžåäžåã®äžä»¥äžã§ããïŒ
ã°ã©ãæç»åŸã®W1ãb1ãW2ãb2ã®ãã³ãã
>>> W1
array([[ 0.15566959, -3.62609222, 4.41335946],
[ 0.15508861, -3.62582171, 4.41213812]])
>>> b1
array([ 4.61571949, 6.2275166 , -0.49241919])
>>> W2
array([[ -8.68490772, 8.71842892],
[ -9.37837986, 8.90361136],
[-10.95008053, 10.89220543]])
>>> b2
array([ 25.00004968, -25.00004968])
äžæ²å€ãçšãã1å±€åºå Z1 = sigmoid(np.dot(x_e,W1) + b1) ã®æ€ç®ã
>>> np.dot(x_e,W1) + b1
array([[ 4.61571949, 6.2275166 , -0.49241919],
[ 4.77138908, 2.60142438, 3.92094027],
[ 4.77080811, 2.60169489, 3.91971893],
[ 4.92647769, -1.02439733, 8.33307838]])
>>> Z1 = sigmoid(np.dot(x_e,W1) + b1)
>>> Z1
array([[0.99020189, 0.99802954, 0.37932383],
[0.99160251, 0.93095319, 0.98056284],
[0.99159767, 0.93097058, 0.98053955],
[0.99280021, 0.26417174, 0.99975963]])
Z1 ãå°æ°ç¹ä»¥äž1æ¡è¡šç€ºããŠã¿ãã
>>> np.round(Z1,decimals=1)
array([[1. , 1. , 0.4],
[1. , 0.9, 1. ],
[1. , 0.9, 1. ],
[1. , 0.3, 1. ]])
1åç®ãäœå°æ¬¡å ã§ã2åç®ãš3åç®ã§ EOR ãå®çŸããããšããŠããããšãæšå¯ãããããäœå°æ¬¡å ããšããèšèã¯ã次局ãžã®åœ±é¿ãå°ããããªåããšããã»ã©ã®æå³ã§äœ¿ã£ãŠããŸãã
念ã®ãã2å±€åºåããã³åºåã« argmax() ãåãŸããçµæãã
>>> np.dot(Z1,W2) + b2
array([[ 2.88671093, -3.34930457],
[-3.0800014 , 2.61450368],
[-3.07986738, 2.61436259],
[ 2.95272011, -3.10272186]])
>>> softmax(np.dot(Z1,W2) + b2)
array([[0.99804618, 0.00195382],
[0.00335312, 0.99664688],
[0.00335404, 0.99664596],
[0.99766042, 0.00233958]])
>>> y = softmax(np.dot(Z1,W2) + b2)
>>> np.argmax(y, axis=1)
array([0, 1, 1, 0], dtype=int64)
[0, 1, 1, 0]ãæ£è§£ããŠããã
ãŒãããäœãDeep Learning â· âèªç¶èšèªåŠçç·š
- äœè :æè€ åº·æ¯
- çºå£²æ¥: 2018/07/21
- ã¡ãã£ã¢: åè¡æ¬ïŒãœããã«ããŒïŒ
åæå€6æ¡äžžããš5æ¡äžžãã®ããŒã¿ãæ¡ã£ããã7æ¡ã®ã±ãŒã¹ãšäŒŒéã£ãŠããã®ã§çç¥ãããçµæãæ¿ããå€åããã®ã4æ¡äžžããš3æ¡äžžãã®ã±ãŒã¹ã ã£ããå·®ã倧ããããå€åããŠåœç¶ãšããèŠæ¹ãã§ãããããããã§ã4æ¡ã§1äžåã®1ã3æ¡ã§ååã®1以äžã®å·®ã§ããã
4æ¡ã§äžžããã±ãŒã¹ã
>>> W1 = np.round(W1, decimals=4)
>>> W2 = np.round(W2, decimals=4)>>> W1
array([[-0.0042, -0.0433, 0.1214],
[-0.0095, 0.0199, 0.0259]])
>>> W2
array([[ 0.0821, -0.0486],
[-0.1715, -0.3033],
[-0.0039, -0.054 ]])
å·ŠïŒã#ã³ãŒã4-3ãã«ããW1ã®3Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-4ãã«ããW1ã®3é¢2Då±éå³é¢šã°ã©ãã
å·ŠïŒã#ã³ãŒã4-5ãã«ããb1ã®3Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-6ãã«ããb1ã®3é¢2Då±éå³é¢šã°ã©ãã
å·ŠïŒã#ã³ãŒã4-7ãã«ããW2ã®3Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-8ãã«ããW2ã®3é¢2Då±éå³é¢šã°ã©ãã
å·ŠïŒã#ã³ãŒã4-9ãã«ãããã€ã¢ã¹b2ã®2Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-2ãã«ããæ£è§£çãšæ倱é¢æ°ã®å€ã®ã°ã©ãã
åã åããã®ïŒããããã§ã¯å°å³ã ã£ãb1ãW2ã®ã°ã©ãã®åããæ¿ãããä»åã¯ã©ãããããã
ã°ã©ãæç»åŸã®W1ãb1ãW2ãb2ã®ãã³ãã
>>> W1
array([[-0.5733437 , -3.00341978, 3.54293311],
[ 0.58475128, 2.82789074, -3.73600438]])
>>> b1
array([3.18836141, 2.22843679, 2.34602933])
>>> W2
array([[ 5.54385952, -5.51035952],
[ 5.69392689, -6.16872689],
[ 5.15003454, -5.20793454]])
>>> b2
array([-13.74932189, 13.74932189])
1å±€åºå Z1 = sigmoid(np.dot(x_e,W1) + b1) ã®å°æ°ç¹ä»¥äž1æ¡è¡šç€ºã
>>> Z1 = sigmoid(np.dot(x_e,W1) + b1)
>>> np.round(Z1,decimals=1)
array([[1. , 0.9, 0.9],
[0.9, 0.3, 1. ],
[1. , 1. , 0.2],
[1. , 0.9, 0.9]])
1è¡ç®ãäœå°æ¬¡å ã®ãããªã®ã¯ãããšããŠã2è¡ç®ãš3è¡ç®ã§EORãå®çŸããããšããæ¹æ³ãã7æ¡äžžãã®ãšããšç°ãªã£ãŠããã
ããªãã¡7æ¡äžžãã®ãšãã¯2åç®ãš3åç®ãANDæŒç®ããŠãããã®ããã ãããã®4æ¡äžžãã§ã¯NANDæŒç®ããŠããããã«èŠããã
4æ¡äžžããš7æ¡äžžãã§ã¯ç°ãªãã¢ãã©ã¯ã¿ãŒã«åŒãå¯ããããŠãããšè¡šçŸããŠããã®ã§ã¯ãªãã ããããã¢ãã©ã¯ã¿ãŒãäžæ£ç¢ºãªèšãæ¹ãªã®ã§ãç®æšãšããåæå€ããªã©ãšèšãæããæ¹ãå€å°ã¯ãã·ããã ãã
2å±€ç®åºåãš argmax()ãçµæã¯åãã§ããã
>>> np.dot(Z1,W2) + b2
array([[ 1.41531244, -1.86461704],
[-1.65174635, 1.47546936],
[-1.64513101, 1.19453733],
[ 1.23769924, -1.67817407]])
>>> softmax(np.dot(Z1,W2) + b2)
array([[0.96373382, 0.03626618],
[0.04199849, 0.95800151],
[0.05521784, 0.94478216],
[0.94862556, 0.05137444]])
>>> y = softmax(np.dot(Z1,W2) + b2)
>>> np.argmax(y, axis=1)
array([0, 1, 1, 0], dtype=int64)
ãŒãããäœãDeep Learning âž âãã¬ãŒã ã¯ãŒã¯ç·š
- äœè :æè€ åº·æ¯
- çºå£²æ¥: 2020/04/20
- ã¡ãã£ã¢: åè¡æ¬ïŒãœããã«ããŒïŒ
3æ¡ã§äžžããã±ãŒã¹ã
>>> W1 = np.round(W1, decimals=3)
>>> W2 = np.round(W2, decimals=3)>>> W1
array([[-0.004, -0.043, 0.121],
[-0.01 , 0.02 , 0.026]])
>>> W2
array([[ 0.082, -0.049],
[-0.172, -0.303],
[-0.004, -0.054]])
å·ŠïŒã#ã³ãŒã4-3ãã«ããW1ã®3Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-4ãã«ããW1ã®3é¢2Då±éå³é¢šã°ã©ãã
å·ŠïŒã#ã³ãŒã4-5ãã«ããb1ã®3Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-6ãã«ããb1ã®3é¢2Då±éå³é¢šã°ã©ãã
å·ŠïŒã#ã³ãŒã4-7ãã«ããW2ã®3Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-8ãã«ããW2ã®3é¢2Då±éå³é¢šã°ã©ãã
å·ŠïŒã#ã³ãŒã4-9ãã«ãããã€ã¢ã¹b2ã®2Dæãç·ã°ã©ãã
å³ïŒã#ã³ãŒã4-2ãã«ããæ£è§£çãšæ倱é¢æ°ã®å€ã®ã°ã©ãã
ã°ã©ãæç»åŸã®W1ãb1ãW2ãb2ã®ãã³ãã
>>> W1
array([[ 3.76666159, -2.17278522, -4.22211443],
[-2.11128289, 3.81356837, -4.28411122]])
>>> b1
array([2.13895947, 2.19372889, 1.55502881])
>>> W2
array([[ 13.5655765 , -13.5325765 ],
[ 13.31123554, -13.78623554],
[ 4.06164038, -4.11964038]])
>>> b2
array([-23.99379003, 23.99379003])
1å±€åºå Z1 ã®å°æ°ç¹ä»¥äž1æ¡è¡šç€ºã
>>> np.round(Z1,decimals=1)
array([[0.9, 0.9, 0.8],
[1. , 0.5, 0.1],
[0.5, 1. , 0.1],
[1. , 1. , 0. ]])
ããã¯äœãããŠãããã ããïŒ 1åç®ãš2åç®ã®NANDã䜿ã£ãŠ3åç®ã¯äœå°æ¬¡å ïŒ ããã«ããŠã¯ããªãŒãã ã
ãããäœå°æ¬¡å ã¯2å±€ç®ã®è¡åæŒç®ã§ç¡èŠã§ããã°ããã®ã ãããããšããš 0 ãŸã㯠1 ã«æããå¿ èŠæ§ã¯ãªãããã«æãããã
2å±€åºåãš argmax()ãçµæã¯åã£ãŠããã®ã ãã
>>> np.dot(Z1,W2) + b2
array([[ 3.47178286, -3.91749739],
[-3.47597717, 3.26513381],
[-3.58969204, 3.12903216],
[ 2.30683187, -2.73956496]])
>>> softmax(np.dot(Z1,W2) + b2)
array([[9.99382541e-01, 6.17458987e-04],
[1.17994009e-03, 9.98820060e-01],
[1.20662080e-03, 9.98793379e-01],
[9.93608643e-01, 6.39135684e-03]])
>>> y = softmax(np.dot(Z1,W2) + b2)
>>> np.argmax(y, axis=1)
array([0, 1, 1, 0], dtype=int64)
ã¹ãã³ãµãŒãªã³ã¯