å¿çšæ°çç§åŠã®è±åœ¢ã§ããæ©æ¢°åŠç¿ãšãããžã£ã³ã«ã§ããããåºæ¬äžã®åºæ¬ã§ããEORåè·¯ãå®çŸããããšããã®ã ãããå è¡ç 究ããªãããããªããšã¯æãã®ã ããèªåã®è¶£å³ã§ãã£ãŠããã®ã§ããããšã«ããã
Â
ãžã§ã€ã ãºã»ã°ãªãã¯ãã«ãªã¹âæ°ããç§åŠãã€ããã(æ°æœ®æ庫)ãããæ°è±¡åŠè ã®ãšãã¯ãŒãã»ããŒã¬ã³ããããã¿ãã©ã€å¹æããããã¯ãã«ãªã¹ããšåŒã°ããçŸè±¡ãçºèŠããç¬éã®èšè¿°ãæãåºããã
ãäžä¹å äžå¹Žå¬ã®ããæ¥ã®ããšãäžåºåãã®ããŒã¿ããã£ãšå¿µå ¥ãã«èª¿ã¹ãããšæã£ãããŒã¬ã³ãã¯ãè¿éãããããšã«ãããæéãç¯çŽããããå§ãã®éšåãã¯ããã£ãŠãäžéããåŠçãå§ããããšã«ããã®ã§ããããŸãæåã®æ¡ä»¶ãã³ã³ãã¥ãŒã¿ã«å ¥ããŠãããããåã«ãšã£ãããªã³ãã¢ãŠãã®æ°åããã£ãããã®ãŸãŸã¿ã€ãããŠãããã³ã³ãã¥ãŒã¿ã®éšé³ãéããŠã³ãŒããŒãã®ãããå»äžã«åºããå°äžæéã»ã©ããŠéšå±ã«æ»ã£ã圌ã¯ããŸã£ããæãããªããã®ããŸãã«æ°ããç§åŠã®çš®ãããã«æãããŠããã®ãèŠãã®ã§ããã
ããã£ãããŒã¬ã³ããèªåã§æ°åã®äžå®äžåããã£ãããã®ãŸãŸã³ã³ãã¥ãŒã¿ã«æã¡ãã¿ãå¥ã«ããã°ã©ã ãå€ããããã§ã¯ãªãã®ã ããããã®çµæãåã®ãšå šãåãã«ãªãã¯ãã ã€ãããšãããä»ãæ°ããããªã³ãã¢ãŠããèŠã€ããããŒã¬ã³ãã®çŒåã«ããæ¡ããããŠããã®ã¯ããã£ãæ°ã«æåã®å€©åã®ãã¿ãŒã³ãªã®ã«ãããã以åã®ãã®ãšã¯äŒŒãŠã䌌ã€ãã¬ãã®ã«ãªãã»ã©ã®é床ã§ãããŠè¡ãããŸã ã£ãã
âªäžç¥â«
ãã ã次ã®ç¬éã圌ã¯ã¯ã£ãšæ¬åœã®ããšã«æ°ãã€ãããæ©æ¢°ãçã£ãã®ã§ã¯ãªããå®ã¯åœŒãæã¡ããã æ°åã®æ¹ã«åé¡ããã£ãã®ã ãã³ã³ãã¥ãŒã¿ã®ã¡ã¢ãªãŒã®äžã«ã¯.506127ãšããå æ¡ã®æ°åãèšæ¶ãããŠããããçŽé¢ãå¹çŽããããããªã³ãã¢ãŠãã«ã¯.506ã®äžæ¡ããå°å·ãããªããã ãååã®äžããããªã倧ãã誀差ã§ã¯ãªããšæã£ãããŒã¬ã³ãã¯ãåæšäºå ¥ããŠçããããã®äžæ¡ã®æ°åããã®ãŸãŸæã¡ããã ã®ã ã
ã第1ç« ãã¿ãã©ã€å¹æãP33ïœ34ãããæ¹è¡äœçœ®å€æŽããŠããŸããã«ãçç¥ããŠããŸãã
ãã¿ãã©ã€å¹æãšã¯åæå€ã®ããããªéããçµæã«ç倧ãªåœ±é¿ãããããçŸè±¡ãã«ãªã¹ãšã¯ç°¡æã«èšè¿°ã§ããç³»ããäºæž¬å°é£ãªçµæãåºãŠããçŸè±¡ããšãããµãã«ç解ããŠããŸãããééã£ãŠããã誰ãæããŠãã ããã
 Â
