๐Ÿ“—
JunegLee's TIL
  • TIL
  • python
    • class
    • String Basic
    • regularExpression
    • String function
    • Generator
    • String format
    • getset
    • module
    • while
    • numpy
    • print()
    • matplotlib
    • for
    • Boolean
    • tuple
    • package
    • input(variable)
    • list
    • if
    • file
    • type()
    • pandas
    • function
    • dictionary
    • ๊ตฌ๋ฌธ ์˜ค๋ฅ˜์™€ ์˜ˆ์™ธ
    • builtinFunction
    • Constructor
  • algorithm
    • sort
      • mergeSort
      • insertionSort
      • bubbleSort
      • heapSort
      • quickSort
      • selectionSort
    • recursion
    • Greedy
    • DepthFirstSearch
    • basic
      • DataStructure
    • hash
    • BreadthFirstSearch
  • tensorflow
    • keras
      • layers
        • Flatten
        • Flatten
        • Dense
        • Dense
        • Conv2D
        • Conv2D
    • tensorflow1x
    • tensorflow2x
  • DB
    • setting
    • join
    • subQuery
    • overview
  • deep-learning
    • neuralNetwork
    • perceptron
    • neuralNetworkLearning
    • convolution neural network
    • Gradient Descent
    • Linear Regression
    • backPropagation
    • logistic regression
    • overview
  • textPreprocessing
    • overview
  • java
    • basics
      • generic
      • Variable
      • String
    • theory
      • Object Oriented Programing
  • NLP
    • Embedding
    • Natural Language Processing
Powered by GitBook
On this page
  • perceptron
  • perceptron
  • Overview
  • ํผ์…‰ํŠธ๋ก ์œผ๋กœ ๊ตฌํ˜„ํ•˜๊ธฐ : AND, NAND, OR
  • (0, 0) -> 1
  • (1, 0) -> 1
  • (0, 1) -> 1
  • (1, 1) -> 0
  • ๋‹ค์ธต ํผ์…‰ํŠธ๋ก 
  • ์ฝ”๋”ฉใ…‡์œผ๋กœ XOR ๋ฌธ์ œ ํ•ด๊ฒฐ

Was this helpful?

  1. deep-learning

perceptron

PreviousneuralNetworkNextneuralNetworkLearning

Last updated 3 years ago

Was this helpful?

perceptron

perceptron

Overview

ํผ์…‰ํŠธ๋ก  (perceptron) : ํผ์…‰ํŠธ๋ก ์€ ํ”„๋ž‘ํฌ ๋กœ์  ๋ธ”๋ผํŠธ(Frank Rosenblatt)๊ฐ€ 1957๋…„์— ๊ณ ์•ˆํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋ฉฐ, ๋‹ค์ˆ˜์˜ ์‹ ํ˜ธ๋ฅผ ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์•„ ํ™œ์„ฑํ™” ํ•จ์ˆ˜์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•ด ์ถœ๋ ฅ ๊ฐ’์„ ๋‹ค์Œ์œผ๋กœ ๋„˜๊ธฐ๋Š” ๊ฐ€์žฅ ์ž‘์€ ์‹ ๊ฒฝ๋ง ๋‹จ์œ„ ์‹ ๊ฒฝ๋ง(๋”ฅ๋Ÿฌ๋‹)์˜ ๊ธฐ์›์ด ๋˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํผ์…‰ํŠธ๋ก ์˜ ๊ตฌ์กฐ๋ฅผ ๋ฐฐ์šฐ๋Š” ๊ฒƒ์€ ์‹ ๊ฒฝ๋ง๊ณผ ๋”ฅ๋Ÿฌ๋‹์œผ๋กœ ๋‚˜์•„๊ฐ€๋Š” ๋ฐ ์ค‘์š”ํ•œ ์•„์ด๋””์–ด๋ฅผ ๋ฐฐ์šด๋‹ค.

  • ์‹ ํ˜ธ๋ž€ ? ์ „๋ฅ˜๋‚˜ ๊ฐ•๋ฌผ์ฒ˜๋Ÿผ ํ๋ฆ„์ด ์žˆ๋Š” ๊ฒƒ. ์ฆ‰, 1์€ ์‹ ํ˜ธ๊ฐ€ ํ๋ฅธ๋‹ค, 0์„ ์‹ ํ˜ธ๊ฐ€ ํ๋ฅด์ง€ ์•Š๋Š”๋‹ค

  • ์ž…๋ ฅ๊ฐ’ (x)๊ณผ ๊ฐ€์ค‘์น˜(w)์˜ ๊ณฒ์„ ๋ชจ๋‘ ๋”ํ•œ ๋‹ค์Œ ๊ฑฐ๊ธฐ์— ๋ฐ”์ด์–ด์Šค(b)๋ฅผ ๋”ํ•œ ๊ฐ’์„ ๊ฐ€์ค‘ํ•ฉ(y)์ด๋ผ๊ณ  ํ•œ๋‹ค ๊ฐ€์ค‘ํ•ฉ์˜ ๊ฒฐ๊ณผ๋ฅผ ๋†“๊ณ  1 ๋˜๋Š” 0์„ ์ถœ๋ ฅํ•ด์„œ ๋‹ค์Œ์œผ๋กœ ๋ณด๋‚ด๋ฉฐ, 0๊ณผ 1์„ ํŒ๋‹จํ•˜๋Š” ํ•จ์ˆ˜๊ฐ€ ์žˆ๋Š”๋ฐ ์ด๋ฅผ ํ™œ์„ฑํ™” ํ•จ์ˆ˜ (activation function)์ด๋ผ ํ•œ๋‹ค

  • ๋‹จ์ˆœํ•œ ๋…ผ๋ฆฌ ํšŒ๋กœ

    ๊ฒŒ์ดํŠธ(gate, ํšŒ๋กœ)

    ์ •์˜

    AND ๊ฒŒ์ดํŠธ

    ๋ชจ๋‘๊ฐ€ 1์ผ๋•Œ๋งŒ

    NAND ๊ฒŒ์ดํŠธ

    Not AND ์˜๋ฏธ

    OR ๊ฒŒ์ดํŠธ

    ์‹ ํ˜ธ์ค‘์— ํ•˜๋‚˜ ์ด์ƒ์ด 1์ด๋ฉด

    XOR ๊ฒŒ์ดํŠธ

    ๋‘˜ ์ค‘ ํ•˜๋‚˜๋งŒ 1์ผ ๋•Œ 1์„ ์ถœ๋ ฅ

