Professional Documents
Culture Documents
Part (1)
Exercise (1)
1. A. The neuron is linear
𝝋 = ( 𝒗 = 𝒚)
𝑛𝑒𝑡 = 𝑥, 𝑤, + 𝑥/ 𝑤/ + 𝑥0 𝑤0 + 𝑥1 𝑤1
𝑛𝑒𝑡 = (10𝑥0.8) + (−20𝑥0.2) + (4𝑥 − 1) + (−2𝑥 − 𝑜. 9) = 1.8
𝑦 = 1.8
4 1
1
5 2
2 1
6 3
3
7 4
10
Exercise (2)
1. A. AND
𝒙𝟐 𝒙𝟏 𝒅
0 0 0
0 1 0
1 0 0
1 1 1
𝒗 = 𝑥, 𝑤, + 𝑥/ 𝑤/ + 𝑏 < 0 , 𝑓𝑜𝑟 𝑦 = 0
𝒗 = 𝑥, 𝑤, + 𝑥/ 𝑤/ + 𝑏 ≥ 0 , 𝑓𝑜𝑟 𝑦 = 1
𝒙𝟐 𝒙𝟏 𝒙𝟏 𝒘 𝟏 + 𝒙𝟐 𝒘 𝟐 𝒚
0 0 0 0 𝑏 ≤ 0
0 1 𝑤, 0 𝑤, + 𝑏 ≤ 0
1 0 𝑤/ 0 𝑤/ + 𝑏 ≤ 0
1 1 𝑤, + 𝑤/ 1 𝑤, + 𝑤/ + 𝑏 > 0
1 , 𝑖𝑓 𝑣 ≥ 0
𝜑=<
0 , 𝑖𝑓 𝑣 < 0
𝒙𝟐 𝒙𝟏 𝒅 𝒗 𝒚
0 0 0 -1.5 0
0 1 0 -0.5 0
1 0 0 -0.5 0
1 1 1 0.5 1
Exercise (2)
1. B. OR
𝒙𝟐 𝒙𝟏 𝒅
0 0 0
0 1 1
1 0 1
1 1 1
𝒗 = 𝑥, 𝑤, + 𝑥/ 𝑤/ + 𝑏 < 0 , 𝑓𝑜𝑟 𝑦 = 0
𝒗 = 𝑥, 𝑤, + 𝑥/ 𝑤/ + 𝑏 ≥ 0 , 𝑓𝑜𝑟 𝑦 = 1
𝒙𝟐 𝒙𝟏 𝒙𝟏 𝒘 𝟏 + 𝒙𝟐 𝒘 𝟐 𝒚
0 0 0 0 𝑏 < 0
0 1 𝑤, 1 𝑤, + 𝑏 ≥ 0
1 0 𝑤/ 1 𝑤/ + 𝑏 ≥ 0
1 1 𝑤, + 𝑤/ 1 𝑤, + 𝑤/ + 𝑏 ≥ 0
𝑤, = 𝑤/ = 1. & 𝑏 = −0.5
𝒗 = 𝑥, 𝑤, + 𝑥/ 𝑤/ + 𝑏
1 , 𝑖𝑓 𝑣 ≥ 0
𝜑=<
0 , 𝑖𝑓 𝑣 < 0
𝒙𝟐 𝒙𝟏 𝒅 𝒗 𝒚
0 0 0 -0.5 0
0 1 0 0.5 1
1 0 0 0.5 1
1 1 1 1.5 1
Exercise (2)
2. A. AND
% Exercise (2): 2. AND
P = [0 0 1 1; 0 1 0 1];
T = [0 0 0 1];
net = newp([0 1; 0 1],1);
Y = net(P)
net.trainParam.epochs = 20;
net = train(net,P,T);
pause
Y = sim(net,P)% The output
W=net.IW{1,1} % The weights
B=net.b{1,1} % The bias
pause
figure
plotpv(P,T)
plotpc(W,B)
Exercise (2)
2. B. OR
% Exercise (2): 2. OR
P = [0 0 1 1; 0 1 0 1];
T = [0 1 1 1];
net = newp([0 1; 0 1],1);
Y = net(P)
net.trainParam.epochs = 20;
net = train(net,P,T);
pause
Y = sim(net,P)% The output
W=net.IW{1,1} % The weights
B=net.b{1,1} % The bias
pause
figure
plotpv(P,T)
plotpc(W,B)
Exercise (3)
1. A.
1 V
1
𝐸(𝑤) = 𝜎 / − 𝑟TU 𝑤 + 𝑤 V 𝑅T 𝑤
2 2
𝑑𝐸(𝑤) V
1
= − 𝑟TU + (𝑅T + 𝑅TV ) 𝑤
𝑑𝑤 2
𝑑𝐸(𝑤) 1 2 1.6364
= −[0.8182 0.354] + \] ^_ 𝑤
𝑑𝑤 2 1.6364 2
𝑑𝐸(𝑤) 1 0.8182
= −[0.8182 0.354] + ] ^𝑤
𝑑𝑤 0.8182 1
Ua(b)
To find the minimum: Ub
=0
1 0.8182
−[0.8182 0.354] + ] ^𝑤 = 0
0.8182 1
1 0.8182 d,
𝑤 = [0.8182 0.354] ∗ ] ^
0.8182 1
𝑑 / 𝐸(𝑤) 1
/
= (𝑅T + 𝑅TV )
𝑑𝑤 2
- 𝜼 = 𝟎. 𝟑
- 𝜼=𝟏
Exercise (4)
1. XOR Problem
𝒙𝟐 𝒙𝟏 𝒅
0 0 0
0 1 1
1 0 1
1 1 0
𝟏 , 𝒊𝒇 𝒗 ≥ 𝟎
𝝋=<
𝟎 , 𝒊𝒇 𝒗 < 𝟎
clc;
clear all;
close all;
% Input and output
P(:,1)=[0.1 1.2]'; P(:,2)=[0.7 1.8]';P(:,3)=[0.8 1.6]'; % Group 1
P(:,4)=[0.8 0.6]'; P(:,5)=[1 0.8]'; % Group 2
P(:,6)=[0.3 0.5]'; P(:,7)=[0 0.2]';P(:,8)=[-0.3 0.8]'; % Group 3
P(:,9)=[-.5 -1.5]'; P(:,10)=[-1.5 -1.3]'; % Group 4
T(:,1)=[0 0]'; T(:,2)=[0 0]';T(:,3)=[0 0]';
T(:,4)=[0 1]'; T(:,5)=[0 1]';
T(:,6)=[1 0]'; T(:,7)=[1 0]';T(:,8)=[1 0]';
T(:,9)=[1 1]'; T(:,10)=[1 1]';
% Creation of the net
net=perceptron;
% Training
net.trainParam.epochs = 20;
net = train(net,P,T);
% Check the output
Y=sim(net,P)
% To see the weights
W=net.IW{1,1}
% The bias
B=net.b{1}
% to plot data and boundaries on the same plot
figure;
plotpv(P,T)
plotpc(W,B)
- MLP with one hidden layer
clc;
clear all;
close all;
% % Input and output
P(:,1)=[0.1 1.2]'; P(:,2)=[0.7 1.8]';P(:,3)=[0.8 1.6]'; % Group 1
P(:,4)=[0.8 0.6]'; P(:,5)=[1.0 0.8]'; % Group 2
P(:,6)=[0.3 0.5]'; P(:,7)=[0.0 0.2]';P(:,8)=[-0.3 0.8]'; % Group 3
P(:,9)=[-0.5 -1.5]'; P(:,10)=[-1.5 -1.3]'; % Group 4
% Patterns
P(:,1)= [1 -1 1 1]';
P(:,2)= [1 1 -1 1]';
P(:,3)= [-1 -1 -1 1]';
% Targets
T(:,1)=[-1 -1]';
T(:,2)=[1 -1]';
T(:,3)=[1 -1]';
% Building a persepton neural net
net = feedforwardnet(10);
net = train(net,P,T);
y = net(P);
% Testing Pattern
pt=[1 -1 1 -1]';
Y=sim(net,pt)
b) Test your design by observing how the following test pattern would be
recognized.