.NET 開発基盤部会 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。

目次

概要

ニューラルネットワークは、

という問題を、データから自動で「重み」のパラメタを学習することで解決する。

というように単一方向へのみ信号が伝播する。

活性化関数

ステップ関数とシグモイド関数とReUL関数がある。

ステップ関数

実装

なんとなくAPI仕様を知らないと難しい感じ。

グラフ

5.0 ~ 5.0までの0.1刻みのプロットをステップ関数にかけてグラフ化する。

"""This is a test program."""

import numpy as np
import matplotlib.pylab as plt

def step_function(x_1):
    """This is a test program."""
    # 上記のいずれかの実装を選択。

X = np.arange(-5.0, 5.0, 0.1)
Y = step_function(X)
plt.plot(X, Y)
plt.ylim(-0.1, 1.1)  # 図で描画するy軸の範囲を指定
plt.show()
step関数グラフ

シグモイド関数

              1
h(x) = ────────
        1 + exp(-x)

実装

ポイントは、Pythonのブロードキャストによって配列も計算できる点。

"""This is a test program."""

import numpy as np

def sigmoid(x_1):
     """This is a test program."""
    return 1 / (1 + np.exp(-x_1))   

グラフ

5.0 ~ 5.0までの0.1刻みのプロットをシグモイド関数にかけてグラフ化する。

"""This is a test program."""

import numpy as np
import matplotlib.pylab as plt

def sigmoid(x_1):
    """This is a test program."""
    return 1 / (1 + np.exp(-x_1))

X = np.arange(-5.0, 5.0, 0.1)
Y = sigmoid(X)
plt.plot(X, Y)
plt.ylim(-0.1, 1.1)
plt.show()
sigmoid関数グラフ

ReUL関数

ReUL(Rectified Linear Unit)関数

           ┌
           │0 ( a <= 0 )
y = h(a) = <
           │a ( a > 0 )
           └

実装

"""This is a test program."""

import numpy as np

def relu(x_1):
    """This is a test program."""
    return np.maximum(0, x)  

グラフ

5.0 ~ 5.0までの0.1刻みのプロットをReUL関数にかけてグラフ化する。

"""This is a test program."""

import numpy as np
import matplotlib.pylab as plt

def relu(x_1):
    """This is a test program."""
    return np.maximum(0, x_1)

X = np.arange(-5.0, 5.0, 0.1)
Y = relu(X)
plt.plot(X, Y)
plt.ylim(-0.1, 5.1)
plt.show()
ReUL関数グラフ

行列の積による実装

簡単なニューラルネットワークの実装

対象

バイアスと活性化関数を省略し重みだけとする。

X行列 * W行列=Y行列

┌      ┐ ┌          ┐   ┌                               ┐
│a1  b1│ │a2  b2  c2│ = │a1a2+b1d2  a1b2+b1e2  a1c2+b1f2│
└      ┘ │          │   └                               ┘
           │d2  e2  f2│
           └          ┘
  X行列       W行列               Y行列

#ref(): File not found: "simple.png" at page "ニューラルネットワーク"

┌    ┐   ┌       ┐      ┌                   ┐
│a  b│   │1  3  5│   =  │1a+2b  3a+4b  5a+6b│
└    ┘   │       │      └                   ┘
           │2  4  6│
           └       ┘
  X行列      W行列                Y行列

実装

>>> x=np.array([1,2])
>>> x
array([1, 2])
>>> w=np.array([[1,3,5],[2,4,6]])
>>> w
array([[1, 3, 5],
       [2, 4, 6]])
>>> y=np.dot(x,w)
>>> y
array([ 5, 11, 17])

3層のニューラルネットワークの実装

対象

#ref(): File not found: "3tier.png" at page "ニューラルネットワーク"

実装

参考


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS