You are on page 1of 7

Name: Jason Dinh

ID: 2597957

Homework 1

Problem 1:
From the script generate_two_moons, the meaning of input/output variables:
[X,Y,Xt] = generate_two_moons(r,w,d,N,seed,display)
Input:
-

r: radius of 2 two moons


w: width of the 2 moons
d: distance between the 2 moons
N: number of samples to generate in each moon
seed: create different random for each time running the script
display: 1 shows the 2 moons after generation, 0 no display after generation

Output:
-

X: 2N2 matrix coordinates of samples of the 2 moons


Y: 2N1 vector identify sample: +1 for top moon and -1 for bottom moon
Xt: uniformly spaced points on a grid

Result:

For r = 10, w = 6, d = -4, N = 10000, seed = 3, display = 1:

Name: Jason Dinh


ID: 2597957

Homework 1

Problem 2:
From the script NN_Perception(dist), variable dist represent the distance between two moons.
The weight/bias vector w(n) is represented by a 31 vector.
The input data x(n) is being stored by a 31 vector in which first element is 1, the other elements
are coordinates of a randomly selected point in (number of training + number of testing sets)
samples.
The desired values d(n) are being stored by the value of class (1: class 1, -1: class 2) from the
selected point.
The learning rate parameter (n) is being stored by a 1 [number of training sets] vector
The learning rate parameter is not constant. It is being adjusted by decreasing the learning rate
from 0.9 to 0.00001 in 1000 steps
The number of training epochs is 50.
Results of running the script with radius = 10, width = 6, distance = -4, number of training sets:
1000, number of testing sets = 2000, epochs = 50.

Name: Jason Dinh


ID: 2597957

Homework 1

Problem 3:
a.
Find the bias and weight for:
AND operation
OR operation
COMPLEMENT operation

My Rosenblats Perception to find weight/bias value:


function [W n_time] = Perception(X,Y)
% W: weight/bias vector
% n_time: times of fixing weight
% X: Input matrix
% Y: Output vector
[m n] = size(X);
W = zeros(n,1);
er = 1;
n = 0.1;
n_time = 1;
while er == 1
er = 0;
for i = 1:m
xi = X(i,:);
v = xi*W;
yi = signum(v);
if yi ~= Y(i)
W = W' + n*(Y(i) - yi)*xi;
W = W';
er = 1;
n_time = n_time + 1;
end
end
end
end

The activate function signum:


function [ y ] = signum(v)
if v >= 0
y = 1;
else
y = 0;
end
end

For OR operation:
X0
1
1
1
1

X1
0
0
1
1

X2
0
1
0
1

Y
0
1
1
1

Result:
3

Name: Jason Dinh


ID: 2597957

Homework 1

so b = -0.1, w1 = 0.1, w2 = 0.1


-

Testing:
X1

X2

0
0
1
1

0
1
0
1

V=

w.x

+b

-0.1
0
0
0.1

0
1
1
1

For AND operation: I change the activate function into


y= 1if v >0
0 if v 0

X0
1
1
1
1
Result:

Testing:

X1
0
0
1
1

X2
0
1
0
1

Y
0
0
0
1

so b = -0.2, w1 = 0.2, w2 = 0.1


X1

X2

0
0
1
1

0
1
0
1

V=

w.x

+b

-0.2
-0.1
0
0.1

0
0
0
1

For COMPLEMENT operation

X0
1
1
Result:

X1
1
0

X2
0
1

Name: Jason Dinh


ID: 2597957

Homework 1

so w1 = -0.2 and b = 0.2


X1
0
1

V=

w.x
0.2
0

+b

Y
1
0

b. From the truth table of XOR operation, I have the diagram:


We cannot find any lines that separate
these 4 points into 2 separate classes.
Therefore, Rosenblatts perception cannot
be used

Name: Jason Dinh


ID: 2597957

Homework 1

Problem 4:

Name: Jason Dinh


ID: 2597957

Homework 1

Problem 5:
Running NN_Perception script for distance d = 0:

Generated two half moons

Learning Curve
-

The classification error rate: 0.67%