本文整理汇总了C#中Encog.MathUtil.Matrices.Matrix类的典型用法代码示例。如果您正苦于以下问题:C# Matrix类的具体用法?C# Matrix怎么用?C# Matrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Matrix类属于Encog.MathUtil.Matrices命名空间,在下文中一共展示了Matrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RowsAndCols
public void RowsAndCols()
{
var matrix = new Matrix(6, 3);
Assert.AreEqual(matrix.Rows, 6);
Assert.AreEqual(matrix.Cols, 3);
matrix[1, 2] = 1.5;
Assert.AreEqual(matrix[1, 2], 1.5);
}
示例2: DotProduct
public void DotProduct()
{
double[][] matrixData1 = {new[] {1.0, 2.0, 3.0, 4.0}};
double[][] matrixData2 = {
new[] {5.0},
new[] {6.0},
new[] {7.0},
new[] {8.0}
};
var matrix1 = new Matrix(matrixData1);
var matrix2 = new Matrix(matrixData2);
double dotProduct = MatrixMath.DotProduct(matrix1, matrix2);
Assert.AreEqual(dotProduct, 70.0);
// test dot product errors
double[][] nonVectorData = {
new[] {1.0, 2.0},
new[] {3.0, 4.0}
};
double[][] differentLengthData = {
new[] {1.0}
};
var nonVector = new Matrix(nonVectorData);
var differentLength = new Matrix(differentLengthData);
try
{
MatrixMath.DotProduct(matrix1, nonVector);
Assert.IsTrue(false);
}
catch (MatrixError)
{
}
try
{
MatrixMath.DotProduct(nonVector, matrix2);
Assert.IsTrue(false);
}
catch (MatrixError)
{
}
try
{
MatrixMath.DotProduct(matrix1, differentLength);
Assert.IsTrue(false);
}
catch (MatrixError)
{
}
}
示例3: Copy
public void Copy()
{
double[][] data = {
new[] {1.0, 2.0},
new[] {3.0, 4.0}
};
var source = new Matrix(data);
var target = new Matrix(2, 2);
MatrixMath.Copy(source, target);
Assert.IsTrue(source.Equals(target));
}
示例4: RowAndColRangeUnder
public void RowAndColRangeUnder()
{
var matrix = new Matrix(6, 3);
// make sure set registers error on under-bound row
try
{
matrix[-1, 0] = 1;
Assert.IsTrue(false); // should have thrown an exception
}
catch (MatrixError)
{
}
// make sure set registers error on under-bound col
try
{
matrix[0, -1] = 1;
Assert.IsTrue(false); // should have thrown an exception
}
catch (MatrixError)
{
}
// make sure get registers error on under-bound row
try
{
double d = matrix[-1, 0];
matrix[0, 0] = d;
Assert.IsTrue(false); // should have thrown an exception
}
catch (MatrixError)
{
}
// make sure set registers error on under-bound col
try
{
double d = matrix[0, -1];
matrix[0, 0] = d;
Assert.IsTrue(false); // should have thrown an exception
}
catch (MatrixError)
{
}
}
示例5: Boolean
public void Boolean()
{
bool[][] matrixDataBoolean = {
new[] {true, false},
new[] {false, true}
};
double[][] matrixDataDouble = {
new[] {1.0, -1.0},
new[] {-1.0, 1.0},
};
var matrixBoolean = new Matrix(matrixDataBoolean);
var matrixDouble = new Matrix(matrixDataDouble);
Assert.IsTrue(matrixBoolean.Equals(matrixDouble));
}
示例6: Inverse
public void Inverse()
{
double[][] matrixData1 = {
new[] {1.0, 2.0, 3.0, 4.0}
};
double[][] matrixData2 = {
new[] {1.0},
new[] {2.0},
new[] {3.0},
new[] {4.0}
};
var matrix1 = new Matrix(matrixData1);
var checkMatrix = new Matrix(matrixData2);
Matrix matrix2 = MatrixMath.Transpose(matrix1);
Assert.IsTrue(matrix2.Equals(checkMatrix));
}
示例7: Bipolar2Double
public void Bipolar2Double()
{
// test a 1x4
bool[] boolData1 = { true, false, true, false };
double[] checkData1 = { 1, -1, 1, -1 };
Matrix matrix1 = Matrix.CreateRowMatrix(BiPolarUtil.Bipolar2double(boolData1));
Matrix checkMatrix1 = Matrix.CreateRowMatrix(checkData1);
Assert.IsTrue(matrix1.Equals(checkMatrix1));
// test a 2x2
bool[][] boolData2 = {
new[]{ true, false },
new[]{ false, true } };
double[][] checkData2 = {
new[] { 1.0, -1.0 },
new[] { -1.0, 1.0 } };
var matrix2 = new Matrix(BiPolarUtil.Bipolar2double(boolData2));
var checkMatrix2 = new Matrix(checkData2);
Assert.IsTrue(matrix2.Equals(checkMatrix2));
}
示例8: DeleteRow
public void DeleteRow()
{
double[][] origData = {
new[] {1.0, 2.0},
new[] {3.0, 4.0}
};
double[][] checkData = {new[] {3.0, 4.0}};
var orig = new Matrix(origData);
Matrix matrix = MatrixMath.DeleteRow(orig, 0);
var check = new Matrix(checkData);
Assert.IsTrue(check.Equals(matrix));
try
{
MatrixMath.DeleteRow(orig, 10);
Assert.IsTrue(false);
}
catch (MatrixError)
{
}
}
示例9: VerifySame
public void VerifySame()
{
double[][] dataBase = {
new[] {1.0, 2.0},
new[] {3.0, 4.0}
};
double[][] dataTooManyRows = {
new[] {1.0, 2.0},
new[] {3.0, 4.0},
new[] {5.0, 6.0}
};
double[][] dataTooManyCols = {
new[] {1.0, 2.0, 3.0},
new[] {4.0, 5.0, 6.0}
};
var baseMatrix = new Matrix(dataBase);
var tooManyRows = new Matrix(dataTooManyRows);
var tooManyCols = new Matrix(dataTooManyCols);
MatrixMath.Add(baseMatrix, baseMatrix);
try
{
MatrixMath.Add(baseMatrix, tooManyRows);
Assert.IsFalse(true);
}
catch (MatrixError)
{
}
try
{
MatrixMath.Add(baseMatrix, tooManyCols);
Assert.IsFalse(true);
}
catch (MatrixError)
{
}
}
示例10: MultiplyScalar
public void MultiplyScalar()
{
double[][] data = {
new[] {2.0, 4.0},
new[] {6.0, 8.0}
};
var matrix = new Matrix(data);
Matrix result = MatrixMath.Multiply(matrix, 2.0);
Assert.AreEqual(4.0, result[0, 0]);
}
示例11: Multiply
public void Multiply()
{
double[][] matrixData1 = {
new[] {1.0, 4.0},
new[] {2.0, 5.0},
new[] {3.0, 6.0}
};
double[][] matrixData2 = {
new[] {7.0, 8.0, 9.0},
new[] {10.0, 11.0, 12.0}
};
double[][] matrixData3 = {
new[] {47.0, 52.0, 57.0},
new[] {64.0, 71.0, 78.0},
new[] {81.0, 90.0, 99.0}
};
var matrix1 = new Matrix(matrixData1);
var matrix2 = new Matrix(matrixData2);
var matrix3 = new Matrix(matrixData3);
Matrix result = MatrixMath.Multiply(matrix1, matrix2);
Assert.IsTrue(result.Equals(matrix3));
}
示例12: Identity
public void Identity()
{
try
{
MatrixMath.Identity(0);
Assert.IsTrue(false);
}
catch (MatrixError)
{
}
double[][] checkData = {
new[] {1.0, 0.0},
new[] {0.0, 1.0}
};
var check = new Matrix(checkData);
Matrix matrix = MatrixMath.Identity(2);
Assert.IsTrue(check.Equals(matrix));
}
示例13: GetCol
public void GetCol()
{
double[][] matrixData1 = {
new[] {1.0, 2.0},
new[] {3.0, 4.0}
};
double[][] matrixData2 = {
new[] {2.0},
new[] {4.0}
};
var matrix1 = new Matrix(matrixData1);
var matrix2 = new Matrix(matrixData2);
Matrix matrixCol = matrix1.GetCol(1);
Assert.IsTrue(matrixCol.Equals(matrix2));
try
{
matrix1.GetCol(3);
Assert.IsTrue(false);
}
catch (MatrixError)
{
Assert.IsTrue(true);
}
}
示例14: MatrixMultiply
public void MatrixMultiply()
{
double[][] a = {
new[] {1.0, 0.0, 2.0},
new[] {-1.0, 3.0, 1.0}
};
double[][] b = {
new[] {3.0, 1.0},
new[] {2.0, 1.0},
new[] {1.0, 0.0}
};
double[][] c = {
new[] {5.0, 1.0},
new[] {4.0, 2.0}
};
var matrixA = new Matrix(a);
var matrixB = new Matrix(b);
var matrixC = new Matrix(c);
var result = (Matrix) matrixA.Clone();
result.ToString();
result = MatrixMath.Multiply(matrixA, matrixB);
Assert.IsTrue(result.Equals(matrixC));
double[][] a2 = {
new[] {1.0, 2.0, 3.0, 4.0},
new[] {5.0, 6.0, 7.0, 8.0}
};
double[][] b2 = {
new[] {1.0, 2.0, 3.0},
new[] {4.0, 5.0, 6.0},
new[] {7.0, 8.0, 9.0},
new[] {10.0, 11.0, 12.0}
};
double[][] c2 = {
new[] {70.0, 80.0, 90.0},
new[] {158.0, 184.0, 210.0}
};
matrixA = new Matrix(a2);
matrixB = new Matrix(b2);
matrixC = new Matrix(c2);
result = MatrixMath.Multiply(matrixA, matrixB);
Assert.IsTrue(result.Equals(matrixC));
matrixB.Clone();
try
{
MatrixMath.Multiply(matrixB, matrixA);
Assert.IsTrue(false);
}
catch (MatrixError)
{
}
}
示例15: Divide
public void Divide()
{
double[][] data = {
new[] {2.0, 4.0},
new[] {6.0, 8.0}
};
var matrix = new Matrix(data);
Matrix result = MatrixMath.Divide(matrix, 2.0);
Assert.AreEqual(1.0, result[0, 0]);
}