svd

Comparing svd and princomp in R

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to get singular values of a matrix in R to get the principal components, then make princomp(x) too to compare results I know princomp() would give the principal components Question How to get the principal components from $d, $u, and $v (solution of s = svd(x) )? 回答1: One way or another, you should probably look into prcomp , which calculates PCA using svd instead of eigen (as in princomp ). That way, if all you want is the PCA output, but calculated using svd , you're golden. Also, if you type stats:::prcomp.default at the command

从主成分分析(PCA)到奇异值分解(SVD)

匿名 (未验证) 提交于 2019-12-03 00:41:02
主成分分析(principal factor analysis),简称PCA,是机器学习中非常常见的压缩降维方法。为什么需要压缩降维?是由于高维的样本本身存在冗余、稀疏的特点,直接把高维样本用于拟合或者模式识别,极其容易出现过拟合。而在处理实际问题时,与学习任务相关的也许仅是高维样本的某个低维分布,因而需要降维。(举个例子,如……) PCA的降维思想是,在高维的样本空间中,寻找一个低维的超平面,把所有高维样本投影于此超平面上,得到低维样本,并且使投影误差最小,或者使投影得到的样本最大可分。 紧接着上述提到的两种性质,在描述PCA的降维思想时,有以下两种定义方式: 最小误差形式 最大方差形式 可以从数学推导上证明,两种定义方式最终导出的结果等价,可以得到一样的算法。(两种方法的数学推导过程有时间再补充……) (算法流程待补充……) 总结来说,主成分分析涉及到计算数据集的均值 x x 和协方差矩阵 S S ,然后寻找协方差矩阵的对应于 M M 个最大特征值的 M M 个特征向量,从而得到投影矩阵。 PCA与SVD的关系主要体现在求解特征向量的过程。在一般介绍PCA算法原理的资料中,均是要先求得样本的协方差矩阵,然后从协方差矩阵中求解得特征值和特征向量。然而,对于归一化的样本,协方差矩阵 S = X X T S = X X T (待补充数学证明),而某些SVD的实现方法可以从样本矩阵 X

奇异值分解(SVD)的推导和应用简介

匿名 (未验证) 提交于 2019-12-03 00:34:01
特征值分解 学过线性代数的同学都知道,n阶方阵可以被特征分解为特征向量和特征值。特征向量可以组成特征矩阵,特征值组成对角矩阵,表示成下面的形式。如果是对称矩阵还可以分解成标准形。 奇异值分解 那么如果我们要处理的矩阵不是方阵它能不能被分解呢?当然可以。分解的方法被称为奇异值分解,即SVD。 奇异值分解在机器学习中的用途非常广泛,例如图像去噪,降维,另外还有推荐算法等。 假设有一个普通的矩阵A(m*n),我们可以将A表示成如下形式: 其中U、V为正交矩阵,E为m*n的对角阵。 证明上式: 图片来自张贤达老师的《矩阵分析与应用》 求解左奇异矩阵U和右奇异矩阵V 左奇异矩阵U:A*At得到一个m*m的方阵,于是我们对A*At进行特征值分解。即 ,我们能得到m个特征值和对应的m个特征向量。m个向量组成特征向量矩阵U。 右奇异矩阵V:At*A得到一个n*n的方阵,于是我们对At*A进行特征值分解。即 ,我们能得到n个特征值和对应的n个特征向量。n个向量组成特征向量矩阵V。 证明上方法能得到左右奇异矩阵 因为 ,所以有 为m*m方阵,对角线为 的特征值。可见分解 能够得到左奇异矩阵U。 为m*m方阵,对角线为 的特征值。 可见分解 能够得到右奇异矩阵V。 求解奇异值 将矩阵A乘以右奇异矩阵V,如下 将对应的左奇异向量和右奇异向量代入上面式子,可以求出对应的奇异值 lambda i

LinAlgError: SVD did not converge

匿名 (未验证) 提交于 2019-12-03 00:05:01
问题描述: 预测最小值时: pmax: 8 qmax: 8 求出来的BIC 最小的p值 和 q 值居然为: 27和0,比最大pmax还大!而且报“LinAlgError: SVD did not converge”的错误。 解决方法: 1、网上查找相关资料,说可能是空值问题,排除通用性的问题。于是尝试从自己代码中的问题着手解决问题。 2、逐步调试,打印出bic_matrix的值,发现居然不是8 8的矩阵,而是81 9的矩阵。认真审查代码后发现,原来是“bic_matrix.append(temp)”前少了一个缩进。 来源:51CTO 作者: 爱问西瓜爱大树 链接:https://blog.csdn.net/u011208984/article/details/100822241

机器学习实战 11- SVD

