本文整理汇总了C#中UserDefinedMatrix类的典型用法代码示例。如果您正苦于以下问题:C# UserDefinedMatrix类的具体用法?C# UserDefinedMatrix怎么用?C# UserDefinedMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UserDefinedMatrix类属于命名空间,在下文中一共展示了UserDefinedMatrix类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CanFactorizeRandomMatrix
public void CanFactorizeRandomMatrix(int row, int column)
{
var matrixA = new UserDefinedMatrix(Matrix<double>.Build.Random(row, column, 1).ToArray());
var factorSvd = matrixA.Svd();
var u = factorSvd.U;
var vt = factorSvd.VT;
var w = factorSvd.W;
// Make sure the U has the right dimensions.
Assert.AreEqual(row, u.RowCount);
Assert.AreEqual(row, u.ColumnCount);
// Make sure the VT has the right dimensions.
Assert.AreEqual(column, vt.RowCount);
Assert.AreEqual(column, vt.ColumnCount);
// Make sure the W has the right dimensions.
Assert.AreEqual(row, w.RowCount);
Assert.AreEqual(column, w.ColumnCount);
// Make sure the U*W*VT is the original matrix.
var matrix = u*w*vt;
for (var i = 0; i < matrix.RowCount; i++)
{
for (var j = 0; j < matrix.ColumnCount; j++)
{
Assert.AreEqual(matrixA[i, j], matrix[i, j], 1.0e-11);
}
}
}
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:30,代码来源:UserSvdTests.cs
示例2: 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);
}
}
}
开发者ID:MaLiN2223,项目名称:mathnet-numerics,代码行数:25,代码来源:UserEvdTests.cs
示例3: 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);
}
}
}
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:29,代码来源:UserCholeskyTests.cs
示例4: CanCheckRankOfNonSquare
public void CanCheckRankOfNonSquare(int row, int column)
{
var matrixA = new UserDefinedMatrix(Matrix<float>.Build.Random(row, column, 1).ToArray());
var factorSvd = matrixA.Svd();
var mn = Math.Min(row, column);
Assert.AreEqual(factorSvd.Rank, mn);
}
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:8,代码来源:UserSvdTests.cs
示例5: 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 factorSvd = matrixA.Svd();
Assert.AreEqual(factorSvd.Determinant, 0);
Assert.AreEqual(factorSvd.Rank, order - 1);
}
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:18,代码来源:UserSvdTests.cs
示例6: CanCheckRankOfSquareSingular
public void CanCheckRankOfSquareSingular([Values(10, 50, 100)] 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, Complex32.Zero);
Assert.AreEqual(factorEvd.Rank, order - 1);
}
开发者ID:Amichai,项目名称:PhysicsPad,代码行数:18,代码来源:UserEvdTests.cs
示例7: CanWriteTabDelimitedData
public void CanWriteTabDelimitedData()
{
var matrix = new UserDefinedMatrix(new[,] { { 1.1, 2.2, 3.3 }, { 4.4, 5.5, 6.6 }, { 7.7, 8.8, 9.9 } });
var headers = new[] { "a", "b", "c" };
var writer = new DelimitedWriter('\t')
{
ColumnHeaders = headers
};
var stream = new MemoryStream();
writer.WriteMatrix(matrix, stream);
var data = stream.ToArray();
var reader = new StreamReader(new MemoryStream(data));
var text = reader.ReadToEnd();
var expected = "a\tb\tc"
+ Environment.NewLine
+ "1.1\t2.2\t3.3"
+ Environment.NewLine
+ "4.4\t5.5\t6.6"
+ Environment.NewLine
+ "7.7\t8.8\t9.9";
Assert.AreEqual(expected, text);
}
开发者ID:rafaortega,项目名称:mathnet-numerics,代码行数:22,代码来源:DelimitedWriterTests.cs
示例8: CanSolveForRandomVector
public void CanSolveForRandomVector(int row, int column)
{
var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.Random(row, column, 1).ToArray());
var matrixACopy = matrixA.Clone();
var factorSvd = matrixA.Svd();
var vectorb = new UserDefinedVector(Vector<Complex>.Build.Random(row, 1).ToArray());
var resultx = factorSvd.Solve(vectorb);
Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
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]);
}
}
}
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:28,代码来源:UserSvdTests.cs
示例9: LUFailsWithNonSquareMatrix
public void LUFailsWithNonSquareMatrix()
{
var matrix = new UserDefinedMatrix(3, 2);
Assert.Throws<ArgumentException>(() => matrix.LU());
}
开发者ID:Amichai,项目名称:PhysicsPad,代码行数:5,代码来源:UserLUTests.cs
示例10: CanSolveForRandomMatrixWhenResultMatrixGiven
public void CanSolveForRandomMatrixWhenResultMatrixGiven(int order)
{
var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.Random(order, order, 1).ToArray());
var matrixACopy = matrixA.Clone();
var factorGramSchmidt = matrixA.GramSchmidt();
var matrixB = new UserDefinedMatrix(Matrix<Complex>.Build.Random(order, order, 1).ToArray());
var matrixBCopy = matrixB.Clone();
var matrixX = new UserDefinedMatrix(order, order);
factorGramSchmidt.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]);
}
}
}
开发者ID:kityandhero,项目名称:mathnet-numerics,代码行数:47,代码来源:UserGramSchmidtTests.cs
示例11: 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]);
}
}
}
开发者ID:rmundy,项目名称:mathnet-numerics,代码行数:32,代码来源:UserCholeskyTests.cs
示例12: 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]);
}
}
}
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:42,代码来源:UserCholeskyTests.cs
示例13: CholeskyFailsWithNonSquareMatrix
public void CholeskyFailsWithNonSquareMatrix()
{
var matrixI = new UserDefinedMatrix(3, 2);
Assert.That(() => matrixI.Cholesky(), Throws.ArgumentException);
}
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:5,代码来源:UserCholeskyTests.cs
示例14: CanSolveForRandomVector
public void CanSolveForRandomVector(int order)
{
var matrixA = new UserDefinedMatrix(Matrix<Complex32>.Build.Random(order, order, 1).ToArray());
var matrixACopy = matrixA.Clone();
var factorGramSchmidt = matrixA.GramSchmidt();
var vectorb = new UserDefinedVector(Vector<Complex32>.Build.Random(order, 1).ToArray());
var resultx = factorGramSchmidt.Solve(vectorb);
Assert.AreEqual(matrixA.ColumnCount, resultx.Count);
var matrixBReconstruct = matrixA * resultx;
// Check the reconstruction.
for (var i = 0; i < order; i++)
{
Assert.AreEqual(vectorb[i].Real, matrixBReconstruct[i].Real, 1e-3f);
Assert.AreEqual(vectorb[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]);
}
}
}
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:29,代码来源:UserGramSchmidtTests.cs
示例15: CanSolveForRandomVectorWhenResultVectorGivenUsingThinQR
public void CanSolveForRandomVectorWhenResultVectorGivenUsingThinQR(int order)
{
var matrixA = new UserDefinedMatrix(Matrix<double>.Build.Random(order, order, 1).ToArray());
var matrixACopy = matrixA.Clone();
var factorQR = matrixA.QR(QRMethod.Thin);
var vectorb = new UserDefinedVector(Vector<double>.Build.Random(order, 1).ToArray());
var vectorbCopy = vectorb.Clone();
var resultx = new UserDefinedVector(order);
factorQR.Solve(vectorb, resultx);
Assert.AreEqual(vectorb.Count, 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-11);
}
// 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]);
}
}
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:35,代码来源:UserQRTests.cs
示例16: 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);
}
开发者ID:MaLiN2223,项目名称:mathnet-numerics,代码行数:22,代码来源:UserEvdTests.cs
示例17: 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);
}
开发者ID:MaLiN2223,项目名称:mathnet-numerics,代码行数:28,代码来源:UserEvdTests.cs
示例18: 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);
}
开发者ID:MaLiN2223,项目名称:mathnet-numerics,代码行数:7,代码来源:UserEvdTests.cs
示例19: 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);
}
}
}
开发者ID:MaLiN2223,项目名称:mathnet-numerics,代码行数:24,代码来源:UserEvdTests.cs
示例20: CanSolveForRandomVectorWhenResultVectorGiven
public void CanSolveForRandomVectorWhenResultVectorGiven(int order)
{
var matrixA = new UserDefinedMatrix(Matrix<Complex>.Build.Random(order, order, 1).ToArray());
var matrixACopy = matrixA.Clone();
var factorGramSchmidt = matrixA.GramSchmidt();
var vectorb = new UserDefinedVector(Vector<Complex>.Build.Random(order, 1).ToArray());
var vectorbCopy = vectorb.Clone();
var resultx = new UserDefinedVector(order);
factorGramSchmidt.Solve(vectorb, resultx);
Assert.AreEqual(vectorb.Count, resultx.Count);
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]);
}
}
开发者ID:kityandhero,项目名称:mathnet-numerics,代码行数:35,代码来源:UserGramSchmidtTests.cs
注:本文中的UserDefinedMatrix类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论