PCA生成高斯和椭圆的初始矩阵?

时间:2014-02-18 09:55:14

标签: matlab matrix pca

我必须在Matlab中进行PCA以进行对象识别。

目前,我随机生成矩阵

 [a,InputMatrix] = sort(rand(100,20)); %Rows=100 Columns=20
 Average=mean(InputMatrix);
 CovarianceMatrix= cov(InputMatrix);
 %% Compute the Eigen Value and Eigen the Vector
 [EigVector,EigValue] = eigs(Matlab_Covariance);
 NewMatrix=(EigVector)*(EigValue)*(EigVector)';

 e1=EigVector(:,1); % Get the all the row at the first column
 e2=EigVector(:,2); % Get the all the row at the second column


 %% Plotting The Matrix with Eigen Value and Eigen Vector

 %creating all combinations of x and y coordinates
 [x,y]=meshgrid(1:size(InputMatrix,2),1:size(InputMatrix,1)); % 2= Columns 1= Rows
 x=x(:);
 y=y(:);

%plotting values of A such that X-Y axis represent the column and row coordinates of A
%respectively. Z-axis represents the value at that coordinate.
scatter3(x,y,InputMatrix(:),30,'rx');

%plotting the mean at the center of the coordinate system
hold on;

scatter3(mean([1:size(InputMatrix,2)]),mean([1:size(InputMatrix,1)]),
mean2(InputMatrix),60,'go','filled');
plot(e1,'k--');
plot(e2,'k--');

但是如果我在随机矩阵(InputMatrix)中执行PCA,我得到的PCA结果的特征向量e1和e2的形状将是错误的(当我在同一图中用InputMatrix绘制它们时)。

**PCA Output**

有人告诉我,对于输入矩阵/数据,它应该满足条件(以普通高斯分布)和椭圆形状(当我绘制它时)。 我想,我必须做旋转,疤痕和其他事情来做..

但我不明白..

可以涂抹请帮助我生成具有普通高斯和椭圆形状的随机矩阵吗? 请帮帮我T_T

1 个答案:

答案 0 :(得分:0)

这可以通过将隐藏分量矩阵乘以噪声向量来实现,即。例如,使用底层ICA模型。要获得更高的维度,只需更改cnum

close all; clear all;

cnum = 2;
nnum = 500;
C = rand(cnum, cnum); % hidden components
N1 = sort(rand(cnum, nnum)); % sorted uniform noise
D1 =  C * N1; % data
N2 = rand(cnum, nnum); % uniform noise
D2 =  C * N2; % data
N3 = randn(cnum, nnum); % Gaussian noise
D3 =  C * N3; % data

[V1, R1] = eig(cov(D3'));
[V2, R2] = eig(cov(D3'));
[V3, R3] = eig(cov(D3'));

subplot(1, 3, 1);
axis equal
hold on
plot(D1(1,:), D1(2,:), '.');
line([C(1, 1) 0 C(1, 2)], [C(2, 1) 0 C(2, 2)], 'Color', [1 .0 .0])
line([V1(1, 1) 0 V1(1, 2)], [V1(2, 1) 0 V1(2, 2)], 'Color', [.0 .0 .0])
title('Sorted uniform')

subplot(1, 3, 2);
axis equal
hold on
plot(D2(1,:), D2(2,:), '.');
line([C(1, 1) 0 C(1, 2)], [C(2, 1) 0 C(2, 2)], 'Color', [1 .0 .0])
line([V2(1, 1) 0 V2(1, 2)], [V2(2, 1) 0 V2(2, 2)], 'Color', [.0 .0 .0])
title('Uniform')

subplot(1, 3, 3);
axis equal
hold on
plot(D3(1,:), D3(2,:), '.');
line([C(1, 1) 0 C(1, 2)], [C(2, 1) 0 C(2, 2)], 'Color', [1 .0 .0])
line([V3(1, 1) 0 V3(1, 2)], [V3(2, 1) 0 V3(2, 2)], 'Color', [.0 .0 .0])
title('Gaussian')

print('-dpng', 'pca.png')

Result

红线代表隐藏的组件,黑线代表PCA组件。