Professional Documents
Culture Documents
Thien Huynh-The
HCM City Univ. Technology and Education
Jan, 2023
How is a neuron modeled?
• But what are the differences between neural networks and other methods of
machine learning? The answer is based on the Inductive Bias phenomenon, a
psychological phenomenon.
• An Inductive Bias of Linear Regression is the linear relationship between X and Y. In this way, a
line or hyperplane gets fitted to the data.
• When X and Y have a complex relationship, it can get difficult for a Linear Regression method
to predict Y. For this situation, the curve must be multi-dimensional or approximate to the
relationship.
• Feed forward neural networks are ANN in which nodes do not form loops. This type
of neural network is also known as a multi-layer neural network as all information is
only passed forward.
• During data flow, input nodes receive data, which travel through hidden layers, and
exit output nodes. No links exist in the network that could get used to by sending
information back from the output node.
• A feed forward neural network approximates functions in the following way:
• An algorithm calculates classifiers by using the formula y = f*(x).
• Input x is therefore assigned to category y.
• According to the feed forward model, y = f(x;θ). This value determines the closest
approximation of the function.
• Working principle
• This model multiplies inputs with weights as they enter the layer.
• The weighted input values get added together to get the sum
• The sum of the values rises above a certain threshold, set at zero, the output value is usually
1, while if it falls below the threshold, it is usually -1.
Input layer:
• The neurons of this layer receive input and pass it on to the other layers of the network.
• Feature or attribute numbers in the dataset must match the number of neurons in the input
layer.
Output layer:
• According to the type of model getting built, this layer represents the forecasted feature.
Hidden layer:
• Input and output layers get separated by hidden layers. Depending on the type of model, there
may be several hidden layers.
• There are several neurons in hidden layers that transform the input before actually transferring
it to the next layer. This network gets constantly updated with weights in order to make it
easier to predict.
Neuron weights:
• Neurons get connected by a weight, which measures
their strength or magnitude. Similar to linear
regression coefficients, input weights can also get
compared, normally values between 0 and 1.
Neuron:
• Artificial neurons get used in FFNN, which later get
adapted from biological neurons.
• Neurons function in two ways: they create weighted
input sums and they activate the sums to make them
normal.
• Activation functions can either be linear or nonlinear.
Neurons have weights based on their inputs. During
the learning phase, the network studies these
weights.
HCMUTE AI Foundations and Applications 03/18/2024 10
Layers of FFNN
Activation function:
• Neurons are responsible for making decisions in this
area.
• According to the activation function, the neurons
determine whether to make a linear or nonlinear
decision. Since it passes through so many layers, it
prevents the cascading effect from increasing neuron
outputs.
• An activation function can be classified into three
major categories: sigmoid, Tanh, and Rectified Linear
Unit (ReLu).
So easy, right?
Cross-entropy loss
The loss of a network measure the cost
incurred from incorrect prediction
• Loss function
03/18/2024 HCMUTE 16
Gradient Descent
• Bằng một phép nội suy, anh ta suy ra được phương trình của đồ thị hàm số
Hay nói cách khác là đi men theo mặt dốc, đây chính
là ý tưởng của thuật toán Gradient Descent.
Trong hình phía trên, các điểm bên trái của điểm local
minimum màu xanh lục có đạo hàm âm, các điểm bên phải có
đạo hàm dương.
Và đối với hàm số này, càng xa về phía trái của điểm local
minimum thì đạo hàm càng âm, càng xa về phía phải thì đạo
hàm càng dương.
Điểm màu xanh lục là điểm local minimum (cực tiểu), xt+1=xt+
và cũng là điểm làm cho hàm số đạt giá trị nhỏ
nhất trong đó Δ là một đại lượng ngược dấu với đạo hàm
• local minimum để thay cho điểm cực tiểu
f(xt).
• global minimum để thay cho điểm mà tại đó hàm
số f(x) đạt giá trị nhỏ nhất
• Dùng phương pháp gradient descent, tìm điểm cực tiểu của phương trình sau
f(x)=x2+5sin(x)
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
print('load data from MNIST')
mnist = tf.keras.datasets.mnist
(x_train,y_train), (x_test,y_test) = mnist.load_data()
# get the digit 0 - 9
dig = np.array([1,3,5,7,9,11,13,15,17,19])
x = x_train[dig,:,:]
y = np.eye(10,10)
plt.subplot(121)
plt.imshow(x[0])
plt.subplot(122)
plt.imshow(x[1])
x = np.reshape(x,(-1,784))/255
W = np.random.uniform(-0.1,0.1,(10,784))
# matrix multiplication
o = sigmoid(np.matmul(x,W.transpose()))
print('output of first neuron with 10 digits ', o[:,0])
fig = plt.figure()
plt.bar([i for i, _ in enumerate(o)],o[:,0])
plt.show()