本文整理汇总了C#中UserDefinedMatrix.Cholesky方法的典型用法代码示例。如果您正苦于以下问题:C# UserDefinedMatrix.Cholesky方法的具体用法?C# UserDefinedMatrix.Cholesky怎么用?C# UserDefinedMatrix.Cholesky使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserDefinedMatrix
的用法示例。
在下文中一共展示了UserDefinedMatrix.Cholesky方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanFactorizeRandomMatrix
public void CanFactorizeRandomMatrix(int order)
{
var matrixX = new UserDefinedMatrix(Matrix<float>.Build.RandomPositiveDefinite(order, 1).ToArray());
var chol = matrixX.Cholesky();
var factorC = chol.Factor;
// Make sure the Cholesky factor has the right dimensions.
Assert.AreEqual(order, factorC.RowCount);
Assert.AreEqual(order, factorC.ColumnCount);
// Make sure the Cholesky factor is lower triangular.
for (var i = 0; i < factorC.RowCount; i++)
{
for (var j = i + 1; j < factorC.ColumnCount; j++)
{
Assert.AreEqual(0.0, factorC[i, j]);
}
}
// Make sure the cholesky factor times it's transpose is the original matrix.
var matrixXfromC = factorC * factorC.Transpose();
for (var i = 0; i < matrixXfromC.RowCount; i++)
{
for (var j = 0; j < matrixXfromC.ColumnCount; j++)
{
Assert.AreEqual(matrixX[i, j], matrixXfromC[i, j], 1e-3);
}
}
}
示例2: CholeskyFailsWithNonSquareMatrix
public void CholeskyFailsWithNonSquareMatrix()
{
var matrixI = new UserDefinedMatrix(3, 2);
Assert.That(() => matrixI.Cholesky(), Throws.ArgumentException);
}
示例3: CanSolveForRandomVectorWhenResultVectorGiven
public void CanSolveForRandomVectorWhenResultVectorGiven(int order)
{
var matrixA = new UserDefinedMatrix(Matrix<float>.Build.RandomPositiveDefinite(order, 1).ToArray());
var matrixACopy = matrixA.Clone();
var chol = matrixA.Cholesky();
var b = new UserDefinedVector(Vector<float>.Build.Random(order, 1).ToArray());
var matrixBCopy = b.Clone();
var x = new UserDefinedVector(order);
chol.Solve(b, x);
Assert.AreEqual(b.Count, x.Count);
var matrixBReconstruct = matrixA * x;
// Check the reconstruction.
for (var i = 0; i < order; i++)
{
Assert.AreEqual(b[i], matrixBReconstruct[i], 0.5);
}
// 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 < order; i++)
{
Assert.AreEqual(matrixBCopy[i], b[i]);
}
}
示例4: CanSolveForRandomMatrixWhenResultMatrixGiven
public void CanSolveForRandomMatrixWhenResultMatrixGiven(int row, int col)
{
var matrixA = new UserDefinedMatrix(Matrix<float>.Build.RandomPositiveDefinite(row, 1).ToArray());
var matrixACopy = matrixA.Clone();
var chol = matrixA.Cholesky();
var matrixB = new UserDefinedMatrix(Matrix<float>.Build.Random(row, col, 1).ToArray());
var matrixBCopy = matrixB.Clone();
var matrixX = new UserDefinedMatrix(row, col);
chol.Solve(matrixB, matrixX);
Assert.AreEqual(matrixB.RowCount, matrixX.RowCount);
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++)
{
Assert.AreEqual(matrixB[i, j], matrixBReconstruct[i, j], 1.0);
}
}
// 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]);
}
}
}
示例5: CanSolveForRandomVector
public void CanSolveForRandomVector(int order)
{
var matrixA = new UserDefinedMatrix(Matrix<Complex32>.Build.RandomPositiveDefinite(order, 1).ToArray());
var matrixACopy = matrixA.Clone();
var chol = matrixA.Cholesky();
var b = new UserDefinedVector(Vector<Complex32>.Build.Random(order, 1).ToArray());
var x = chol.Solve(b);
Assert.AreEqual(b.Count, x.Count);
var matrixBReconstruct = matrixA * x;
// Check the reconstruction.
for (var i = 0; i < order; i++)
{
Assert.AreEqual(b[i].Real, matrixBReconstruct[i].Real, 1e-3f);
Assert.AreEqual(b[i].Imaginary, matrixBReconstruct[i].Imaginary, 1e-3f);
}
// 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]);
}
}
}
示例6: CanSolveForRandomMatrix
public void CanSolveForRandomMatrix(int row, int col)
{
var matrixA = new UserDefinedMatrix(Matrix<Complex32>.Build.RandomPositiveDefinite(row, 1).ToArray());
var matrixACopy = matrixA.Clone();
var chol = matrixA.Cholesky();
var matrixB = new UserDefinedMatrix(Matrix<Complex32>.Build.Random(row, col, 1).ToArray());
var matrixX = chol.Solve(matrixB);
Assert.AreEqual(matrixB.RowCount, matrixX.RowCount);
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++)
{
Assert.AreEqual(matrixB[i, j].Real, matrixBReconstruct[i, j].Real, 0.01f);
Assert.AreEqual(matrixB[i, j].Imaginary, matrixBReconstruct[i, j].Imaginary, 0.01f);
}
}
// 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]);
}
}
}
示例7: CholeskyFailsWithNonSquareMatrix
public void CholeskyFailsWithNonSquareMatrix(int row, int col)
{
var I = new UserDefinedMatrix(row, col);
I.Cholesky();
}