生成正半定矩阵的简单算法
我想生成正随机半定矩阵。 我正在寻找一种算法,或更优选的是用 C、matlab、java 或任何语言实现该算法的简单实现。
I want to generate positive random semi-definite matrices. I am looking for an algorithm or more preferably an simple implementation of the algorithm in C, matlab, java or any language.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
示例代码(Python):
Example code (Python):
您需要明确“随机”的定义。 您对所得矩阵有哪些限制? 您希望系数均匀分布还是正态分布? 您希望特征值具有特定的分布吗? (等等)
有多种方法可以生成正半定矩阵 M,包括:
出于数字原因,我可能会选择第二种方法是生成具有所需属性的对角矩阵,然后生成 Q 作为许多Householder 反射<的组合/a> (生成随机向量 v,缩放至单位长度,H = I - 2vvT); 我怀疑你想要使用 K * N,其中 N 是矩阵 M 的大小,K 是 1.5-3 之间的数字(我猜测这一点),以确保它具有足够的自由度。
您还可以使用 Givens 旋转 生成正交矩阵 Q:选择从 1 到 N 的 2 个不同值,然后围绕该对轴生成吉文斯旋转,角度在 0 到 2 * pi 之间均匀分布。 然后取其中的 K * N(与上段相同的推理),它们的组合产生 Q。
编辑:我猜测(不确定)如果你有独立生成且正态分布的系数,那么整个矩阵将是“正态分布”(无论这意味着什么)。 至少对于向量来说是这样。 (N 个独立生成的高斯随机变量,每个分量一个,为您提供一个高斯随机向量)对于均匀分布的分量来说,情况并非如此。
You need to be clear on your definition of "random". What are your constraints on the resulting matrix? Do you want the coefficients to be uniformly or normally distributed? Do you want the eigenvalues to have a particular distribution? (etc.)
There are a number of ways to generate positive semidefinite matrices M, including:
For numerical reasons I'd probably choose the second approach by generating the diagonal matrix with desired properties, then generating Q as the composition of a number of Householder reflections (generate a random vector v, scale to unit length, H = I - 2vvT); I suspect you'd want to use K * N where N is the size of the matrix M, and K is a number between 1.5-3 (I'm guessing on this) that ensures that it has enough degrees of freedom.
You could also generate an orthonormal matrix Q using Givens rotations: pick 2 distinct values from 1 to N and generate a Givens rotation about that pair of axes, with an angle uniformly distributed from 0 to 2 * pi. Then take K * N of these (same reasoning as above paragraph) and their composition yields Q.
edit: I'd guess (not sure) that if you have coefficients that are independently-generated and normally distributed, then the matrix as a whole would be "normally distributed" (whatever that means). It's true for vectors, at least. (N independently-generated Gaussian random variables, one for each component, gives you a Gaussian random vector) This isn't true for uniformly-distributed components.
如果你可以用你选择的语言生成一个随机矩阵,那么通过使用矩阵乘以其转置是半正定的属性,你可以生成一个随机正半定矩阵
在Matlab中它会像下面这样简单
If you can generate a random matrix in your chosen language, then by using the property that a matrix multiplied by its transpose is positive semi-definte, you can generate a random positive semi-definite matix
In Matlab it would be as simple as
正半定矩阵上的自然分布是 Wishart 分布。
Natural distributions on positive semidefinite matrices are Wishart distributions.
A'*A 将给出一个正半定矩阵当且仅当 A 是秩亏的。 因此,上述答案和从维基百科复制的答案通常并不正确。 要计算正半定矩阵,只需取任何矩形 m × n 矩阵 (m < n) 并将其乘以其转置即可。 即,如果B是m×n矩阵,其中m<1。 n,则 B'*B 是半定矩阵。 我希望这有帮助。
A'*A will give a positive semidefite matrix iff and only if A is rank-deficient. So the answers stated above and that copied from wikipedia are not generally true. To compute a positive semidefinite matrix simply take any rectangular m by n matrix (m < n) and multiply it by its transpose. I.e. if B is an m by n matrix, with m < n, then B'*B is a semidefinite matrix. I hope this helps.
澄清一点(我希望)。 令 A 为随机矩阵(例如,由随机正态变量填充),mxn,其中 m >= n。 那么如果 A 是满列秩的,A'A 将是正定的。 如果 A 的秩 < n 那么 A'A 将是半正定的(但不是
正定)。
m >= n 的随机正态矩阵几乎肯定是满秩的; 为了生成秩亏矩阵,可以附加一列或多列,这些列是其他列的线性组合。
To clarify a little (I hope). Let A be a random matrix (for example, populated by random normal variates), m x n with m >= n. Then if A is of full column rank, A'A will be positive definite. If A is of rank < n then A'A will be positive semidefinite (but not
positive definite).
A random normal matrix with m >= n will almost surely be of full rank; to generate a rank-deficient matrix one can append one or more columns that are linear combinations of other columns.