Learning XOR - Gradient Based Learning - Hidden Units
Learning XOR - Gradient Based Learning - Hidden Units
Perceptrons 𝑏
𝑤
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑥1 1
𝑇 Output:
𝑤2
𝑥2
…
𝑤𝐷
𝑥𝐷
[]
𝑥1
• A perceptron is a function that maps
𝑥2
D-dimensional vectors to real numbers. 𝐱 = 𝑥3
• For notational convenience, we add an
…
extra input, called the bias input. 𝑥𝐷
The bias input is always equal to 1.
• is called the bias weight. It is optimized during training.
• are also weights that are optimized during training. 1
1
Perceptrons 𝑏
𝑤
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑥1 1
𝑇 Output:
𝑤2
𝑥2
…
𝑤𝐷
𝑥𝐷
• A perceptron computes its output in two steps:
Step 1:
Step 2:
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑥1 1
𝑇 Output:
𝑤2
𝑥2
…
𝑤𝐷
𝑥𝐷
• A perceptron computes its output in two steps:
Step 1:
Step 2:
• In a single formula:
3
Notation for 1 𝑤
0
𝑤
Bias Weight
𝑧=h ( 𝒘 𝒙 )
𝑥1 1
𝑇 Output:
𝑤2
𝑥2
…
𝑤𝐷
𝑥𝐷
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑥1 1
𝑇 Output:
Neurons 𝑥 𝑤 2
2
…
𝑤𝐷
𝑥𝐷
6
Activation
Functions
• A perceptron produces
output .
• Another choice for the
activation function :
the sigmoidal function.
7
Example: The AND Perceptron
• Suppose we use the step function for activation.
• Suppose boolean value false is represented as number 0.
• Suppose boolean value true is represented as number 1.
• Then, the perceptron below computes the boolean AND function:
–.
• Corresponds to case false AND false = false.
false AND false = false
1 false AND true = false
𝑏= true AND false = false
− 1. true AND true = true
5
𝑤1 =1
𝑥1
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑇 Output:
𝑤 2 =1
𝑥2 9
Example: The AND Perceptron
• Verification: If and :
–.
• Corresponds to case false AND true = false.
false AND false = false
1 false AND true = false
𝑏= true AND false = false
− 1. true AND true = true
5
𝑤1 =1
𝑥1
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑇 Output:
𝑤 2 =1
𝑥2 10
Example: The AND Perceptron
• Verification: If and :
–.
• Corresponds to case true AND false = false.
false AND false = false
1 false AND true = false
𝑏= true AND false = false
− 1. true AND true = true
5
𝑤1 =1
𝑥1
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑇 Output:
𝑤 2 =1
𝑥2 11
Example: The AND Perceptron
• Verification: If and :
–.
• Corresponds to case true AND true = true.
false AND false = false
1 false AND true = false
𝑏= true AND false = false
− 1. true AND true = true
5
𝑤1 =1
𝑥1
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑇 Output:
𝑤 2 =1
𝑥2 12
Example: The OR Perceptron
• Suppose we use the step function for activation.
• Suppose boolean value false is represented as number 0.
• Suppose boolean value true is represented as number 1.
• Then, the perceptron below computes the boolean OR function:
–.
• Corresponds to case false OR false = false.
false OR false = false
1 false OR true = true
𝑏= true OR false = true
−0 true OR true = true
.5
𝑤1 =1
𝑥1
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑇 Output:
𝑤 2 =1
𝑥2 14
Example: The OR Perceptron
• Verification: If and :
–.
• Corresponds to case false OR true = true.
false OR false = false
1 false OR true = true
𝑏= true OR false = true
−0 true OR true = true
.5
𝑤1 =1
𝑥1
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑇 Output:
𝑤 2 =1
𝑥2 15
Example: The OR Perceptron
• Verification: If and :
–.
• Corresponds to case true OR false = true.
false OR false = false
1 false OR true = true
𝑏= true OR false = true
−0 true OR true = true
.5
𝑤1 =1
𝑥1
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑇 Output:
𝑤 2 =1
𝑥2 16
Example: The OR Perceptron
• Verification: If and :
–.
• Corresponds to case true OR true = true.
false OR false = false
1 false OR true = true
𝑏= true OR false = true
−0 true OR true = true
.5
𝑤1 =1
𝑥1
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑇 Output:
𝑤 2 =1
𝑥2 17
Example: The NOT Perceptron
• Suppose we use the step function for activation.
• Suppose boolean value false is represented as number 0.
• Suppose boolean value true is represented as number 1.
• Then, the perceptron below computes the boolean NOT function:
NOT(false) = true
1
𝑏= NOT(true) = false
0.5
𝑧=h ( 𝑏+𝒘 𝒙 ) 𝑇
𝑤1 =−1 Output:
𝑥1
18
Example: The NOT Perceptron
• Verification: If :
–.
• Corresponds to case NOT(false) = true.
NOT(false) = true
1
𝑏= NOT(true) = false
0.5
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑇
𝑤1 =−1 Output:
𝑥1
19
Example: The NOT Perceptron
• Verification: If :
–.
• Corresponds to case NOT(true) = false.
NOT(false) = true
1
𝑏= NOT(true) = false
0.5
𝑧=h ( 𝑏+𝒘 𝒙 )
𝑇
𝑤1 =−1 Output:
𝑥1
20
The XOR
Function
false XOR false = false
false XOR true = true
true XOR false = true
true XOR true = false
• As before, we represent
false with 0 and true with 1.
• The figure shows the four input points of the XOR function.
– red corresponds to output value true.
– green corresponds to output value false.
• The two classes (true and false) are not linearly separable.
• Therefore, no perceptron can compute the XOR function.
21
Our First Neural Network: XOR
• A neural network is built using perceptrons as building blocks.
• The inputs to some perceptrons are outputs of other perceptrons.
• Here is an example neural network computing the XOR function.
Logical OR
43