7 Neural Networks
7 Neural Networks
Ammar Hasan
Department of Electrical Engineering
College of Engineering
Artificial Neurons
Implementation in Python
Brain versus Computer
3
Artificial Neurons
Modeling a Neuron
9
𝑧 = 𝑤0 + 𝑥𝑖 𝑤𝑖
𝑖 weight on
weighted
sum ith input
index over
input connections
𝑧 = 𝑤0 + 𝑥𝑖 𝑤𝑖
𝑖 𝑦
0
𝑦=𝑓 𝑧 =𝑧
0
𝑧 = 𝑤0 + 𝑥𝑖 𝑤𝑖
𝑖
Linear Neurons: Example
13
Linear Neurons: Example
14
Linear Neurons: Example
15
Linear Neurons: Example
16
Linear Neurons: Example
17
Sigmoid Neurons: Used for Classification
18
y 0.5
0
0 z
Sigmoid Neurons: Example
19
Sigmoid Neurons: Example
20
Sigmoid Neurons: Example
21
Sigmoid Neurons: Example
22
Sigmoid Neurons: Example
23
Using Sigmoid Neurons for Classification
24
Neural Network
Neural Network
39
Modeling a Neural Network
40
Output layer
Input layer
Hidden layer
Operation of Neural Networks
41
….
Forward operation (continued)
44
Note: You also compute the cost function value to see if your network
is doing a good job. One example cost function can be the mean
squared error computed over the training, validation or testing
examples.
If e.g., one input instance is from Class 1 (in a binary classification
problem) and the output of the network is 0.8. Then the squared error
is (1-0.8)2 for this instance
Forward Operation
45
https://towardsdatascience.com/how-to-build-your-own-neural-network-from-scratch-in-python-68998a08e4f6
46
https://towardsdatascience.com/how-to-build-your-own-neural-network-from-scratch-in-python-68998a08e4f6
Backward Operation (Backpropagation)
47
Implementation in Python
NNs Classification in Python: Example
51
Input
Sepal Length, Sepal Output
NN Classifier
Width, Petal Length, Iris Species
Petal Width
TensorFlow Playground
55
McCulloch-Pitts (1943):
Firstcompute a weighted sum of the inputs. 1
Then send out a fixed size spike of activity if
output
the weighted sum exceeds a threshold.
McCulloch and Pitts thought that each spike is
like the truth value of a proposition and each 0
threshold
neuron combines truth values to compute the
truth value of another proposition! weighted input
Not included in syllabus
Extra: Binary Threshold Neurons
59
𝑧 = 𝑤0 + 𝑥𝑖 𝑤𝑖 1
𝑖
𝑦
1 if 𝑧 ≥ 0
𝑦=ቊ
0 otherwise 0
0 𝑧
Not included in syllabus
Extra: Binary Threshold Neurons: Example
60
Not included in syllabus
Extra: Binary Threshold Neurons: Example
61
Not included in syllabus
Extra: Binary Threshold Neurons: Example
62
Not included in syllabus
Extra: Binary Threshold Neurons: Example
63
Not included in syllabus
Extra: Binary Threshold Neurons: Example
64
Extra: inRectified
Not included Linear (ReLU) Neurons
syllabus
𝑧 = 𝑤0 + 𝑥𝑖 𝑤𝑖
𝑖
𝑧 if 𝑧 ≥ 0
𝑦
𝑦=ቊ 0 𝑧
0 otherwise
Not included in syllabus
Extra: ReLU Neurons: Example
66
Not included in syllabus
Extra: ReLU Neurons: Example
67
Not included in syllabus
Extra: ReLU Neurons: Example
68
Not included in syllabus
Extra: ReLU Neurons: Example
69
Not included in syllabus
Extra: ReLU Neurons: Example
70