LoginSignup
0
0

More than 3 years have passed since last update.

【Deep Learning】パーセプトロンで作るAND回路

Last updated at Posted at 2020-05-04

1. AND回路

 AND回路についての説明は省略する. 入力は2つ, 出力は1つである. 入出力関係を下記の真理値表に示す.

 入力a   入力b   出力c 
 0   0   0 
 0   1   0 
 1   0   0 
 1   1   1 

2. パーセプトロン

 パーセプトロンとはディープラーニングに必要なアルゴリズムである. 複数の信号を入力として受け取り, 一つの信号を出力する.各入力に重みwを加えた値が一定値を超えると信号を出力する. 下記にパーセプトロンのモデルを示す.
Screenshot from 2020-05-05 15-52-34.png

3. パーセプトロンを用いたAND回路実装(使用言語: Python)

 パーセプトロンによってAND回路を作成する. 下記のコード内の関数ANDがパーセプトロンを表しており, 入力信号と出力信号をmain内で確認している. 下記のコードを実行すると, AND回路と同じ入出力結果が得られることが分かる.

AND.py
# -*- coding: utf-8 -*-

def AND(x1, x2):

    w1, w2, theta = 0.5, 0.5, 0.7 #重み, 値域
    y = x1*w1 + x2*w2             #出力

    if   y <= theta:
        return 0
    elif y  > theta:
        return 1

if __name__ == '__main__':

    a, b = 0, 0      #入力
    c    = AND(a, b) #出力
    print ('入力%d %d 出力%d' % (a, b, c))

    a, b = 0, 1      #入力
    c    = AND(a, b) #出力
    print ('入力%d %d 出力%d' % (a, b, c))

    a, b = 1, 0      #入力
    c    = AND(a, b) #出力
    print ('入力%d %d 出力%d' % (a, b, c))

    a, b = 1, 1      #入力
    c    = AND(a, b) #出力
    print ('入力%d %d 出力%d' % (a, b, c))
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0