本文整理汇总了C#中Accord.Math.Decompositions.SingularValueDecomposition.Inverse方法的典型用法代码示例。如果您正苦于以下问题:C# SingularValueDecomposition.Inverse方法的具体用法?C# SingularValueDecomposition.Inverse怎么用?C# SingularValueDecomposition.Inverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Accord.Math.Decompositions.SingularValueDecomposition
的用法示例。
在下文中一共展示了SingularValueDecomposition.Inverse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InverseTest
public void InverseTest()
{
double[,] value = new double[,]
{
{ 1.0, 1.0 },
{ 2.0, 2.0 }
};
SingularValueDecomposition target = new SingularValueDecomposition(value);
double[,] expected = new double[,]
{
{ 0.1, 0.2 },
{ 0.1, 0.2 }
};
double[,] actual = target.Solve(Matrix.Identity(2));
Assert.IsTrue(Matrix.IsEqual(expected, actual, 0.001));
actual = target.Inverse();
Assert.IsTrue(Matrix.IsEqual(expected, actual, 0.001));
}
示例2: InverseTest2
public void InverseTest2()
{
int n = 5;
var I = Matrix.Identity(n);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
double[,] value = Matrix.Magic(n);
var target = new SingularValueDecomposition(value);
double[,] solution = target.Solve(I);
double[,] inverse = target.Inverse();
double[,] reverse = target.Reverse();
Assert.IsTrue(Matrix.IsEqual(solution, inverse, 1e-4));
Assert.IsTrue(Matrix.IsEqual(value, reverse, 1e-4));
}
}
}
示例3: MahalanobisTest3
public void MahalanobisTest3()
{
// Example from Statistical Distance Calculator
// http://maplepark.com/~drf5n/cgi-bin/dist.cgi
double[,] cov =
{
{ 1.030303, 2.132728, 0.576716 },
{ 2.132728, 4.510515, 1.185771 },
{ 0.576716, 1.185771, 0.398922 }
};
double[] x, y;
double actual, expected;
var svd = new SingularValueDecomposition(cov, true, true, true);
var inv = cov.Inverse();
var pinv = svd.Inverse();
Assert.IsTrue(inv.IsEqual(pinv, 1e-6));
x = new double[] { 2, 4, 1 };
y = new double[] { 0, 0, 0 };
{
var bla = cov.Solve(x);
var blo = svd.Solve(x);
var ble = inv.Multiply(x);
var bli = pinv.Multiply(x);
Assert.IsTrue(bla.IsEqual(blo, 1e-6));
Assert.IsTrue(bla.IsEqual(ble, 1e-6));
Assert.IsTrue(bla.IsEqual(bli, 1e-6));
}
expected = 2.0773536867741504;
actual = Distance.Mahalanobis(x, y, inv);
Assert.AreEqual(expected, actual, 1e-6);
actual = Distance.Mahalanobis(x, y, svd);
Assert.AreEqual(expected, actual, 1e-6);
x = new double[] { 7, 5, 1 };
y = new double[] { 1, 0.52, -79 };
expected = 277.8828871106366;
actual = Distance.Mahalanobis(x, y, inv);
Assert.AreEqual(expected, actual, 1e-5);
actual = Distance.Mahalanobis(x, y, svd);
Assert.AreEqual(expected, actual, 1e-5);
}