匿名 (未验证) 提交于 2019-12-02 23:39:01
1 SVD 相关理论 1.1 奇异值分解定义 SVD,即奇异值分解,矩阵论中学过内容,公式为: 用一张图来形象表达一下: 其中的奇异值矩阵,奇异值从大到小排列,而且减少的特别快,我们可以用前面最大的k个奇异值来表示这个原有矩阵,且保留大部分信息。如图: 1.2 与PCA有何勾结 之前我们解释过 PCA ,PCA 的本质就是将原数据投影到低维坐标系中,获取主要信息值,起到降维作用。 究竟 SVD 与其有何关系呢?我们看一下下面的公式推导,就明白了。 由上图可以比较出,PCA 中得到的 P 就是奇异值分解中的 V。 如果需要给列降维到 k ,则: 如果需要给行降维到 k ,则: 即 左奇异矩阵负责给行降维,一般用来减小无效样本。 1.3 优点与用途 优点: 当我们使用PCA的时候,用到协方差矩阵,但是当样本数量m大特征n也大的时候,协方差就不好计算,特征值和特征向量就不易求出。此时如果使用SVD,速度快很多,有人会说,奇异值分解时不也是利用了协方差矩阵么?其实不然这只是求取分解的一种方法,一般会使用迭代的办法,这里不赘述,只需明白它的计算速度远远加快,有兴趣可以看看这两篇文章: 并行计算奇异值: https://www.cnblogs.com/zhangchaoyang/articles/2575948.html 一篇关于奇异值计算的论文: http://www.cs.utexas

[转] 矩阵分解介绍

我们两清 提交于 2019-12-02 18:03:13
from: https://www.cnblogs.com/marsggbo/p/10152644.html#autoid-4-0-0 https://www.cnblogs.com/marsggbo/p/10156077.html 1 | 0 I. 行列式(Determinants)和迹(Trace) 1 | 1 1. 行列式(Determinants) 为避免和绝对值符号混淆,本文一般使用 𝑑 𝑒 𝑡 ( 𝐴 ) det(A)来表示矩阵 𝐴 A的行列式。另外这里的 𝐴 ∈ 𝑅 𝑛 × 𝑛 A∈Rn×n默认是方阵,因为只有方阵才能计算行列式。 行列式如何计算的就不在这里赘述了,下面简要给出行列式的各种性质和定理。 定理1 :当且仅当一个方阵的行列式不为0,则该方阵可逆。 定理2 :方阵 𝐴 A的行列式可沿着某一行或某一列的元素展开,形式如下: 沿着第 𝑖 i行展开: 𝑑 𝑒 𝑡 ( 𝐴 ) = ∑ 𝑘 = 1 𝑛 ( − 1 ) 𝑘 + 𝑖 𝑎 𝑖 𝑘 𝑑 𝑒 𝑡 ( 𝐴 𝑖 , 𝑘 ) det(A)=∑k=1n(−1)k+iaikdet(Ai,k) 沿着第 𝑖 i列展开: 𝑑 𝑒 𝑡 ( 𝐴 ) = ∑ 𝑘 = 1 𝑛 ( − 1 ) 𝑘 + 𝑖 𝑎 𝑘 𝑖 𝑑 𝑒 𝑡 ( 𝐴 𝑘 , 𝑖 ) det(A)=∑k=1n(−1)k+iakidet(Ak,i) 定理3

Solving an underdetermined scipy.sparse matrix using svd

北城以北 提交于 2019-12-02 00:35:50
问题 Problem I have a set of equations with variables denoted with lowercase variables and constants with uppercase variables as such A = a + b B = c + d C = a + b + c + d + e I'm provided the information as to the structure of these equations in a pandas DataFrame with two columns: Constants and Variables E.g. df = pd.DataFrame([['A','a'],['A','b'],['B','c'],['B','d'],['C','a'],['C','b'], ['C','c'],['C','d'],['C','e']],columns=['Constants','Variables']) I then convert this to a sparse CSC matrix

Solving an underdetermined scipy.sparse matrix using svd

倾然丶 夕夏残阳落幕 提交于 2019-12-01 20:45:36
Problem I have a set of equations with variables denoted with lowercase variables and constants with uppercase variables as such A = a + b B = c + d C = a + b + c + d + e I'm provided the information as to the structure of these equations in a pandas DataFrame with two columns: Constants and Variables E.g. df = pd.DataFrame([['A','a'],['A','b'],['B','c'],['B','d'],['C','a'],['C','b'], ['C','c'],['C','d'],['C','e']],columns=['Constants','Variables']) I then convert this to a sparse CSC matrix by using NetworkX table = nx.bipartite.biadjacency_matrix(nx.from_pandas_dataframe(df,'Constants',

Comparing svd and princomp in R

删除回忆录丶 提交于 2019-12-01 20:23:22
I want to get singular values of a matrix in R to get the principal components, then make princomp(x) too to compare results I know princomp() would give the principal components Question How to get the principal components from $d, $u, and $v (solution of s = svd(x) )? One way or another, you should probably look into prcomp , which calculates PCA using svd instead of eigen (as in princomp ). That way, if all you want is the PCA output, but calculated using svd , you're golden. Also, if you type stats:::prcomp.default at the command line, you can see how it's using the output of svd yourself.

Best fit plane for 3D data

最后都变了- 提交于 2019-11-30 21:15:09
问题 I have my 3D data X,Y,Z (Matrices with size NxM) I want to fit it to the best fit plane what I did: X = X(isfinite(X));% deleting the NaN because svd Doesn't accept them Y = Y(isfinite(Y)); Z = Z(isfinite(Z)); G = [X,Y,Z,ones(size(X(:)))]; [u s v] = svd(G,0); P = v(:,4); scalar = 2*P./P(1); P = P./scalar; % supposed to be my plane equation but there is something wrong and then recalculate the Z from X and Y Z = -(P(1)*X + P(2)*Y + P(4)) / P(3); I don't know what the problem is!! 回答1: Ok, so