Â
ååã®èšäºãã1ã¶æ以äžçµã£ãŠããŸã£ããããŒãããäœãDeep Learning âPythonã§åŠã¶ãã£ãŒãã©ãŒãã³ã°ã®çè«ãšå®è£ ããšããæ¬ãèªãã§ããã3ç« ã§ãšãŠãé£æ床ã®é«ããšæããã«ãã«ã¶ã¡åœãã£ãã®ã§ãèªåèªèº«ã®ç解ã®åºŠåãã確èªããããã«ãé£æ床ã®äœãç·Žç¿åé¡ãäœã£ãŠè§£ããŠã¿ããšããå 容ã®ãšã³ããªãŒã ã
äžæ²æž3ç« ã«ã¯ãããã¥ãŒã©ã«ãããã¯ãŒã¯ãããªãã¡è¡åç©ãšããã€ãã®é¢æ°ã®çµã¿åãããçšããŠãMNISTããŒã¿ã»ããããªãã¡ææžãæ°åã®ãã¹ãããŒã¿ãèªèãããæ¹æ³ã«ã€ããŠèª¬æãããããããåèªæã«ã¯ãšãŠãé£ããæããããã®ã§ãããç°¡åãªäŸãšããŠã4ã»ã°ã¡ã³ãLEDããšããã®ãèããŠã¿ãã®ã ããããããã¹ãP84ïœ86ã§ãããšããã®ãæ©æ¢°åŠç¿ãã§ã¯ãªãã人ã®èããã¢ã«ãŽãªãºã ãã§ãèªèãããããšã¯ã§ããã
ã§ã¯ãããããæ©æ¢°åŠç¿ãã«ãã£ãŠå®çŸã§ãããããèªåèªèº«ã«äžãã次ãªã課é¡ã§ãã£ãã
çµè«ãå ã«æžããšãå®çŸã§ããããããé©ãã¹ãããšã«ã4ç« P113以éã«æ²ããããã2å±€ãã¥ãŒã©ã«ãããã¯ãŒã¯ã®ã¯ã©ã¹ãã«å¯Ÿããé©åãšæãããããŒã¿ããã³åŒæ°ïŒäžæ²æžã§èšããšããã®ããã€ããŒãã©ã¡ãŒã¿ãïŒïŒãäžããã ãã§ãå®çŸã§ããŠããŸã£ãïŒ
ããã«é©ãã¹ãããšã«ã4ã»ã°ã¡ã³ãã©ããããçŸå®ã«äœ¿çšãããŠãã7ã»ã°ã¡ã³ãLEDã«å¯ŸããŠããåãã¯ã©ã¹ãçšããæ©æ¢°åŠç¿ã«ããèªèãå®çŸã§ããŠããŸã£ãïŒ
ãã®ããšã説æãããããäœåãã«ããããšã³ããªãŒãèµ·ããã察象èªè ã¯ããŒãããäœãDeep LearningãïŒä»¥äžããã¹ããšè¡šèšããïŒèªè éå®ãªã®ã§ããã€ãã®ããã«é æ ®ããŠãæ°çãšã³ããªãŒããç®ç«ã¡ã«ããããããæ¥ä»ãããã®ãŒã£ãŠå ¬éããã
ã¹ãã³ãµãŒãªã³ã¯
Â
Â
ããã¹ã4ç« ã§ã¯ãåŸé æ³ã«ãã2å€æ°ã®é¢æ°ã®æå°å€ã®æ¢çŽ¢ã説æãããïŒP109ãŸã§ïŒãããã«ç¶ããŠ2次å 6å€æ°ã®ãã¥ãŒã©ã«ãããã¯ãŒã¯ã«å¯ŸããŠåŸé ãèšç®ããäŸã瀺ãããïŒP110ïœ112ïŒããã®ãã¥ãŒã©ã«ãããã¯ãŒã¯ã¯ãåãªãæ°å€äŸã«éãããäœãå ·äœçãªã¢ãã«ãããããã§ã¯ãªãã
ããã«ç¶ããŠã2å±€ãã¥ãŒã©ã«ãããã¯ãŒã¯ã®ã¯ã©ã¹ã瀺ããããã®ããã¹ãã®æ žå¿éšãšãèšãã¹ãMNISTããŒã¿ã»ããã«å¯ŸãããããããåŠç¿ã®å®è£ ã®èª¬æãå§ãŸãã®ã§ããïŒP117ïœïŒãããã§ãŸããæåŽçµ¶å£ãšãããã¹ãé£æ床ã®å€åãæãããããŸãããšæžããã®ã¯ã3ç« ã§ãæããæèŠã«äŒŒãŠããããã ã
ããã§ä»åããŸããèªåã§ããç°¡åãªäŸé¡ãäœã£ãŠè§£ããŠã¿ãããšèãããæåŽçµ¶å£ã«ãã·ãŽãããããããªã€ããã§ããã
ããããååãã£ã4ã»ã°ã¡ã³ãLEDã§ãé£æ床é«ããšæãããããã§2ç« ãŸã§ããã®ãŒã£ãŠãããŒã»ãããã³ã®å®è£ ãæ©æ¢°åŠç¿ã§ããããããªãããšèãããããŒã»ãããã³ãšã¯ããããã£ã±ã«èšããšãéã¿ããšããã€ã¢ã¹ãã«ããè«çåè·¯ã®å®çŸã§ããã
ããã¹ãP110ã«ã¯ã2è¡Ã3åã®ãéã¿ãã©ã¡ãŒã¿ãã®ã¿ãæãããã¥ãŒã©ã«ãããã¯ãŒã¯ã«å¯ŸããŠåŸé ãæ±ããã¯ã©ã¹ "simpleNet" ãšããŠã次ã®ãããªã³ãŒãã瀺ãããŠããã
import sys, os
sys.path.append(os.pardir)
import numpy as np
from common.functions import softmax, cross_entropy_error
from common.gradient import numerical_gradient
class simpleNet:
  def __init__(self):    self.W = np.random.randn(2,3) # ã¬ãŠã¹ååžã§åæå
  def predict(self, x):    return np.dot(x, self.W)
  def loss(self, x, t):
    z = self.predict(x)
    y = softmax(z)
    loss = cross_entropy_error(y, t)
    return loss
