本文整理汇总了C#中UserDefinedVector.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# UserDefinedVector.Clone方法的具体用法?C# UserDefinedVector.Clone怎么用?C# UserDefinedVector.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserDefinedVector
的用法示例。
在下文中一共展示了UserDefinedVector.Clone方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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]);
}
}
示例2: 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]);
}
}
示例3: CanSolveForRandomVectorWhenResultVectorGiven
public void CanSolveForRandomVectorWhenResultVectorGiven(int row, int column)
{
var matrixA = new UserDefinedMatrix(Matrix<float>.Build.Random(row, column, 1).ToArray());
var matrixACopy = matrixA.Clone();
var factorSvd = matrixA.Svd();
var vectorb = new UserDefinedVector(Vector<float>.Build.Random(row, 1).ToArray());
var vectorbCopy = vectorb.Clone();
var resultx = new UserDefinedVector(column);
factorSvd.Solve(vectorb, resultx);
var matrixBReconstruct = matrixA*resultx;
// Check the reconstruction.
for (var i = 0; i < vectorb.Count; i++)
{
Assert.AreEqual(vectorb[i], matrixBReconstruct[i], 1e-4);
}
// 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]);
}
}
示例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: 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]);
}
}
示例6: 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);
}
示例7: CanSolveForRandomVectorAndSymmetricMatrixWhenResultVectorGiven
public void CanSolveForRandomVectorAndSymmetricMatrixWhenResultVectorGiven(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 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++)
{
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]);
}
}
// Make sure b didn't change.
for (var i = 0; i < vectorb.Count; i++)
{
Assert.AreEqual(vectorbCopy[i], vectorb[i]);
}
}