用Mathnet数值库进行SVD​​重组似乎是错误的 [英] Svd recomposition with Mathnet numerics library seems wrong

查看:100
本文介绍了用Mathnet数值库进行SVD​​重组似乎是错误的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找Mathnet.Iridium和Mathnet.Numerics之间的非回归.这是我的代码,使用Mathnet.Numerics:

I'm looking for non regression between Mathnet.Iridium and Mathnet.Numerics. Here is my code, using Mathnet.Numerics :

double[][] symJaggedArray = new double[5][];
symJaggedArray[0] = new double[] { 3, 0, 0, 0, 0 };
symJaggedArray[1] = new double[] { 0, 2, 4, 0, 0 };
symJaggedArray[2] = new double[] { 0, 4, 5, -4, 5 };
symJaggedArray[3] = new double[] { 0, 0, -4, -8, 12 };
symJaggedArray[4] = new double[] { 0, 0, 5, 12, -5 };
symDenseMatrix = DenseMatrix.OfArray(new Matrix(symJaggedArray).CopyToArray());// not optimal but it's not the point

Svd svd = new UserSvd(symDenseMatrix , true);
Matrix<double> recompo = svd.U().Multiply(svd.W()).Multiply(svd.VT());

当我比较recompo和初始矩阵时,它们是不同的. 在将每个分解矩阵与以前的实现进行比较时,我发现了这种差异:

When i compare recompo and the initial matrix, they are different. I found this difference when comparing each decomposition matrix with the previous implementation :

  • U和singularValueDecomposition.LeftSingularVectors相等
  • W和sin​​gularValueDecomposition.S相等
  • VT和Matrix.Transpose(singulaValueDecomposition.RightSingularVectors)不同

最后,使用较早的API进行重组是正确的.

Finally, recomposition with older API is correct.

使用的MathNet.Numerics版本:Math.NET Numerics v2.5.0

MathNet.Numerics version used : Math.NET Numerics v2.5.0

所以我的问题是:用新的API重建初始矩阵时,我的错误在哪里?

So my question is : Where is my mistake when rebuilding initial matrix with the new API ?

RecompoMatrix =

RecompoMatrix =

  • 3 0 0 0 0
  • 0 -1.216846655456 2.83903817786199 1.4472680220698 2.89215520227421
  • 0 -2.46695399700557 8.657344064164 0.92863757484644 -0.31963101527516
  • 0 0.349540484418384 8.20515629935223 -2.26741625715781 -12.3049605878983
  • 0 -0.402667067831389 -6.32914150795323 9.13315298351198 8.3884053064068

推荐答案

我迅速尝试重现此方法,但失败了.我使用过Math.NET Numerics v2.6(NuGet软件包),但是此版本中的SVD分解没有变化.这是我的代码:

I quickly tried to reproduce this, but I failed. I've used Math.NET Numerics v2.6 (NuGet package), but there was no change around the SVD decomposition in this release. This is my code:

var m = DenseMatrix.OfArray(new double[,] {
   { 3, 0, 0, 0, 0 },
   { 0, 2, 4, 0, 0 },
   { 0, 4, 5, -4, 5 },
   { 0, 0, -4, -8, 12},
   { 0, 0, 5, 12, -5 }});

var svd = m.Svd(true);
//var svd = new UserSvd(m, true);

svd.U() * svd.W() * svd.VT()

最后一行的计算结果为:

Where the last line evaluates to:

DenseMatrix 5x5-Double
           3            0            0            0            0
           0            2            4 -1.23512E-15   -3.747E-16
           0            4            5           -4            5
           0  3.26128E-16           -4           -8           12
           0 -1.15186E-15            5           12           -5

在这种情况下,

VT为:

VT in this case is:

DenseMatrix 5x5-Double
           0   -0.0449147     0.249507     0.718099    -0.648123
           0     0.466822     0.823535    0.0324572     0.320646
           0     0.208479     0.176729    -0.670706    -0.689534
          -1            0            0            0            0
           0     0.858252    -0.477811     0.182848   -0.0408292

我想知道为什么会得到完全不同的结果? 您可以使用我上面发布的相同代码再试一次吗?

I wonder why you get a completely different result? Can you try again with the same code I posted above?

这篇关于用Mathnet数值库进行SVD​​重组似乎是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