Course Material - Artificial Intelligence-Week2 - Update
Course Material - Artificial Intelligence-Week2 - Update
Wonsu Kim
KISTI School
Contents
source : ‘From Vision to Actions: Towards Adaptive and Autonomous Humanoid Robots’, Jürgen Schmidhuber
• The second advantage is that even if a few units malfunction, the overall system
still functions without significant issues.
Input Weight
Activation
Function f
Output
y
Threshold
bias
Output
Intuition
𝑑 − 𝑦 needs to be adjusted toward 0!
Input: training data (x1, d1)~ (xm, dm): xk→input, dk→target 𝑑 − 𝑦 < 0 ∶ The weight vector should align less
1. Initialize all weights w and bias b to 0 or small random values. with the input vector 𝑥
⇒ decreased 𝒘 𝒙, decreased 𝒚
2. while (repeat until weights no longer change)
For each training data xk and target dk:
learning rate
perceptron_fit(X, y, 6)
𝒙𝟏 𝒙𝟐 𝒚
perceptron_predict(X, y)
𝒙𝟏
𝒙𝟐 𝒚
UST AI Class - 2025 10
Output
epoch= 0 ======================
Current Input= [0 0 1] Answer= 0 Output= 0 Changed Weights= [0. 0. 0.]
Current Input= [0 1 1] Answer= 0 Output= 0 Changed Weights= [0. 0. 0.]
Current Input= [1 0 1] Answer= 0 Output= 0 Changed Weights= [0. 0. 0.]
Current Input= [1 1 1] Answer= 1 Output= 0 Changed Weights= [0.2 0.2 0.2]
================================
epoch= 1 ======================
Current Input= [0 0 1] Answer= 0 Output= 1 Changed Weights= [0.2 0.2 0. ]
Current Input= [0 1 1] Answer= 0 Output= 1 Changed Weights= [ 0.2 0. -0.2]
Current Input= [1 0 1] Answer= 0 Output= 0 Changed Weights= [ 0.2 0. -0.2]
Current Input= [1 1 1] Answer= 1 Output= 0 Changed Weights= [0.4 0.2 0. ]
================================
epoch= 2 ======================
Current Input= [0 0 1] Answer= 0 Output= 0 Changed Weights= [0.4 0.2 0. ]
Current Input= [0 1 1] Answer= 0 Output= 1 Changed Weights= [ 0.4 0. -0.2]
Current Input= [1 0 1] Answer= 0 Output= 1 Changed Weights= [ 0.2 0. -0.4]
Current Input= [1 1 1] Answer= 1 Output= 0 Changed Weights= [ 0.4 0.2 -0.2]
================================
epoch= 3 ======================
Current Input= [0 0 1] Answer= 0 Output= 0 Changed Weights= [ 0.4 0.2 -0.2]
Current Input= [0 1 1] Answer= 0 Output= 0 Changed Weights= [ 0.4 0.2 -0.2]
Current Input= [1 0 1] Answer= 0 Output= 1 Changed Weights= [ 0.2 0.2 -0.4]
Current Input= [1 1 1] Answer= 1 Output= 0 Changed Weights= [ 0.4 0.4 -0.2]
UST AI Class - 2025
================================ 11
Output
epoch= 4 ======================
Current Input= [0 0 1] Answer= 0 Output= 0 Changed Weights= [ 0.4 0.4 -0.2]
Current Input= [0 1 1] Answer= 0 Output= 1 Changed Weights= [ 0.4 0.2 -0.4]
Current Input= [1 0 1] Answer= 0 Output= 0 Changed Weights= [ 0.4 0.2 -0.4]
Current Input= [1 1 1] Answer= 1 Output= 1 Changed Weights= [ 0.4 0.2 -0.4]
================================
epoch= 5 ======================
Current Input= [0 0 1] Answer= 0 Output= 0 Changed Weights= [ 0.4 0.2 -0.4]
Current Input= [0 1 1] Answer= 0 Output= 0 Changed Weights= [ 0.4 0.2 -0.4]
Current Input= [1 0 1] Answer= 0 Output= 0 Changed Weights= [ 0.4 0.2 -0.4]
Current Input= [1 1 1] Answer= 1 Output= 1 Changed Weights= [ 0.4 0.2 -0.4]
================================
0 0 -> 0
0 1 -> 0
1 0 -> 0
1 1 -> 1
# Creating Perceptron. tol: stop condition. random_state: seed for random number
clf = Perceptron(tol=1e-3, random_state=0)
# Training
clf.fit(X, y)
# Testing
print(clf.predict(X))
[0 0 0 1]
𝒙𝟐
𝒙𝟏
𝒙𝟏 𝒙𝟐 𝒚
𝒙𝟏
𝒙𝟐
𝒙𝟐
𝒙𝟐
How can you
separate them with
one line?
𝒙𝟏
𝒙𝟏
UST AI Class - 2025 14
Training Perceptron for XOR
from sklearn.linear_model import Perceptron
# Creating Perceptron. tol: stop condition. random_state: seed for random number
clf = Perceptron(tol=1e-3, random_state=0)
# Training
clf.fit(X, y)
# Testing
print(clf.predict(X))
[0 0 0 1]
Learning does not occur at all. The perceptron can learn AND or
OR operations, but why can't it learn the XOR operation?
UST AI Class - 2025 15
Linearly separable problems
• In their 1969 book "Perceptrons," Minsky and Papert mathematically proved that
a single-layer perceptron cannot learn the XOR problem.
Output
• The XOR operation cannot be correctly classified using a single straight line.
• However, if you use two straight lines, you can classify XOR inputs correctly.
• If you use two straight lines, you can classify XOR inputs correctly.
𝒙𝟏 𝒙𝟐 𝒚𝟏 𝒚𝟐 𝒚 Target
𝐵𝑖𝑎𝑠 = −0.5
0 0 𝐻 −0.5 = 0 𝐻 −1.5 = 0 𝐻 0 =0 0
𝑤 =1
𝑤′ =1 𝐵𝑖𝑎𝑠 0 1 𝐻 0.5 = 1 𝐻 −0.5 = 0 𝐻 1 =1 1
𝑤 =1 Bias = 0
1 0 𝐻 0.5 = 1 𝐻 −0.5 = 0 𝐻 1 =1 1
𝑤 =1
1 1 𝐻 1.5 = 1 𝐻 0.5 = 1 𝐻 −1 = 0 0
𝑤′ = −2
𝑤 =1
Bias = −1.5
𝐵𝑖𝑎𝑠 𝑦 = 𝐻(𝑤 𝑥 + 𝑤 𝑥 + 𝑏 ) 𝐻: Step function
b 𝑦 = 𝐻(𝑤 𝑥 + 𝑤 𝑥 + 𝑏 )
𝑦 = 𝐻(𝑤′ 𝑦 + 𝑤′ 𝑦 + 𝑏)
Backpropaga
tion!
output
Error
Calculation ⇒ The error should decrease
through repeated forward
and backward passes.
Backward pass
UST AI Class - 2025 23
Activation Function
• Role: Transforms the output of the previous layer and passes the signal to the
neurons in the next layer
• In the perceptron, a step function was used as the activation function, but in
MLPs, various “nonlinear” functions are used as activation functions.
Input Weight
A
Out
put
Activation
Function
bias
Two networks
perform the
same function.
Two
Two networks
networks perform
perform the
the same
same function.
function.
• The step function is a function that outputs 1 if the sum of the input signals
exceeds 0, and 0 otherwise.
• The sigmoid function is a traditional activation function used since the 1980s. It
has an S-shaped curve and is defined as:
• The ReLU (Rectified Linear Unit) function outputs the input directly if it is greater
than 0, and outputs 0 if the input is less than or equal to 0.
• The `tanh()` function is provided by NumPy. It is notable for its output range,
which is from -1 to +1.
• The feed-forward pass refers to the process in which input signals are fed into
the input layer units and then propagate through the hidden layers to reach the
output layer.
Check out
Forward pass Forward pass
out
Input put Calculating
Error
Backward pass
Two networks perform the same function.
Two networks
Two networks perform
perform
the same
the function.
same function.
It’s a matrix
multiplication!
It’s a famous
Input Weight Bias
equation in NN!
ℎ 𝑤 𝑤 𝑏
𝑤 𝑤 𝑥
ℎ =𝑓 𝑥 + 𝑏
ℎ 𝑤 𝑤 𝑏
• If the output value is incorrect, how should the weights be adjusted? When
training a neural network, the error between the output and target values (i.e.,
desired output) is used. Weights are adjusted in a direction that minimizes this
error. Check out
Error
Forward pass Calculation
out
Input put Calculating
Error
Backward pass
Label
Two networks perform the same function.
• The total error is the sum of the squared differences between the target output
values and the actual output values for all output nodes.
Cat 1.0
Otherwise 0.0
or
Dog 1.0
Otherwise 0.0
layer4
layer3
layer1 layer2
Two networks perform the same function.
28 pixels
28 pixels
0 1 2 3 4 5 6 7 8 9 ← corresponding digits
target = np.array([ 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]) ← our target values
y = np.array([ 0.9, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ) ← outputs from the model
>>> MSE(target, y)
0.81 ← calculated loss (seem large)
y = np.array([ 0.0, 0.0, 0.8, 0.1, 0.0, 0.0, 0.0, 0.1, 0.0, 0.0 ]) ← revised outputs from the model
>>> MSE(target, y)
0.029999999999999992 ← calculated loss (improved!!)
Error
Calculation
Backward pass
• In the backward pass, the process of adjusting weights uses the errors computed
in the previous step. The backpropagation algorithm is employed here.
Backpropagation approaches the problem of minimizing the loss function as an
optimization problem.
Check out
Forward pass Backward pass
out
Input put Calculating
Error
Backward pass
UST AI Class - 2025 41
The process of adjusting weights
The process of adjusting weights is akin to tuning a radio by adjusting the dial to find the correct
frequency.
• In practice, you can compute the output of the neural network by increasing or
decreasing the weights, and then compare this output with the target to
recalculate the error. However, this method is time-consuming because it
requires recalculating the network’s output every time a weight is changed. Is
there a better method?
Programming Language
Interpreter language
Python
Deep Learning
Machine Learning
• Navigator
- Move/Add Table of
Contents in Notepad
- Code snippet
- File Explorer
• Notepad
- Code cell and Text cell
- Display result of a code cell
Text Cell
Code Cell
Execution Result
• Notepad
- Code cell and Text cell
- Display result of a code cell
Colab
Source: https://zerowithdot.com/colab-github-workflow/