本文整理汇总了C#中System.Matrix.Subtract方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Subtract方法的具体用法?C# Matrix.Subtract怎么用?C# Matrix.Subtract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Matrix
的用法示例。
在下文中一共展示了Matrix.Subtract方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExceptionIncompatibleMatrices2
public void ExceptionIncompatibleMatrices2()
{
IMathematicalMatrix matrix1 = new Matrix(2, 3);
matrix1[0, 0] = 1;
matrix1[0, 1] = 2;
matrix1[0, 2] = -4;
matrix1[1, 0] = 0;
matrix1[1, 1] = 3;
matrix1[1, 2] = -1;
IMathematicalMatrix matrix2 = MatrixTest.GetTestMatrix();
matrix1.Subtract(matrix2);
}
示例2: SubtractRaiseExceptionIfDifferentRowSize
public void SubtractRaiseExceptionIfDifferentRowSize()
{
Matrix matrix1 = new Matrix(new double[][] { new double[] { 1.0, 2.0 }, new double[] { 3.0, 4.0 } });
Matrix matrix2 = new Matrix(new double[][] { new double[] { 5.0, 6.0 }, new double[] { 7.0, 8.0 }, new double[] { 9.0, 10.0 } });
try
{
matrix1.Subtract(matrix2);
Assert.Fail();
}
catch (Exception ex)
{
Assert.IsInstanceOfType(ex, typeof(InvalidOperationException));
Assert.AreEqual("Matrices have different sizes", ex.Message);
}
}
示例3: Subtract
public void Subtract()
{
Matrix matrix1 = new Matrix(new double[][] { new double[] { 1.0, 2.0 }, new double[] { 3.0, 4.0 } });
Matrix matrix2 = new Matrix(new double[][] { new double[] { 5.0, 6.0 }, new double[] { 7.0, 8.0 } });
Matrix matrix = matrix1.Subtract(matrix2);
Assert.AreEqual(4, matrix.Size);
var elements = matrix.Elements;
Assert.AreEqual(1.0 - 5.0, elements[0][0]);
Assert.AreEqual(2.0 - 6.0, elements[0][1]);
Assert.AreEqual(3.0 - 7.0, elements[1][0]);
Assert.AreEqual(4.0 - 8.0, elements[1][1]);
}
示例4: KLTransform
public Matrix KLTransform(Matrix matrix)
{
matrix = (Matrix)matrix.Transpose();
int columnNumber = matrix.ColumnCount;
Matrix mean = GetMean(matrix);
//Don't print it becouse is a lot of values
// PrintMatrix(mean, null, " mean matrix"); -
float[,] oneD = new float[1, columnNumber];
for (int i = 0; i < columnNumber; i++)
{
oneD[0, i] = 1;
}
//so called edinichna matrica
Matrix onesMatrix = DenseMatrix.OfArray(oneD);
// center the data
Matrix xm = (DenseMatrix)matrix.Subtract(mean.Multiply(onesMatrix));
// PrintMatrix(null, xm.ToArray(), "center the data");
// Calculate covariance matrix
DenseMatrix cov = (DenseMatrix)(xm.Multiply(xm.Transpose())).Multiply(1.0f / columnNumber);
// PrintMatrix(cov, null, "Calculate covariance matrix");
PrintText(cov.ColumnCount.ToString() + " Calculate covariance ColumnCount");
PrintText(cov.RowCount.ToString() + " Calculate covariance RowCount");
//this is from another libraly accord .net
EigenvalueDecomposition v = new EigenvalueDecomposition(FromFloatMatrixToDouble(cov.ToArray()));
double[,] eigVectors = v.Eigenvectors;
double[,] eidDiagonal = v.DiagonalMatrix;
Matrix eigVectorsTransposedMatrix = (DenseMatrix)DenseMatrix.OfArray(FromDoubleMatrixToFlaot(eigVectors)).Transpose();
Matrix eidDiagonalMatrix = DenseMatrix.OfArray(FromDoubleMatrixToFlaot(eidDiagonal));
int rowsCountDiagonals = eidDiagonal.GetLength(0);
int maxLambdaIndex = 0;
for (int i = 0; i < rowsCountDiagonals - 1; i++)
{
if (eidDiagonal[i, i] <= eidDiagonal[i + 1, i + 1])
{
maxLambdaIndex = i + 1;
}
}
double maxAlpha = eidDiagonal[maxLambdaIndex, maxLambdaIndex];
double sumAlpha = 0;
for (int i = 0; i < rowsCountDiagonals; i++)
{
sumAlpha += eidDiagonal[i, i];
}
CalculateAndPrintError(maxAlpha, sumAlpha);
PrintText("Max lambda index " + maxLambdaIndex);
// PrintMatrix(eidDiagonalMatrix, null, "Eign vals");
// //PCA
float[,] arr = new float[1, eigVectorsTransposedMatrix.ColumnCount];
for (int i = 0; i < eigVectorsTransposedMatrix.ColumnCount; i++)
{
arr[0, i] = eigVectorsTransposedMatrix[maxLambdaIndex, i];
}
Matrix mainComponentMatrix = DenseMatrix.OfArray(arr);
// PrintMatrix(mainComponentMatrix, null, "Main Component");
Matrix pca = (DenseMatrix)mainComponentMatrix.Multiply(xm);
// PrintMatrix(pca, null, "PCA");
return pca;
}