ïŒWindowsã³ãã³ãããã³ããã®python察話ã¢ãŒãã«ã³ããŒïŒããŒã¹ãã§ãããããäžéšæ¹è¡ãåé€ããŠããŸãïŒ
ãã®ã³ãŒããå®è¡ããããšã«ãããããã¹ãP111ã«ç€ºããããããªãéã¿ãã©ã¡ãŒã¿ããæ倧å€ã®ã€ã³ããã¯ã¹ããæ倱é¢æ°ã®å€ããèšç®ããããšãã§ããããåè¿°ã®ãšãããããã®å€ã«ã¯ç¹æ®µã®æå³ãããããã§ã¯ãªãã
ããã§ãéã¿ãã©ã¡ãŒã¿ãã2è¡Ã3åãã1è¡3åã«å€æŽããå€æ°åãšããŠã¯ã¡ãã£ãšå€ã ããW[0]ãšW[1]ãæ¹ããŠãéã¿ããW[2]ãããã€ã¢ã¹ããšããããšã«ããã2ç« ããŒã»ãããã³ãæ©æ¢°åŠç¿ã§ããªãããšèããã®ã ã
å°ãªããã¬èŠåŽãããããã§ãããçµæã®ã³ãŒãã瀺ããã¯ã©ã¹å "Perceptrn" ãšããŠã¿ããã¡ãœãã "predict" ã¯æšå®å€ãæ±ããé¢æ°ã§ããã®å€ãæ£ãªã "1"ãè² ãªã "0"ã"loss" ã¯æšå®å€ã«ã·ã°ã¢ã€ãé¢æ°ïŒããã¹ãP45ã48ïŒãåãŸããäžã§ãæ£è§£ãšã®äºä¹èª€å·®ã«ããæ倱ãèšç®ããé¢æ°ã§ããã
import sys, os
sys.path.append(os.pardir)
import numpy as np
from common.functions import sigmoid
from common.gradient import numerical_gradientclass Perceptrn:
  def __init__(self):
    self.W = np.random.randn(3)
  def predict(self, x):
    return x[0]* self.W[0]+ x[1] *self.W[1] + self.W[2]
  def loss(self, x, t):
    z1= sigmoid(self.predict(x))
    y = (z1-t)**2
    return y
