본문 바로가기

python/deep learning3

softmax 함수의 장점 아래는 softmax 함수와 relative_frequency 함수를 비교하는 python 코드다. relative_frequency 함수는 전체에 대한 상대적인 크기를 반환한다. 즉 (각 값 / 전체 값의 합)이다. 두 함수는 모두 배열의 합이 1이 된다는 공통점이 있다(전체 값이 모두 양수라는 조건이 있어야 한다). import math import matplotlib.pyplot as plt arrx = range(5) array = [2, 3, 5, 7, 11] def softmax(array): array = [x - max(array) for x in array] a0 = 0 for x in array: a0 += math.exp(x) a1 = [] for x in array: a1.appen.. 2021. 8. 10.
NAND NOR NAND 게이트의 조합만으로 모든 게이트를 만들 수 있다. 아래는 NAND 게이트의 퍼셉트론만으로 모든 게이트를 구현한 python 코드이다. def NAND(x1, x2): a0 = -0.5 * (x1 + x2) + 0.7 if a0 > 0: return 1 else: return 0 def NOT(x): return NAND(x, x) def AND(x1, x2): return NOT(NAND(x1, x2)) def OR(x1, x2): return NAND(NOT(x1), NOT(x2)) def NOR(x1, x2): return NOT(OR(x1, x2)) def XOR(x1, x2): return AND(NAND(x1, x2), OR(x1, x2)) def XNOR(x1, x2): return .. 2021. 8. 9.
python 경사 하강법 ref: https://github.com/gilbutITbook/006958/tree/master/deeplearning/deep_class 단순 선형 회귀 import random def sqrt(x): return x ** 0.5 # x, y의 데이터 값 data = [[2, 81], [4, 93], [6, 91], [8, 97]] x_data = [x_row[0] for x_row in data] y_data = [y_row[1] for y_row in data] # 기울기 a와 y 절편 b의 값을 임의로 정한다. # 단, 기울기의 범위는 0 ~ 10 사이이며 y 절편은 0 ~ 100 사이에서 변하게 한다. a = random.random() * 10 b = random.random() * 100.. 2021. 8. 6.