[TensorFlow1.0] 인공신경망 (Artificial neural network) 기초 Start

BioinformaticsAndMe










1. 인공신경망 (Artificial Neural Network;ANN)


: 인공신경망(ANN)은 인간의 뇌를 묘사한 기계학습 예측 모델

→ 인공적인 신경망인 뉴런으로 구성되어, 입력값을 받아 계산 수행

: 인공신경망은 최근 딥러닝의 도약으로 그 성능이 재조명되고 활발하게 사용되는 중

: 인공신경망 종류

ㄱ) Perceptron(퍼셉트론) - 각 노드의 가중치 합이 0보다 크면 활성화되는 기본적인 인공신경망 알고리즘

ㄴ) Convolutional Neural Network(CNN) - 시신경 구조를 모방한 인공신경망 알고리즘

ㄷ) Recurrent Neural Network(RNN) - 뉴런 출력이 다시 입력으로 재귀하는 연결 구조의 인공신경망 알고리즘


#INPUT LAYER(입력층) - 외부 데이터를 입력하는 입구 노드

#HIDDEN LAYER(은닉층) - 노드 사이를 연결하고, 결과를 노드로 전달

#OUTPUT LAYER(출력층) - 최종 결과를 내보내는 출구 노드





2. [TensorFlow] 텐서플로우 인공신경망 기초


# '__future__' : python 2에서 python 3 문법 사용 가능

from __future__ import absolute_import, division, print_function

# 케라스, 넘파이 라이브러리 임포트 from tensorflow.keras import layers , models , optimizers , losses , initializers import numpy as np



ㄱ) Input 1개, Output 1개 인공신경망

# 그래프 생성

# initializers.Constant(2)는 weight값을 default 2로 지정 input_node = layers.Input(shape = (1,) ) output_node = layers.Dense( units = 1 , kernel_initializer = initializers.Constant(2))(input_node) # 모델 생성 model = models.Model( inputs = input_node , outputs = output_node )

# 샘플 1개를 생성된 모델로 출력

x = np.asarray([[10]]) model.predict(x)

array([[20.]], dtype=float32)

# 샘플 3개를 생성된 모델로 출력

x = np.asarray([[1],[2],[10]]) model.predict(x)

array([[ 2.], [ 4.], [20.]], dtype=float32)



ㄴ) Input 2개, Output 2개 인공신경망


# 그래프 생성

input_node = layers.Input(shape = (2,) ) output_node = layers.Dense( units = 2 , kernel_initializer = initializers.Constant(2))(input_node)

# 모델 생성 model = models.Model( inputs = input_node , outputs = output_node )

# 샘플 1개를 생성된 모델로 출력

x = np.asarray([[10 , 2]]) model.predict(x)

array([[24., 24.]], dtype=float32)

# 샘플 4개를 생성된 모델로 출력

x = np.asarray([[10 , 2],[2 , 4],[10 , 5],[22,11]]) model.predict(x)

array([[24., 24.], [12., 12.], [30., 30.], [66., 66.]], dtype=float32)



ㄷ) Input 2개, Hidden 2개, Output 1개 인공신경망

# 그래프 생성

input_node = layers.Input(shape = (2,) ) hidden_node = layers.Dense( units = 2 , kernel_initializer = initializers.Constant(2))(input_node) output_node = layers.Dense( units = 1 , kernel_initializer = initializers.Constant(3))(hidden_node)


# 모델 생성 model = models.Model( inputs = input_node , outputs = output_node )

# 샘플 1개를 생성된 모델로 출력

x = np.asarray([[10 , 2]]) model.predict(x)

array([[144.]], dtype=float32)

# 샘플 4개를 생성된 모델로 출력

x = np.asarray([[10 , 2],[2 , 4],[10 , 5],[22,11]]) model.predict(x)

array([[144.], [ 72.], [180.], [396.]], dtype=float32)





3. [TensorFlow] 활성함수 (relu vs softmax)


relu 활성함수

- 노드 결과값이 음수면 0을 내보냄

- 마지막이 아닌 레이어에 사용


 softmax 활성함수

- 입력값을 0~1사이 값으로 표준화하여 출력

- 출력값들의 총합은 항상 1

- 마지막 레이어 Output이 2개 이상일 경우, 마지막 레이어에 사용


# relu 활성함수 모델링

input_node2 = layers.Input(shape = (2,) ) output_node2 = layers.Dense( units = 1 , activation = 'relu' , kernel_initializer = initializers.Constant(1))(input_node2) model2 = models.Model( inputs = input_node2 , outputs = output_node2 )


# 예제 데이터 data = [[ 1 ,-3], [ 3 , -9], [ 10, 0], [ -8 ,10], [ 0 , -1]] data = np.array(data)


# relu 활성함수 예제 결과 res2 = model2.predict(data) print(res2)

[[ 0.] [ 0.] [10.] [ 2.] [ 0.]]





#Reference

1) https://namu.wiki/w/%EC%9D%B8%EA%B3%B5%EC%8B%A0%EA%B2%BD%EB%A7%9D

2) https://ko.wikipedia.org/wiki/%EC%9D%B8%EA%B3%B5_%EC%8B%A0%EA%B2%BD%EB%A7%9D

3) 2019년도 유전체 분석 분야 재직*연구자 전문교육

4) https://www.sciencedirect.com/science/article/pii/B9780128015599000065

5) https://m.blog.naver.com/wideeyed/221021710286





[TensorFlow1.0] 인공신경망 (Artificial neural network) 기초 End

BioinformaticsAndMe

+ Recent posts