「.NET 開発基盤部会 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。
目次 †概要 †ここでは正確には、人口ニューロン、単純パーセプトロンについて説明する。
動作原理 †(x1) --------- w1 --------> (y) ↑ (x2) --------- w2 -----------┘ 入力信号 固有の重み 出力信号
式 †
活性化関数 †
論理回路をパーセプトロンで表現 †機械学習では下のパラメタ(w1, w2, θ(-b))を決める作業をコンピュータに行わせる。 ANDゲート †下記のANDゲートを満たすパーセプトロン(w1, w2, θ(-b))を作る。
例 †
プロット †│ 0 ① │ │ ─0──0───── │ NANDゲート †下記のNANDゲートを満たすパーセプトロン(w1, w2, θ(-b))を作る。
例 †(ANDゲートのパラメタの符号を反転すればOK)
プロット †│ ① 0 │ │ ─①──①───── │ ORゲート †下記のORゲートを満たすパーセプトロン(w1, w2, θ(-b))を作る。
例 †
プロット †│ ① ① │ │ ─0──①───── │ XORゲート †下記のXORゲートを満たす1層のパーセプトロンを作ることはできない。
プロット †理由は、以下の縦軸x1、横軸x2のプロットは、 │ ① 0 │ │ ─0──①───── │ 多層のパーセプトロン †しかし、前述のAND、NADN、ORのゲートを 例えば、
を使用すると、
と多層(2層)パーセプトロンとしてXORゲートを作ることができる。 (x1) ──NAND──→ (s1)─AND┐ └── OR ───↑┐ ↓ ││ (y) ┌───NAND──┘↓ ↑ (x2) ── OR ──→ (s2)─AND┘ 論理回路をパーセプトロンで実装 †簡単な実装 †ここから、VSCodeでPythonファイルに書いた。 ANDゲート †"""This is a test program.""" def and_method(x_1, x_2): """This is a test program.""" w_1, w_2, theta = 0.5, 0.5, 0.7 tmp = x_1 * w_1 + x_2 * w_2 if tmp <= theta: return 0 else: return 1 print(and_method(0, 0)) print(and_method(1, 0)) print(and_method(0, 1)) print(and_method(1, 1)) NANDゲート †w, θを以下のようにする。 w_1, w_2, theta = -0.5, -0.5, -0.7 ORゲート †w, θを以下のようにする。 w_1, w_2, theta = 0.5, 0.5, 0.3 バイアスを用いた実装 †ANDゲート †"""This is a test program.""" import numpy as np def and_method(x_1, x_2): """This is a test program.""" x = np.array([x_1, x_2]) w = np.array([0.5, 0.5]) b = -0.7 tmp = b + np.sum(x*w) if tmp <= 0: return 0 else: return 1 print(and_method(0, 0)) print(and_method(1, 0)) print(and_method(0, 1)) print(and_method(1, 1)) NANDゲート †w, bを以下のようにする。 w = np.array([-0.5, -0.5]) b = 0.7 ORゲート †w, bを以下のようにする。 w = np.array([0.5, 0.5]) b = -0.3 XORゲート †多層パーセプトロン(MLP)として以下のように実装できる。 """This is a test program.""" import numpy as np def and_method(x_1, x_2): """This is a test program.""" x = np.array([x_1, x_2]) w = np.array([0.5, 0.5]) b = -0.7 tmp = b + np.sum(x*w) if tmp <= 0: return 0 else: return 1 def nand_method(x_1, x_2): """This is a test program.""" x = np.array([x_1, x_2]) w = np.array([-0.5, -0.5]) b = 0.7 tmp = b + np.sum(x*w) if tmp <= 0: return 0 else: return 1 def or_method(x_1, x_2): """This is a test program.""" x = np.array([x_1, x_2]) w = np.array([0.5, 0.5]) b = -0.3 tmp = b + np.sum(x*w) if tmp <= 0: return 0 else: return 1 def xor_method(x_1, x_2): """This is a test program.""" s_1 = nand_method(x_1, x_2) s_2 = or_method(x_1, x_2) return and_method(s_1, s_2) print(xor_method(0, 0)) print(xor_method(1, 0)) print(xor_method(0, 1)) print(xor_method(1, 1)) 参考 † |