Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem: These are notes that may be found helpful, and under them is a skeleton

ID: 3110749 • Letter: P

Question

Problem:



These are notes that may be found helpful, and under them is a skeleton of the matlab code that you can use to write the code on the lines saying "write you matlab code here"




I know the notes are in bad handwriting but try to read them, atleast try to complete tasks 1 & 2, because they should be very manageable. If task 3 is completed that would be awesome. Below is the code skeleton as I mentioned before.






To assist you to implement the algorithm in MatLab, I am providing you with a skeleton in the MatLab code below.
You are not required to use this MatLab skeleton/Matlab template. But it might make the task a lot easier for you. The Step 1 of the Algorithm, Step 2, Step 3 correspond to the 3 steps in the algorithm. In several places, it says, "Write your own code here". Those are places where you can insert your Matlab code.
The Matlab code begins with a section "Make the Data". After that section, you will have the 50 data samples in a matrix called Xmat. Each column of Xmat now contains one data sample, and the matrix has 50 columns.
The 3 steps of the algorithm that comes after the section "Make the Data" correspond to the 3 steps of the algorithm explained in the paper.
Note that at the end, there is a section that asks you to verify that the calculation of the matrix M_mat is correct. This is the place where you verify that the expression of Phi(Y) in equation (2) and in equation (6) are correct. These two equations can be found in the paper.
Note that when you make a mistake in this project, you should check that you have calculated the matrix M correctly. This is the matrix M in equation (6).
Dr. Enrico [see code below]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% Make the Data
%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
nrow = 60; dimN = 50; Nsamples = 50; K = 4;

patch = 20*ones(28, 20);
background = zeros(nrow, dimN);
seed = 13579;   
BigPrime = (2^31)-1;
  
Xmat = zeros(nrow*dimN,Nsamples);

index = 1;
  
  
for corner1 = 4:8
for corner2 = 4:8

for jj = 1:nrow
for kk = 1:dimN
seed = mod(16807*seed,BigPrime);
background(jj,kk) = 4*( seed/BigPrime );
end
end
picture = background;
picture([(corner1):(corner1+27)],[corner2:corner2+19]) = patch;

Xmat(:,index) = reshape(picture,nrow*dimN,1);
index = index + 1;
end   
end
  
for corner1 = 26:30
for corner2 = 26:30
  
for jj = 1:nrow
for kk = 1:dimN
seed = mod(16807*seed,BigPrime);
background(jj,kk) = 4*( seed/BigPrime );
end
end
picture = background;
picture([(corner1):(corner1+27)],[corner2:corner2+19]) = patch;

Xmat(:,index) = reshape(picture,nrow*dimN,1);
index = index + 1;
end
end
  

  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% Step 1 of the Algorithm
%%% Find the distance between each pair of data points x_j and x_k
%%% For each data point, find its K nearest neighbours
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%% Write your own code here


%%%
%%% each column stores the K nearest neighbours for that data point
%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% Step 2 of the Algorithm
%%% Solve for the weights for each data point
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%% Write your own code here

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% Step 3 of the Algorithm
%%% Compute the M matrix, call it M_mat
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Write your own code here

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% compute the eigenvectors of the matrix M_mat
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[V, D] = eig(M_mat);

%%% if the two smallest eigenvalues are both zero,
%%% then use the eigenvectors in the third and fourth column of matrix V.

%%% x_axis =   
%%% y_axis =

scatter(x_axis, y_axis)





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% Verfiy that the calculation of matrix M_mat is done correctly.
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% write your own code here

To assist you to implement the algorithm in MatLab, I am providing you with a skeleton in the MatLab code below.
You are not required to use this MatLab skeleton/Matlab template. But it might make the task a lot easier for you. The Step 1 of the Algorithm, Step 2, Step 3 correspond to the 3 steps in the algorithm. In several places, it says, "Write your own code here". Those are places where you can insert your Matlab code.
The Matlab code begins with a section "Make the Data". After that section, you will have the 50 data samples in a matrix called Xmat. Each column of Xmat now contains one data sample, and the matrix has 50 columns.
The 3 steps of the algorithm that comes after the section "Make the Data" correspond to the 3 steps of the algorithm explained in the paper.
Note that at the end, there is a section that asks you to verify that the calculation of the matrix M_mat is correct. This is the place where you verify that the expression of Phi(Y) in equation (2) and in equation (6) are correct. These two equations can be found in the paper.
Note that when you make a mistake in this project, you should check that you have calculated the matrix M correctly. This is the matrix M in equation (6).
Dr. Enrico [see code below]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% Make the Data
%%%   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
nrow = 60; dimN = 50; Nsamples = 50; K = 4;

