本文整理汇总了C#中UserDefinedMatrix.Evd方法的典型用法代码示例。如果您正苦于以下问题:C# UserDefinedMatrix.Evd方法的具体用法?C# UserDefinedMatrix.Evd怎么用?C# UserDefinedMatrix.Evd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserDefinedMatrix
的用法示例。
在下文中一共展示了UserDefinedMatrix.Evd方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanFactorizeRandomMatrix
public void CanFactorizeRandomMatrix(int order)
{
var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.Random(order, order, 1).ToArray());
var factorEvd = matrixA.Evd();
var eigenVectors = factorEvd.EigenVectors;
var d = factorEvd.D;
Assert.AreEqual(order, eigenVectors.RowCount);
Assert.AreEqual(order, eigenVectors.ColumnCount);
Assert.AreEqual(order, d.RowCount);
Assert.AreEqual(order, d.ColumnCount);
// Make sure the A*V = λ*V
var matrixAv = matrixA * eigenVectors;
var matrixLv = eigenVectors * d;
for (var i = 0; i < matrixAv.RowCount; i++)
{
for (var j = 0; j < matrixAv.ColumnCount; j++)
{
AssertHelpers.AlmostEqualRelative(matrixAv[i, j], matrixLv[i, j], 7);
}
}
}
示例2: CanCheckRankOfSquareSingular
public void CanCheckRankOfSquareSingular(int order)
{
var matrixA = new UserDefinedMatrix(order, order);
matrixA[0, 0] = 1;
matrixA[order - 1, order - 1] = 1;
for (var i = 1; i < order - 1; i++)
{
matrixA[i, i - 1] = 1;
matrixA[i, i + 1] = 1;
matrixA[i - 1, i] = 1;
matrixA[i + 1, i] = 1;
}
var factorEvd = matrixA.Evd();
Assert.AreEqual(factorEvd.Determinant, 0);
Assert.AreEqual(factorEvd.Rank, order - 1);
}
示例3: CanSolveForRandomMatrixAndSymmetricMatrixWhenResultMatrixGiven
public void CanSolveForRandomMatrixAndSymmetricMatrixWhenResultMatrixGiven([Values(1, 2, 5, 10, 50, 100)] int order)
{
var A = new UserDefinedMatrix(Matrix<Complex>.Build.RandomPositiveDefinite(order, 1).ToArray());
MatrixHelpers.ForceHermitian(A);
var ACopy = A.Clone();
var evd = A.Evd(Symmetricity.Hermitian);
var B = new UserDefinedMatrix(Matrix<Complex>.Build.Random(order, order, 1).ToArray());
var BCopy = B.Clone();
var X = new UserDefinedMatrix(order, order);
evd.Solve(B, X);
// The solution X row dimension is equal to the column dimension of A
Assert.AreEqual(A.ColumnCount, X.RowCount);
// The solution X has the same number of columns as B
Assert.AreEqual(B.ColumnCount, X.ColumnCount);
var BReconstruct = A * X;
// Check the reconstruction.
AssertHelpers.AlmostEqual(B, BReconstruct, 9);
// Make sure A/B didn't change.
AssertHelpers.AlmostEqual(ACopy, A, 14);
AssertHelpers.AlmostEqual(BCopy, B, 14);
}
示例4: CanSolveForRandomVectorAndSymmetricMatrixWhenResultVectorGiven
public void CanSolveForRandomVectorAndSymmetricMatrixWhenResultVectorGiven([Values(1, 2, 5, 10, 50, 100)] int order)
{
var A = new UserDefinedMatrix(Matrix<Complex>.Build.RandomPositiveDefinite(order, 1).ToArray());
MatrixHelpers.ForceHermitian(A);
var ACopy = A.Clone();
var evd = A.Evd(Symmetricity.Hermitian);
var b = new UserDefinedVector(Vector<Complex>.Build.Random(order, 1).ToArray());
var bCopy = b.Clone();
var x = new UserDefinedVector(order);
evd.Solve(b, x);
var bReconstruct = A * x;
// Check the reconstruction.
AssertHelpers.AlmostEqual(b, bReconstruct, 9);
// Make sure A/B didn't change.
AssertHelpers.AlmostEqual(ACopy, A, 14);
AssertHelpers.AlmostEqual(bCopy, b, 14);
}
示例5: CanCheckRankSquare
public void CanCheckRankSquare(int order)
{
var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.Random(order, order, 1).ToArray());
var factorEvd = matrixA.Evd();
Assert.AreEqual(factorEvd.Rank, order);
}
示例6: CanFactorizeRandomSymmetricMatrix
public void CanFactorizeRandomSymmetricMatrix(int order)
{
var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.RandomPositiveDefinite(order, 1).ToArray());
var factorEvd = matrixA.Evd(Symmetricity.Hermitian);
var eigenVectors = factorEvd.EigenVectors;
var d = factorEvd.D;
Assert.AreEqual(order, eigenVectors.RowCount);
Assert.AreEqual(order, eigenVectors.ColumnCount);
Assert.AreEqual(order, d.RowCount);
Assert.AreEqual(order, d.ColumnCount);
// Make sure the A = V*λ*VT
var matrix = eigenVectors * d * eigenVectors.ConjugateTranspose();
for (var i = 0; i < matrix.RowCount; i++)
{
for (var j = 0; j < matrix.ColumnCount; j++)
{
AssertHelpers.AlmostEqualRelative(matrix[i, j], matrixA[i, j], 7);
}
}
}
示例7: CanSolveForRandomVectorAndSymmetricMatrix
public void CanSolveForRandomVectorAndSymmetricMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
{
var A = new UserDefinedMatrix(Matrix<float>.Build.RandomPositiveDefinite(order, 1).ToArray());
MatrixHelpers.ForceSymmetric(A);
var ACopy = A.Clone();
var evd = A.Evd();
var b = new UserDefinedVector(Vector<float>.Build.Random(order, 1).ToArray());
var bCopy = b.Clone();
var x = evd.Solve(b);
var bReconstruct = A * x;
// Check the reconstruction.
AssertHelpers.AlmostEqual(b, bReconstruct, -1);
// Make sure A/B didn't change.
AssertHelpers.AlmostEqual(ACopy, A, 14);
AssertHelpers.AlmostEqual(bCopy, b, 14);
}
示例8: CanFactorizeRandomSymmetricMatrix
public void CanFactorizeRandomSymmetricMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
{
var matrixA = new UserDefinedMatrix(Matrix<float>.Build.RandomPositiveDefinite(order, 1).ToArray());
var factorEvd = matrixA.Evd();
var eigenVectors = factorEvd.EigenVectors;
var d = factorEvd.D;
Assert.AreEqual(order, eigenVectors.RowCount);
Assert.AreEqual(order, eigenVectors.ColumnCount);
Assert.AreEqual(order, d.RowCount);
Assert.AreEqual(order, d.ColumnCount);
// Make sure the A = V*λ*VT
var matrix = eigenVectors * d * eigenVectors.Transpose();
for (var i = 0; i < matrix.RowCount; i++)
{
for (var j = 0; j < matrix.ColumnCount; j++)
{
Assert.AreEqual(matrix[i, j], matrixA[i, j], 1e-3);
}
}
}
示例9: CanSolveForRandomVectorAndSymmetricMatrixWhenResultVectorGiven
public void CanSolveForRandomVectorAndSymmetricMatrixWhenResultVectorGiven(int order)
{
var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.RandomPositiveDefinite(order, 1).ToArray());
var matrixACopy = matrixA.Clone();
var factorEvd = matrixA.Evd();
var vectorb = new UserDefinedVector(Vector<Complex>.Build.Random(order, 1).ToArray());
var vectorbCopy = vectorb.Clone();
var resultx = new UserDefinedVector(order);
factorEvd.Solve(vectorb, resultx);
var matrixBReconstruct = matrixA * resultx;
// Check the reconstruction.
for (var i = 0; i < vectorb.Count; i++)
{
AssertHelpers.AlmostEqual(vectorb[i], matrixBReconstruct[i], 10);
}
// Make sure A didn't change.
for (var i = 0; i < matrixA.RowCount; i++)
{
for (var j = 0; j < matrixA.ColumnCount; j++)
{
Assert.AreEqual(matrixACopy[i, j], matrixA[i, j]);
}
}
// Make sure b didn't change.
for (var i = 0; i < vectorb.Count; i++)
{
Assert.AreEqual(vectorbCopy[i], vectorb[i]);
}
}
示例10: CanSolveForRandomMatrixAndSymmetricMatrixWhenResultMatrixGiven
public void CanSolveForRandomMatrixAndSymmetricMatrixWhenResultMatrixGiven(int order)
{
var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.RandomPositiveDefinite(order, 1).ToArray());
var matrixACopy = matrixA.Clone();
var factorEvd = matrixA.Evd();
var matrixB = new UserDefinedMatrix(Matrix<Complex>.Build.Random(order, order, 1).ToArray());
var matrixBCopy = matrixB.Clone();
var matrixX = new UserDefinedMatrix(order, order);
factorEvd.Solve(matrixB, matrixX);
// The solution X row dimension is equal to the column dimension of A
Assert.AreEqual(matrixA.ColumnCount, matrixX.RowCount);
// The solution X has the same number of columns as B
Assert.AreEqual(matrixB.ColumnCount, matrixX.ColumnCount);
var matrixBReconstruct = matrixA * matrixX;
// Check the reconstruction.
for (var i = 0; i < matrixB.RowCount; i++)
{
for (var j = 0; j < matrixB.ColumnCount; j++)
{
AssertHelpers.AlmostEqual(matrixB[i, j], matrixBReconstruct[i, j], 10);
}
}
// Make sure A didn't change.
for (var i = 0; i < matrixA.RowCount; i++)
{
for (var j = 0; j < matrixA.ColumnCount; j++)
{
Assert.AreEqual(matrixACopy[i, j], matrixA[i, j]);
}
}
// Make sure B didn't change.
for (var i = 0; i < matrixB.RowCount; i++)
{
for (var j = 0; j < matrixB.ColumnCount; j++)
{
Assert.AreEqual(matrixBCopy[i, j], matrixB[i, j]);
}
}
}
示例11: CanSolveForRandomVectorAndSymmetricMatrix
public void CanSolveForRandomVectorAndSymmetricMatrix(int order)
{
var matrixA = new UserDefinedMatrix(Matrix<double>.Build.RandomPositiveDefinite(order, 1).ToArray());
var matrixACopy = matrixA.Clone();
var factorEvd = matrixA.Evd();
var vectorb = new UserDefinedVector(Vector<double>.Build.Random(order, 1).ToArray());
var resultx = factorEvd.Solve(vectorb);
Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
var matrixBReconstruct = matrixA * resultx;
// Check the reconstruction.
for (var i = 0; i < vectorb.Count; i++)
{
Assert.AreEqual(vectorb[i], matrixBReconstruct[i], 1.0e-10);
}
// Make sure A didn't change.
for (var i = 0; i < matrixA.RowCount; i++)
{
for (var j = 0; j < matrixA.ColumnCount; j++)
{
Assert.AreEqual(matrixACopy[i, j], matrixA[i, j]);
}
}
}