ããŒã¬ã³ãã®ã²ãã¿ã«å£ã£ãŠããã³ããããW1ãW2ã®å€ãåæå€ãšããŠã³ãŒãäžã«èšè¿°ããPython ã®ã©ã€ãã©ãª numpy ã® round ã¡ãœããã䜿ã£ãŠãåæ¡ã§äžžããŠã¿ãã
ãã©ã¡ãŒã¿ã®æ°ã 8ïŒ8ïŒéã¿W1ã®åœ¢ç¶2Ã4ãW2ã®åœ¢ç¶4Ã2ã®å ŽåïŒãšå€ããã©ãããæãã€ãããããã®ãå³åº§ã«å€æä»ããªãã£ãã®ã§ãæ軜ã«å€æŽãã工倫ã®ã€ããã ã£ãã
ããªãã¡ååã®ãšã³ããªãŒã«èšè¿°ãããã³ãŒã4ããã次ã®ããã«æ¹é ããŠâŠ
#ã³ãŒã4-1
import sys, os
sys.path.append(os.pardir)
import numpy as np
from common.functions import *
from common.gradient import numerical_gradientx_e = np.array([[0, 0], [1, 0], [0, 1], [1, 1]]) #å ¥åããŒã¿
t_e = np.array([[1, 0], [0, 1], [0, 1], [1, 0]]) #æåž«ããŒã¿W1 = np.array([[ 0.007111976, 0.008841753, 0.016924526, -0.022701769],
[-0.018342164, -0.000087162, 0.016726299, 0.021702541]])
W2 = np.array([[ 0.013091743, -0.003338104],
[-0.013076172, 0.00560719 ], [ 0.013749352, 0.000776133],
[ 0.000917579, 0.016105434]])
b1, b2 = np.zeros(4), np.zeros(2) #ãŒãã§åæådef predict(x):
  A1 = np.dot(x,W1) + b1
  Z1 = sigmoid(A1) #ã·ã°ã¢ã€ãé¢æ°P48
  A2 = np.dot(Z1,W2) + b2
  y = softmax(A2) #ãœããããã¯ã¹é¢æ°P66
  return yÂ
 W1ãšW2ã®å€ãã次ã®ããã«äžžããã