patch = 20*ones(28, 20);
background = zeros(nrow, dimN);
seed = 13579;   
BigPrime = (2^31)-1;
  
Xmat = zeros(nrow*dimN,Nsamples);

index = 1;
  
  
for corner1 = 4:8
for corner2 = 4:8

for jj = 1:nrow
for kk = 1:dimN
seed = mod(16807*seed,BigPrime);
background(jj,kk) = 4*( seed/BigPrime );
end
end
picture = background;
picture([(corner1):(corner1+27)],[corner2:corner2+19]) = patch;

Xmat(:,index) = reshape(picture,nrow*dimN,1);
index = index + 1;
end   
end
  
for corner1 = 26:30
for corner2 = 26:30
  
for jj = 1:nrow
for kk = 1:dimN
seed = mod(16807*seed,BigPrime);
background(jj,kk) = 4*( seed/BigPrime );
end
end
picture = background;
picture([(corner1):(corner1+27)],[corner2:corner2+19]) = patch;

Xmat(:,index) = reshape(picture,nrow*dimN,1);
index = index + 1;
end
end
  

  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% Step 1 of the Algorithm
%%% Find the distance between each pair of data points x_j and x_k
%%% For each data point, find its K nearest neighbours
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%% Write your own code here


%%%
%%% each column stores the K nearest neighbours for that data point
%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% Step 2 of the Algorithm
%%% Solve for the weights for each data point
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%% Write your own code here

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% Step 3 of the Algorithm
%%% Compute the M matrix, call it M_mat
%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Write your own code here

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% compute the eigenvectors of the matrix M_mat
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[V, D] = eig(M_mat);

%%% if the two smallest eigenvalues are both zero,
%%% then use the eigenvectors in the third and fourth column of matrix V.

%%% x_axis =   
%%% y_axis =

scatter(x_axis, y_axis)





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%% Verfiy that the calculation of matrix M_mat is done correctly.
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% write your own code here

Summary of the Algorithm Find K nearest neighbours per data point. Reconstruction errors are measured by the function E(W) where the weight Wo is the contribution of the j th data point to the i-th reconstruction. Minimize E(W) subject to a sparseness constraint and an invariance constraint. each data point (X) is reconstructed only from its neighbours the rows of the weight matrix sum to 1. y,Wo-1. for each i. Finally, each input x, is mapped to a low dimensional output representing global intermal coordinates This is choosing the d.dimensional coordinates of each output minimize the embedding cost function: (2) Here, we fix the weights Wy while optimizing the output y. The enabedding is computed directly from the weight unatrix W: the original inputs i are not involved in this step. Let be a data point with K neighbours Let ur, be the reconstruction weights. Let be the error. Note that 7-20E, e), since Y," 1. We have (3) where (4) G is the local Gram matrix It is symmetric and positive GA GAR Positive definite means for any definite, symmetric means 20.

Explanation / Answer

clear all;
close all;

I=[3,4; 4,3; 4,4; 4,5; 5,4 ; 5,5; 5,6 ; 6,5];
I=I'
avrgx = mean(I')';

for j=1:1:8
for i=1:1:2
    J(:,j) = I(:,j) - avrgx;% substruct the average
    K=J;
end;

end;
K

cx= 1/8*(K*K')

[V,D] = eig(cx);         %eigen values of cov matrix

eigen_values = sort(diag(D,0),'Descend')

%%% taking only one eigen vector

V1=V;%(1,:)];%[V(3,:);V(4,:)];
%% calculating Y
y= V1*(K)

%% calculating cy

%y=y'

%%%% verifying properties
avrgy = mean(y')';

for p=1:1:8
for q=1:1:2
    M(:,p) = y(:,p) - avrgy;
    N=M;
end;

end;
N

cy= 1/8*(N*N')


%%%% inverse transform


x = V1'*y;
for z=1:8
  
    x(:,z)= x(:,z)+ avrgx;
    ReconstrucetdArray=x;
end

ReconstrucetdArray


%% mean square error
ems = sum(sum(eigen_values)- sum(eigen_values(1)));


%%%% compression ratio calculatio
Comp= size(I)/size(y);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote