Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ゼロから作る Deep Learningを Ruby で

ゼロから作る Deep Learningを Ruby で

ゼロから作る
Deep Learningを
Ruby で

niwasawa

May 12, 2017
Tweet

More Decks by niwasawa

Other Decks in Programming

Transcript

  1. import numpy as np import matplotlib matplotlib.use("AGG") # ඳըϥΠϒϥϦʹAGG(Anti-Grain Geometry)Λ࢖͏

    import matplotlib.pyplot as plt # σʔλͷ࡞੒ x = np.arange(0, 6, 0.1) # 0͔Β6·Ͱ0.1ࠁΈͰੜ੒ y1 = np.sin(x) y2 = np.cos(x) # άϥϑͷඳը plt.figure(figsize=(4, 3), dpi=160) # ը૾αΠζ plt.plot(x, y1, label="sin") plt.plot(x, y2, linestyle = "--", label="cos") # ഁઢͰඳը plt.xlabel("x") # x࣠ͷϥϕϧ plt.ylabel("y") # y࣠ͷϥϕϧ plt.title("sin & cos") # λΠτϧ plt.legend() plt.savefig("python_graph.png")
  2. require 'numo/narray' require 'numo/gnuplot' # σʔλͷ࡞੒ x = Numo::DFloat.new(60).seq(0, 0.1)

    # 0͔Β6·Ͱ0.1ࠁΈͰੜ੒ y1 = Numo::DFloat::Math.sin(x) y2 = Numo::DFloat::Math.cos(x) # άϥϑͷඳը g = Numo::gnuplot do set term: {png: {size: [640, 480]}} # ը૾αΠζ set output: 'ruby_graph.png' set title: 'sin \& cos' # λΠτϧ set key: 'box left bottom' set offset: [0, 0, 0, 0] plot x, y1, {w: 'lines', lw: 3, title: 'sin'}, x, y2, {w: 'lines', lw: 3, title: 'cos'} end
  3. import numpy as np def AND(x1, x2): x = np.array([x1,

    x2]) w = np.array([0.5, 0.5]) # ॏΈ b = -0.7 # όΠΞε tmp = np.sum(w*x) + b if tmp <= 0: return 0 else: return 1
  4. require 'numo/narray' def AND(x1, x2) x = Numo::DFloat[x1, x2] w

    = Numo::DFloat[0.5, 0.5] # ॏΈ b = -0.7 # όΠΞε tmp = (w*x).sum + b if tmp <= 0 0 else 1 end end
  5. ࣮ߦ݁Ռ $ python and_gate.py (0, 0) -> 0 (1, 0)

    -> 0 (0, 1) -> 0 (1, 1) -> 1 $ ruby and_gate.rb [0, 0] -> 0 [1, 0] -> 0 [0, 1] -> 0 [1, 1] -> 1
  6. ࠓճͷιʔείʔυ͸ Qiita Ͱެ։தɻ Python vs Ruby ʰθϩ͔Β࡞ΔDeep Learningʱ 1ষ sinؔ਺ͱcosؔ਺

    ͷάϥϑ - Qiita http://qiita.com/niwasawa/items/6d9aba43f3cdba5ca725 Python vs Ruby ʰθϩ͔Β࡞ΔDeep Learningʱ 2ষ ύʔηϓτϩϯ ʹΑΔ࿦ཧճ࿏ - Qiita http://qiita.com/niwasawa/items/73f604f956d043671f39 Naoki Iwasawa @niwasawa