본문 바로가기
AI-driven Methodology/ANN

[ANN] 신경망 구현

by goatlab 2022. 11. 17.
728x90
반응형
SMALL

단층 신경망

 

import numpy as np

inputs = np.array([0.5, -0.3])
weights = np.array([0.4, 0.6])
bias = -0.5

y = sigmoid(np.dot(inputs, weights.T) + bias)
print(y)

 

다층 신경망

 

 

inputs = [1.0, 0.5] # 1x2 행렬
w1 = np.array([[0.1, 0.2, 0.3], [0.2, 0.3, 0.4]]) # 2x3 행렬
b1 = np.array([0.2, 0.3, 0.4]) # 3개 노드
w2 = np.array([[0.1, 0.2], [0.3, 0.2], [0.3, 0.4]]) # 3x2행렬
b2 = np.array([0.1, 0.2]) # 2개 노드
w3 = np.array([[0.1, 0.2], [0.3, 0.4]]) # 2x2행렬
b3 = np.array([0.1, 0.2]) # 2개 노드

# 신경망 구성 (포워딩)
l1_output = np.dot(inputs, w1) + b1
l1_y = sigmoid(l1_output)
l2_output = np.dot(l1_y, w2) + b2
l2_y = sigmoid(l2_output)
l3_output = np.dot(l2_y, w3) + b3

# 마지막 레이어에서는 경우에 따라서 다른 활성화 함수를 쓰거나 쓰지 않는 경우도 있음
l3_y = sigmoid(l3_output)
print(l3_y)
728x90
반응형
LIST

'AI-driven Methodology > ANN' 카테고리의 다른 글

[ANN] 퍼셉트론 연산  (0) 2022.11.10
[ANN] GRU으로 삼성전자 주가 예측  (0) 2022.10.21
[ANN] LSTM으로 삼성전자 주가 예측  (0) 2022.10.21
[ANN] SimpleRNN (2)  (0) 2022.10.21
[ANN] SimpleRNN (1)  (0) 2022.10.19