- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我发现很难将理论与实现联系起来。如果能帮助我了解我的理解错误之处,我将不胜感激。
符号 - 粗体大写矩阵和粗体小写字母向量
<子> 是 上的数据集观察,每一个 变量。因此,鉴于这些观察到的 维数据向量,维主轴是 ,对于 在 其中是目标维度。
观察到的数据矩阵的主要成分将是 其中矩阵 ,矩阵 和矩阵 。
的列为 形成一个正交基础特征和输出 是最小化平方重构误差的主成分投影:
数据模型是
X(i,j) = A(i,:)*S(:,j) + noise
其中 PCA 应该在 X 上完成以获得输出 S。S 必须等于 Y。
问题一:缩减后的数据 Y 不等于模型中使用的 S。我的理解哪里错了?
问题2:如何重构使得误差最小?
请帮忙。谢谢。
clear all
clc
n1 = 5; %d dimension
n2 = 500; % number of examples
ncomp = 2; % target reduced dimension
%Generating data according to the model
% X(i,j) = A(i,:)*S(:,j) + noise
Ar = orth(randn(n1,ncomp))*diag(ncomp:-1:1);
T = 1:n2;
%generating synthetic data from a dynamical model
S = [ exp(-T/150).*cos( 2*pi*T/50 )
exp(-T/150).*sin( 2*pi*T/50 ) ];
% Normalizing to zero mean and unit variance
S = ( S - repmat( mean(S,2), 1, n2 ) );
S = S ./ repmat( sqrt( mean( Sr.^2, 2 ) ), 1, n2 );
Xr = Ar * S;
Xrnoise = Xr + 0.2 * randn(n1,n2);
h1 = tsplot(S);
X = Xrnoise;
XX = X';
[pc, ~] = eigs(cov(XX), ncomp);
Y = XX*pc;
更新 [8 月 10 日]
根据答案,这里是完整的代码
clear all
clc
n1 = 5; %d dimension
n2 = 500; % number of examples
ncomp = 2; % target reduced dimension
%Generating data according to the model
% X(i,j) = A(i,:)*S(:,j) + noise
Ar = orth(randn(n1,ncomp))*diag(ncomp:-1:1);
T = 1:n2;
%generating synthetic data from a dynamical model
S = [ exp(-T/150).*cos( 2*pi*T/50 )
exp(-T/150).*sin( 2*pi*T/50 ) ];
% Normalizing to zero mean and unit variance
S = ( S - repmat( mean(S,2), 1, n2 ) );
S = S ./ repmat( sqrt( mean( S.^2, 2 ) ), 1, n2 );
Xr = Ar * S;
Xrnoise = Xr + 0.2 * randn(n1,n2);
X = Xrnoise;
XX = X';
[pc, ~] = eigs(cov(XX), ncomp);
Y = XX*pc; %Y are the principal components of X'
%what you call pc is misleading, these are not the principal components
%These Y columns are orthogonal, and should span the same space
%as S approximatively indeed (not exactly, since you introduced noise).
%If you want to reconstruct
%the original data can be retrieved by projecting
%the principal components back on the original space like this:
Xrnoise_reconstructed = Y*pc';
%Then, you still need to project it through
%to the S space, if you want to reconstruct S
S_reconstruct = Ar'*Xrnoise_reconstructed';
plot(1:length(S_reconstruct),S_reconstruct,'r')
hold on
plot(1:length(S),S)
情节是这与答案中显示的非常不同。 S 只有一个组件与 S_reconstructed 的组件完全匹配。源输入S的整个原始二维空间不应该被重构吗?即使我切断噪声,也只有 S 的一个分量被完全重构。
最佳答案
我看到没有人回答你的问题,所以这里是:
您在 Y
中计算的是 X'
的主成分(您所说的 pc
具有误导性,这些不是主成分).这些 Y
列是正交的,并且应该大致跨越与 S
相同的空间(不完全是,因为你引入了噪音)。
如果你想重构Xrnoise
,你必须看看理论(例如here)并正确应用它:可以通过将主成分投影回原始空间来检索原始数据像这样:
Xrnoise_reconstructed = Y*pc'
那么,如果要重构S
,还需要通过pinv(Ar)*Xrnoise_reconstructed
进行改造。
更新 [8 月 10 日] 的回答:(8 月 12 日编辑)
您的 Ar
矩阵没有定义标准正交基,因此,转置 Ar'
不是反向变换。因此,我之前提供的答案是错误的。答案已在上面更正。
关于matlab - 如何使用缩减后的数据——主成分分析的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38690382/
我有一些带有反应组件抽象的外部 UI,我想从试剂中重用它们,有没有什么方法可以通过从 clojurescript 传递数据来直接渲染预定义的 react 组件。我是 clojurescript 初学者
我刚刚构建了一个库(Material Components库)from source并将本地Maven存储库添加到了我的项目中。现在,我可以通过将Log调用添加到库的本地源中来成功地进行一些外行调试。
我正在尝试测试呈现 grommet 的组件菜单 组件。索环 Menu 组件将绝对定位的菜单呈现到文档的顶层,作为子级插入到 body 中。因此它呈现在包装器的范围之外。我可以使用 document.b
如何创建一个凹形的 SKPhysicsBody? 我的猜测是创建一个由多个凸体组成的复合节点。我可以用任何其他方式“粘贴”它们,从而在它们之间创建 SKPhysicsJointFixed 吗? 最佳答
我正在开发一个食谱应用程序来帮助我妻子培养她的蛋糕爱好。这个想法是创建一个食谱数据库来保存她所有的蛋糕食谱。 每个食谱都有多种成分。每种成分都会有测量值(克、毫升、茶匙等),然后是数量。 我了解如何创
我正在使用 sklearn's PCA用于对大量图像进行降维。安装 PCA 后,我想看看组件的外观。 可以通过查看 components_ 属性来做到这一点。没有意识到这是可用的,我做了其他事情: e
我是一名优秀的程序员,十分优秀!