Lec 09 Neural Nets for XOR & backpropagation

Lec 09 Neural Nets for XOR & backpropagation

Lec 09-01 : XOR 문제 딥러닝으로 풀기

1. Neural NEtwork (NN)을 사용하여 XOR 문제 풀기

: Wx + b 식을 S함수에 넣고 계산

: Ex) 아래의 3개 식 계산

2. Forward propagation

: x1, x2가 각각의 유닛으로 계산되어 sigmoid가 입력값으로 들어가고, 변수값을 만나 최종값으로 계산된다.

3. NN

: multiinomial classification을 활용해 2개의 네트워크를 1개로 통합하여 계산

: 2차원 데이터로 늘어난 변수들을 활용해 연산 처리

[code]

#NN

K = tf.sigmoid(tf.matmul(X, W1) + b1) // 첫번째 k

hypothesis = tf.sigmoid(tf.matmul(K, W2) + b2) // H(x) 함수

Led 09-02 : Backpropagation

1. How can we learn W1,W2,B1,B2 from training data?

: cost의 기울기 값 계산 위해 미분 개념 활용

: 계산량 증가 - 문제점 발견

3. Backpropagation

: 계산 문제 해결 위해 도입

: 그래프의 형식으로 chain rule을 재해석

- 방법 1) foward : w=2, x=5, b=3 값을 넣어 g와 f를 계산

방법 2) backward : 좀 더 복잡한 형태일때, 가장 마지막 노드부터 계산

4. Back propagation in TensorFlow : TensorBoard

# cost function

cost = -tf.reduce_mean(Y*tf.log(hypothesis) + (1-Y)*tf.log(1-hypothesis))

5. Neural Net

NN - 2 layer

[Tensorflow code]

def neural_net(features):

layer1 = tf.sigmoid(tf.matmul(features, W1) + b1) # W1=[2,1], b1=[1]

layer2 = tf.sigmoid(tf.matmul(features, W2) + b2) # W2=[2,1], b1=[1]

hypothesis = tf.sgimoid(tf.matmul(tf.concat([layer1, layer2], -1), W3) + b3) # W3=[2,1], b3=[1]

return hypothesis

NN - vector

[Tensorflow code]

def neural_net(features):

layer = tf.sigmoid(tf.matmul(features, W1) + b1) # W1=[2,2], b1=[2]

hypothesis = tf.sigmoid(tf.matmul(layer, W2) + b2 # W2=[2,1], b2=[1]

return hypothesis

from http://trisha227.tistory.com/15 by ccl(A) rewrite - 2021-11-09 20:26:34