ํผ์…‰ํŠธ๋ก ์œผ๋กœ ๊ตฌํ˜„ํ•˜๊ธฐ : AND, NAND, OR

  • AND ํ•จ์ˆ˜ (๊ฐ€์ค‘์น˜์™€ ํŽธํ–ฅ์„ ๋„์ž…)

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

if __name__ == '__main__':
    for xs in [(0, 0), (1, 0), (0, 1), (1, 1)]:
        y = AND(xs[0], xs[1])
        print(str(xs) + " -> " + str(y))

# (0, 0) -> 0
# (1, 0) -> 0
# (0, 1) -> 0
# (1, 1) -> 1
  • NAND ๊ฒŒ์ดํŠธ

    ```python

    import numpy as np

def NAND(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 if name == 'main': for xs in [(0, 0), (1, 0), (0, 1), (1, 1)]: y = NAND(xs[0], xs[1]) print(str(xs) + " -> " + str(y))

(0, 0) -> 1

(1, 0) -> 1

(0, 1) -> 1

(1, 1) -> 0

* OR ๊ฒŒ์ดํŠธ 

```python
import numpy as np


def OR(x1, x2):
    x = np.array([x1, x2])
    w = np.array([0.5, 0.5])
    b = -0.2
    tmp = np.sum(w*x) + b
    if tmp <= 0:
        return 0
    else:
        return 1

if __name__ == '__main__':
    for xs in [(0, 0), (1, 0), (0, 1), (1, 1)]:
        y = OR(xs[0], xs[1])
        print(str(xs) + " -> " + str(y))

# (0, 0) -> 0
# (1, 0) -> 1
# (0, 1) -> 1
# (1, 1) -> 1

๋‹ค์ธต ํผ์…‰ํŠธ๋ก 