W1 = np.round(W1, decimals=7)
W2 = np.round(W2, decimals=7)Â
round ã¡ãœããã® decimarl ãªãã·ã§ã³ã¯ãäžžããå°æ°ç¹ä»¥äžã®æ¡æ°ã®æå®ã§ãããÂ
ã«ãªã¹âæ°ããç§åŠãã€ãã (æ°æœ®æ庫)
- äœè :ãžã§ã€ã ãºã»ã°ãªãã¯
- ã¡ãã£ã¢: æ庫
decimarl ãªãã·ã§ã³ã®æå®å€ã 2ïœ7ã®ç¯å²ã§å€æŽããŠãç¶ããŠååæãšã³ããªãŒã#ã³ãŒã5ãã Anaconda ããã³ããã«è²Œãä»ããæãããã°ã©ãã®ã¹ã¯ãªãŒã³ã·ã§ããã瀺ãã
å·ŠïŒdecimals=7ãå³ïŒdecimals=6ã
iterationïŒç¹°ãè¿ãåæ°ãlossïŒæ倱é¢æ°ã®å€ãaccïŒæ£è§£çã§ããã以äžåãã
Â
å·ŠïŒdecimals=5ãå³ïŒdecimals=4ã
Â
å·ŠïŒdecimals=3ãå³ïŒdecimals=2
Â
decimals=2 ã®ã°ã©ãã®åœ¢ç¶ãç¹ç°ãªã®ã¯ãªããšãªãä»æ¹ãªããšããæ°ãããããdecimals=3 ãš decimals=4 ã§åœ¢ç¶ãæ¿ããå€åããdecimals=5 ã§å ã«æ»ã£ãŠããããã«èŠããã®ãç®ãåŒãã
èšããŸã§ããªãdecimals=3 ãš decimals=4 ã§ã¯1/10,000以äžãdecimals=4 ãš decimals=5 ã§ã¯1/100,000以äžã®å·®ãããªãã¯ãã§ããã
Â
ã°ã©ãã®åœ¢ç¶ãéãã®ã¿ãªãããåæããW1ãW2ãb1ãb2ã®å€ãç°ãªãã
以äžã«ç€ºãã®ã¯ç 究ããŒãã®ã€ããã§ã³ãŒãããã³ããã¹ã¯ã·ã§ãªã©çã£ç«¯ãã貌ãä»ããŠããpptxãã¡ã€ã«ã®ã¹ã¯ã·ã§ã§ããã
æåã®W1ãW2ã¯np.roundå®è¡åŸã®ãã³ããç¶ãW1ãb1ãW2ãb2ã¯ã°ã©ãæç»åŸã®ãã³ãã§ãããã¿ã€ãã«ã®ãP3-1-1'ããšããã®ã¯èªåã®åºå¥çšã§æå³ã¯ãªãã
äžã«è²Œã£ãã°ã©ãã®ã¹ã¯ã·ã§ã¯ããã°ãæžããªããæ¡åãããã®ã ããpptxã«è²Œãä»ããã®ã¯5æ¥ã»ã©åã®ãã®ã ãã€ãŸãåœç¶ãªããåçŸæ§ããããšããããšã§ãããã
ã©ããããã¿ãã©ã€å¹æããŸãã¯ãã«ãªã¹ããšåŒã°ããçŸè±¡ãèµ·ããŠãããšèããŠãããããªæ°ãããã
å éšã§äœãèµ·ããŠããããããã¡ãã£ãšæããããªã®ã§ãåŒãç¶ãæã£ãŠã¿ãã
è¿œèšïŒ
å®åãšããŠæ©æ¢°åŠç¿ããã£ãŠã人ã ã£ããããã¿ãã©ã€å¹æãã«ãªã¹çŸè±¡ã«ã¯é¢å¿ãåããããã€ããŒãã©ã¡ãŒã¿ãäžé©åã ã£ãïŒãã®å ŽåW1ãW2ã®åæå€ãå°ããããïŒããšããã£ããšä¿®æ£ãããããšããããç¥ããªãã
å®éâŠ
weight_init_std=1.
W1 = weight_init_std * np.array([
[ 0.07111976, 0.08841753, 0.16924526, -0.22701769],
[-0.18342164, -0.00087162, 0.16726299, 0.21702541]])
W2 = weight_init_std * np.array([[ 0.13091743, -0.03338104],
[-0.13076172, 0.0560719 ],
[ 0.13749352, 0.00776133],
[ 0.00917579, 0.16105434]])
b1 = np.zeros(4)
b2 = np.zeros(2)
loss_list = [ ]
acc_list = [ ]
learning_rate , step_num = 5.0, 50
ãšããŠã
å·ŠïŒweight_init_std=10.ãå³ïŒweight_init_std=20.ã®ã°ã©ãã
Â
å·ŠïŒweight_init_std=50.ãå³ïŒweight_init_std=100.ã®ã°ã©ãã
ã¹ãã³ãµãŒãªã³ã¯
Â