ããã¹ãP110ã®ã¯ã©ã¹ "simpleNet" ãå®è¡ã§ããç°å¢ã§ããã°ãå®è¡ãããããã¯ãã§ããã
Windows ã® Anaconda Prompt ã§å®è¡ããããšãããã¬ãŠã¹ååžã§åæåããéã¿Wã®åæå€ã¯ãããã ã£ãã
æšå®å€ãèŠãããããããã¹ãããé¢æ°ïŒããã¹ãP45ïŒãã€ã³ããŒãããã
åŠç¿ç "learning_rate" 㯠1.0 ãšããŠã¿ãã
from common.functions import step_function
pct = Perceptrn()
f = lambda w: pct.loss(x, t)
learning_rate = 1.0Â
python ã«äžæ £ããªã®ã§ãforæããããªãµãã«èšè¿°ããã®ãé©åãã©ããã¯ãããããªããççå€è¡šã¿ããã«èŠããªãããšãã工倫ã®ã€ããã§ããã
for (x, t) in [\
(np.array([0, 0]), 0),(np.array([0, 1]), 0),(np.array([1, 0]), 0),(np.array([1, 1]), 1)]:
  print("p = " + str(pct.predict(x)) + " : " + str(step_function(pct.predict(x))))
  print(âl = " + str(pct.loss(x,t)))
  dW = numerical_gradient(f,pct.W)
  print("dW = " + str(dW))
  pct.W -= learning_rate * dW
  print("W = " + str(pct.W))
ããã [Ctrl]+[v] 㧠Anaconda Prompt ã«é£ç¶ããŠè²Œãä»ããã
貌ãä»ã1åç®ã®çµæã "p" ã¯æšå®å€ã§æ£ãªã "1"ãè² ãªã "0"ãã¡ãã£ãšã¯èŠããããªããªãããªãšãã¹ãããé¢æ°ã«ãã "1"/"0"ãžã®å€æãä»ãå ããŠã¿ãã"l" ã¯æ倱ã"dW" ã¯æ倱ã«åŸé æ³ãé©çšããŠæ±ããéã¿ã®å€åã"W" ã¯éã¿ã§ããã
åœç¶ãªããççå€è¡šã¯ã¡ãã£ã¯ãã£ã§ããã
2åç®ã®çµæãæ倱 "l" ãæžã£ãŠããããšã確èªã§ããããããå±æçã«ã¯å¢ããå Žåãããã®ããéã¿ "W" ã®åŸ®èª¿æŽãç¹°ãè¿ããã³ã«ãããŒã¿ã«ã§ã¯æžå°ããã¯ãã§ããã
18åç®ã®è²Œãä»ãçµæãã€ãã«æ£ããççå€è¡šãåŸãããïŒ äœåºŠãè©Šãããšãããã ããã20åç®ããããŸã§ã«ã¯æ£ããçµæãåŸãããããã ã
W[0]ãW[1]ãW[2] ã®æ¯ã¯ 1ïŒ1ïŒïŒ1.51 ãããã®å€ã«åæããããããããŒã»ãããã³ã«ããANDã²ãŒãã®ãæ©æ¢°åŠç¿ã«ãã£ãŠæ±ããããéã¿ãšãã€ã¢ã¹ãšèšãããã
ãã¡ããç¹°ãè¿ãããŒã¹ãããå¿ èŠã¯ãªããforæã2éåããããšã«ãããäœåºŠã§ãç¹°ãè¿ãããšãã§ããããã ããŒã¹ããããã³ã«å€ãå€åããã®ããèŠãŠããŠé¢çœãã£ãã®ã ã
ãã®é¢çœãå æžããªããšãä»äººã«äŒããããªãããšãã°ã©ããæããŠã¿ããgifã¢ãã¡åããããšãããããããã©ããã€ãã€ãã§ããããã¯ãèªåã§ã¹ã¯ãªãããåäœãããã«ããã¯ãªãããã ã
ã°ã©ãã ã貌ã£ãŠã¿ããããªãäžåŽã®éãå®ç·ã W[0]ãäžåŽã®ç·ã®ç¹ç·ã W[2] ã§ããã暪軞ã¯ç¹°ãè¿ãåæ°ã ã
ãªãåœç¶ãªãããfor æã®ç¹°ãè¿ãæ¡ä»¶ã
(np.array([0, 0]), 0),(np.array([0, 1]), 0),(np.array([1, 0]), 0),(np.array([1, 1]), 1)]:
ãã
(np.array([0, 0]), 0),(np.array([0, 1]), 1),(np.array([1, 0]), 1),(np.array([1, 1]), 1)]:
ã«å€ãããšORã²ãŒããå®çŸããéã¿ãšãã€ã¢ã¹ãããŸã
(np.array([0, 0]), 1),(np.array([0, 1]), 1),(np.array([1, 0]), 1),(np.array([1, 1]), 0)]:
ã«å€ãããšNANDã²ãŒããå®çŸããéã¿ãšãã€ã¢ã¹ãåŸããããOR ã®å ŽåãW[0]ãW[1]ãW[2] ã®æ¯ã¯ 1ïŒ1ïŒïŒ0.47 ãããã«åæããããŸã NAND ã®å Žåã¯ãæ¯ã¯ AND ãšåããããã ã£ãã W[0]ãW[1] ãW[2] ã®ç¬Šå·ãå転ããã
ãããïŒãããããããïŒãããããããïŒ
ãã®çµæã«åæ°ãåŸãŠã5æ21æ¥ã®ãšã³ããªãŒã§èªåèªèº«ã«äžãã宿é¡ãããªãã¡æ©æ¢°åŠç¿ã«ããã4ã»ã°ã¡ã³ãLEDãã®èªèã«ãã£ã¬ã³ãžããã
ãã®é ã€ã¥ããÂ
ãŒãããäœãDeep Learning âPythonã§åŠã¶ãã£ãŒãã©ãŒãã³ã°ã®çè«ãšå®è£
- äœè : æè€åº·æ¯
- åºç瀟/ã¡ãŒã«ãŒ: ãªã©ã€ãªãŒãžã£ãã³
- çºå£²æ¥: 2016/09/24
- ã¡ãã£ã¢: åè¡æ¬ïŒãœããã«ããŒïŒ
- ãã®ååãå«ãããã° (16件) ãèŠã