: ๊ธฐ์กด์ด ํผ์…‰ํŠธ๋ก ์œผ๋กœ๋Š” XOR๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์—†์–ด ๋‹ค์ธต ํผ์…‰ํŠธ๋ก ์œผ๋กœ ๊ทธ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์˜€๋‹ค. ์ฆ‰, ์ขŒํ‘œ ํ‰๋ฉด ์ž์ฒด์— ๋ณ€ํ™”๋ฅผ ์ฃผ์–ด, ๋‘๊ฐœ์˜ ํผ์…‰ํŠธ๋ก ์„ ํ•œ๋ฒˆ์— ๊ณ„์‚ฐ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋งŒ๋“ค์—ˆ์œผ๋ฉฐ, ์ˆจ์–ด์žˆ๋Š” ์ธต, ์ฆ‰ ์€๋‹‰์ธต์„ ๋งŒ๋“ค์–ด์„œ ๊ทธ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์˜€๋‹ค ์€๋‹‰์ธต์— ๋ชจ์ด๋Š” ์ค‘๊ฐ„ ์ •๊ฑฐ์žฅ์„ ๋…ธ๋“œ(node)๋ผ๊ณ  ํ•œ๋‹ค

  • ์œ„ ๋‘ ์‹์˜ ๊ฒฐ๊ณผ๊ฐ’์ด ์ถœ๋ ฅ์ธ ์‘๋กœ ๋ณด๋‚ด์ง€๋ฉฐ, ์ถœ๋ ฅ์ธต์—์„œ๋Š” ์‹œ๊ทธ๋ชจ์ด๋“œ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด y๊ฐ’์ด ์ •ใ…Ž์ง„๋‹ค

    ์ด ๊ฐ’์„ yout์ด๋ผ ํ• ๋•Œ ์‹์œผ๋กœ ํ‘œํ˜„ํ•˜๋ฉด

  • ๊ฐ๊ฐ์˜ ๊ฐ€์ค‘์น˜(w) ์™€ ๋ฐ”์ด์–ด์Šค (b)์˜ ๊ฐ’์„ 2์ฐจ์› ๋ฐฐ์—ด๋กœ ๋Š˜์–ด ๋†“์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ,

    ์€๋‹‰์ธต์„ ํฌํ•จํ•ด ๊ฐ€์ค‘์น˜ 6๊ฐœ์™€ ๋ฐ”์ด์–ด์Šค 3๊ฐœ๊ฐ€ ํ•„์š”ํ•˜๋‹ค

์ฝ”๋”ฉใ…‡์œผ๋กœ XOR ๋ฌธ์ œ ํ•ด๊ฒฐ

import numpy as np

# ๊ฐ€์ค‘์น˜์™€ ๋ฐ”์ด์–ด์Šค
w11 = np.array([-2, -2])
w12 = np.array([2, 2])
w2 = np.array([1, 1])
b1 = 3
b2 = -1
b3 = -1

# ํผ์…‰ํŠธ๋ก 
def MLP(x, w, b):
    y = np.sum(w * x) + b
    if y <= 0:
        return 0
    else:
        return 1

# NAND ๊ฒŒ์ดํŠธ
def NAND(x1,x2):
    return MLP(np.array([x1, x2]), w11, b1)

# OR ๊ฒŒ์ดํŠธ
def OR(x1,x2):
    return MLP(np.array([x1, x2]), w12, b2)

# AND ๊ฒŒ์ดํŠธ
def AND(x1,x2):
    return MLP(np.array([x1, x2]), w2, b3)

# XOR ๊ฒŒ์ดํŠธ
def XOR(x1,x2):
    return AND(NAND(x1, x2),OR(x1,x2))
    # XOR๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ๊ธฐ ์œ„ํ•ด์„œ๋Š” ์œ„์—์„œ ์ •์˜ํ•œ AND, NAND, OR๋ฅผ ์ด์šฉํ•˜์—ฌ 
    # ์ˆจ์–ด์žˆ๋Š” ๋‘ ๊ฐœ์˜ ๋…ธ๋“œ๋ฅผ ๋‘” ๋‹ค์ธต์˜ ํผ์…‰ํŠธ๋ก ์œผ๋กœ XOR ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ๋‹ค  


# x1, x2 ๊ฐ’์„ ๋ฒˆ๊ฐˆ์•„ ๋Œ€์ž…ํ•ด ๊ฐ€๋ฉฐ ์ตœ์ข…๊ฐ’ ์ถœ๋ ฅ
if __name__ == '__main__':
    for x in [(0, 0), (1, 0), (0, 1), (1, 1)]:
        y = XOR(x[0], x[1])
        print("์ž…๋ ฅ ๊ฐ’: " + str(x) + " ์ถœ๋ ฅ ๊ฐ’: " + str(y))
์ž…๋ ฅ ๊ฐ’: (0, 0) ์ถœ๋ ฅ ๊ฐ’: 0
์ž…๋ ฅ ๊ฐ’: (1, 0) ์ถœ๋ ฅ ๊ฐ’: 1
์ž…๋ ฅ ๊ฐ’: (0, 1) ์ถœ๋ ฅ ๊ฐ’: 1
์ž…๋ ฅ ๊ฐ’: (1, 1) ์ถœ๋ ฅ ๊ฐ’: 0
perceptron
singlePerceptron
multiPerceptron