3-3 Softmax 구현
·
Deep Learning/Deep learning Bacis Mathematics
IO of Softmax¶ In [2]: import tensorflow as tf from tensorflow.keras.layers import Activation logit = tf.random.uniform(shape=(8, 5), minval=-10, maxval=10) softmax_value = Activation("softmax")(logit) softmax_sum = tf.reduce_sum(softmax_value, axis=1) print("Logits: \n", logit.numpy()) print("Probabilities: \n", softmax_value.numpy()) print("Sum of softmax values: \n", softmax_sum) Logits: [[-8..
3-2 Sigmoid 구현
·
Deep Learning/Deep learning Bacis Mathematics
The Graphs of Odds and Logit¶ In [12]: import numpy as np import tensorflow as tf import matplotlib.pyplot as plt plt.style.use('_classic_test_patch') p_np = np.linspace(0.01, 0.99, 100) p_tf = tf.linspace(0.01, 0.99, 100) # 오즈 계산 odds_np = p_np/(1 - p_np) odds_tf = p_tf/(1 - p_tf) # 로짓 logit_np = np.log(odds_np) logit_tf = tf.math.log(odds_tf) fig, axes = plt.subplots(2, 1, figsize=(15,..
3-1 Sigmoid & Softmax 이론
·
Deep Learning/Deep learning Bacis Mathematics
신경망의 핵심은 데이터에서 복잡한 패턴을 학습하여 예측을 수행하는 것이다. 이 과정에서 활성화 함수는 매우 중요한 역할을 한다. 오늘은 신경망에서 널리 사용되는 두 가지 활성화 함수, 시그모이드(Sigmoid)와 소프트맥스(Softmax)에 대해 자세히 살펴본다. 로짓에서 확률로: 시그모이드 함수의 유도 과정 시그모이드 함수는 오즈(odds)와 로짓(logit)의 개념에서 출발한다. 오즈는 성공 확률 대 실패 확률의 비율을 의미하며, 로짓은 이 오즈의 로그 값을 취한 것이다. 시그모이드 함수는 로짓의 역함수로, 이를 통해 주어진 로짓 값을 확률로 변환할 수 있다. 시그모이드 함수: 이진 분류의 핵심 여기서 l은 로짓이며, 시그모이드 함수의 출력값 p는 0과 1 사이의 값을 갖는다. 이는 확률로 해석될 수..
2-4 Model Implementation with Dense layer 구현
·
Deep Learning/Deep learning Bacis Mathematics
Model Implementation with Sequential Method¶ In [ ]: from tensorflow.keras.layers import Dense from tensorflow.keras.models import Sequential model = Sequential() model.add(Dense(units=10, activation='sigmoid')) model.add(Dense(units=20, activation='sigmoid')) Model Implementation with Model-subclassing¶ In [ ]: from tensorflow.keras.layers import Dense from tensorflow.keras.mode..
2-3 Cascaded_Dense_Layers 구현
·
Deep Learning/Deep learning Bacis Mathematics
Shapes of cacaded Dense Layers¶ In [1]: import tensorflow as tf from tensorflow.keras.layers import Dense N, n_feature = 4, 10 X = tf.random.normal(shape=(N, n_feature)) n_neurons = [3, 5] dense1 = Dense(units=n_neurons[0], activation="sigmoid") dense2 = Dense(units=n_neurons[1], activation="sigmoid") # forward propagation A1 = dense1(X) Y = dense2(A1) # get weight/bias W1, B1 = dense1.get_weigh..
2-2 Dense Layer 구현
·
Deep Learning/Deep learning Bacis Mathematics
shapes of Dense Layers¶ In [1]: import tensorflow as tf from tensorflow.keras.layers import Dense N, n_feature = 8, 10 X = tf.random.normal(shape=(N, n_feature)) n_neuron = 3 dense = Dense(units=n_neuron, activation="sigmoid") Y = dense(X) W, B = dense.get_weights() print("=============Input/Weight/Bias============") print("X : ", X.shape) print("W : ", W.shape) print("B : ", B.shape) print("Y :..
2-1 Dense Layer 이론
·
Deep Learning/Deep learning Bacis Mathematics
Dense Layer 의 구성 요소: 뉴런 벡터와 층(Layer): 뉴런 벡터는 해당 층의 뉴런의 출력값들을 나타낸다. 각 층(Layer)는 하나 이상의 뉴런으로 구성되며, 각 뉴런은 다음 층으로의 입력값을 생성한다. 가중치와 바이어스(Weights and Bias): 각 밀집층은 입력에 적용되는 가중치 행렬(W[i])과 바이어스 벡터(b[i])를 가진다. 가중치는 입력 신호의 중요도를 조절하고, 바이어스는 뉴런의 활성화 임계값을 조정한다. 전방 전파(Forward Propagation): 계산 과정: 입력 벡터는 가중치 행렬과 내적한 다음, 바이어스가 더해지고 활성화 함수를 통과하여 출력 벡터를 생성한다. 이 과정은 첫 번째 층에서 시작하여 네트워크를 통해 순차적으로 진행된다. 활성화 함수(Activa..
1-3. Artificial Nuerons 구현 (2)
·
Deep Learning/Deep learning Bacis Mathematics
Activation Layer¶ In [5]: import tensorflow as tf from tensorflow.math import exp, maximum from tensorflow.keras.layers import Activation x = tf.random.normal(shape=(1, 5)) # import Activation func sigmoid = Activation('sigmoid') tanh = Activation('tanh') relu = Activation('relu') #foward propagation(Tensorflow) y_sigmoid_tf = sigmoid(x) y_tanh_tf = tanh(x) y_relu_tf = relu(x) print("x = {}\n{}"..
1-2. Artificial Nuerons 구현 (1)
·
Deep Learning/Deep learning Bacis Mathematics
Affine Function¶ In [2]: import tensorflow as tf from tensorflow.keras.layers import Dense from tensorflow.keras.layers import Conv2D x = tf.constant([[10.0]]) # input setting (Note : input은 matrix 형태 ) dense = Dense(units=1, activation="linear") # imp.an affine function y_tf = dense(x) # forward propagation + p arams initialization W, B = dense.get_weights() # get weight, bias # print results p..
1-1. Artificial Neurons 이론 (1)
·
Deep Learning/Deep learning Bacis Mathematics
인공 뉴런 - 매개변수 함수: 인공 뉴런 모델은 다양한 수학적 함수를 매개변수로 사용하여 입력 데이터를 변환한다. 예를 들어, 지수 함수(ex)와 로그 함수(log(x))는 데이터를 변환하는 데 사용되는 기본적인 함수 유형이다. 이러한 함수들은 인공 뉴런의 출력을 결정하는데 중요한 역할을 한다. 인공 뉴런 - 텐서 계산의 계층 구조: 텐서 연산은 인공 뉴런의 핵심적인 계산 메커니즘이다. 제로 차수(스칼라)부터 세 번째 차수(3D 텐서)까지의 연산을 설명하며, 이러한 연산은 복잡한 데이터 구조를 처리하는 데 필수적이다. 인공 뉴런 - 데이터셋(X 데이터): 인공 뉴런 학습에 사용되는 데이터셋의 구조에 대해 설명한다. 이 구조는 학습 과정에서 입력 데이터가 어떻게 조직되고, 처리되는지에 대한 기초를 제공한다..