/// <summary> /// Tests that the /// <see cref="Advanced.Cloud.Standardize"/> /// method has /// been properly implemented. public static void Succeed( TestableCloud testableCloud) { var cloud = testableCloud.Cloud; var actual = cloud.Standardize(); DoubleMatrixAssert.AreEqual( expected: testableCloud .Standardized, actual: actual .Coordinates, delta: CloudTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableCloud .Weights, actual: actual .Weights, delta: CloudTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableCloud .Basis.basisMatrixT, actual: actual .Basis.basisMatrixT, delta: CloudTest.Accuracy); }
/// <summary> /// Tests that the /// <see cref="Advanced.Cloud.Rebase(Advanced.Basis)"/> /// method has /// been properly implemented. public static void Succeed( TestableCloud testableCloud) { var cloud = testableCloud.Cloud; var rebased = testableCloud.Rebased; var newBasis = rebased.Keys.First(); var newCoordinates = rebased.Values.First(); var actual = cloud.Rebase(newBasis); DoubleMatrixAssert.AreEqual( expected: newCoordinates, actual: actual .Coordinates, delta: CloudTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableCloud .Weights, actual: actual .Weights, delta: CloudTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: newBasis .basisMatrixT, actual: actual .Basis.basisMatrixT, delta: CloudTest.Accuracy); }
/// <summary> /// Verifies that specified categorical data sets are equal. /// </summary> /// <param name="expected">The expected categorical data set.</param> /// <param name="actual">The actual categorical data set.</param> public static void AreEqual( CategoricalDataSet expected, CategoricalDataSet actual) { if (null == expected && null == actual) { return; } if (((null == expected) && (null != actual)) || ((null != expected) && (null == actual))) { throw new AssertFailedException( "One categorical data set is null, the other is not."); } if (expected.Name != actual.Name) { throw new AssertFailedException( "Categorical data sets have different names."); } if (expected.Variables.Count != actual.Variables.Count) { throw new AssertFailedException( "Categorical data sets have different numbers of variables."); } for (int i = 0; i < expected.Variables.Count; i++) { CategoricalVariableAssert.AreEqual( expected.Variables[i], actual.Variables[i]); } var expectedVariables = (List <CategoricalVariable>) Reflector.GetField(expected, "variables"); var actualVariables = (List <CategoricalVariable>) Reflector.GetField(actual, "variables"); if (expectedVariables.Count != actualVariables.Count) { throw new AssertFailedException( "Categorical data sets have different numbers of variables."); } for (int i = 0; i < expectedVariables.Count; i++) { CategoricalVariableAssert.AreEqual( expectedVariables[i], actualVariables[i]); } DoubleMatrixAssert.AreEqual( (DoubleMatrix)Reflector.GetField(expected, "data"), (DoubleMatrix)Reflector.GetField(actual, "data"), 1e-4); DoubleMatrixAssert.AreEqual(expected.Data, actual.Data, 1e-4); }
/// <summary> /// Tests that the /// <see cref="PrincipalProjections.ActiveCloud"/> /// property has /// been properly implemented. public static void Succeed( TestablePrincipalProjections testablePrincipalProjections) { var principalProjections = testablePrincipalProjections.PrincipalProjections; DoubleMatrixAssert.AreEqual( expected: testablePrincipalProjections .ActiveCloud.Basis.GetBasisMatrix(), actual: principalProjections .ActiveCloud.Basis.GetBasisMatrix(), delta: PrincipalProjectionsTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testablePrincipalProjections .ActiveCloud.Coordinates, actual: principalProjections .ActiveCloud.Coordinates, delta: PrincipalProjectionsTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testablePrincipalProjections .ActiveCloud.Weights, actual: principalProjections .ActiveCloud.Weights, delta: PrincipalProjectionsTest.Accuracy); }
static void CheckPartialGraph( Func <ReadOnlyDoubleMatrix, DoubleMatrix> matrixFunc, Dictionary <TestableDoubleMatrix, DoubleMatrix> partialGraph) { foreach (var pair in partialGraph) { var arguments = pair.Key; var values = pair.Value; Assert.IsNotNull(arguments); Assert.IsNotNull(values); Assert.AreEqual( arguments.Expected.NumberOfRows, values.NumberOfRows); Assert.AreEqual( arguments.Expected.NumberOfColumns, values.NumberOfColumns); DoubleMatrixAssert.AreEqual( expected: values, actual: matrixFunc(arguments.AsDense.AsReadOnly()), delta: ProbabilityDistributionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: values, actual: matrixFunc(arguments.AsSparse.AsReadOnly()), delta: DoubleMatrixTest.Accuracy); } }
/// Tests that method /// <see cref="SingularValueDecomposition /// .GetSingularValues(ComplexMatrix)"/>, /// method has /// been properly implemented. public static void Succeed( TestableSingularValueDecomposition <TestableComplexMatrix, ComplexMatrix> testableSvd) { var testableMatrix = testableSvd.TestableMatrix; #region Writable // Dense { var actualValues = SingularValueDecomposition.GetSingularValues( testableMatrix.AsDense); DoubleMatrixAssert.AreEqual( expected: GetMainDiagonal(testableSvd.Values), actual: actualValues, delta: SingularValueDecompositionTest.Accuracy); } // Sparse { var actualValues = SingularValueDecomposition.GetSingularValues( testableMatrix.AsSparse); DoubleMatrixAssert.AreEqual( expected: GetMainDiagonal(testableSvd.Values), actual: actualValues, delta: SingularValueDecompositionTest.Accuracy); } #endregion #region ReadOnly // Dense { var actualValues = SingularValueDecomposition.GetSingularValues( testableMatrix.AsDense.AsReadOnly()); DoubleMatrixAssert.AreEqual( expected: GetMainDiagonal(testableSvd.Values), actual: actualValues, delta: SingularValueDecompositionTest.Accuracy); } // Sparse { var actualValues = SingularValueDecomposition.GetSingularValues( testableMatrix.AsSparse.AsReadOnly()); DoubleMatrixAssert.AreEqual( expected: GetMainDiagonal(testableSvd.Values), actual: actualValues, delta: SingularValueDecompositionTest.Accuracy); } #endregion }
/// <summary> /// Tests that the /// <see cref="Advanced.Cloud.Coordinates"/> /// property has /// been properly implemented. public static void Succeed( TestableCloud testableCloud) { var cloud = testableCloud.Cloud; DoubleMatrixAssert.AreEqual( expected: testableCloud .Coordinates, actual: cloud .Coordinates, delta: CloudTest.Accuracy); }
/// <summary> /// Tests that the /// <see cref="PrincipalProjections.RepresentationQualities"/> /// property has /// been properly implemented. public static void Succeed( TestablePrincipalProjections testablePrincipalProjections) { var principalProjections = testablePrincipalProjections.PrincipalProjections; DoubleMatrixAssert.AreEqual( expected: testablePrincipalProjections .RepresentationQualities, actual: principalProjections .RepresentationQualities, delta: PrincipalProjectionsTest.Accuracy); }
/// <summary> /// Tests that the /// <see cref="PrincipalProjections.Variances"/> /// property has /// been properly implemented. public static void Succeed( TestablePrincipalProjections testablePrincipalProjections) { var principalProjections = testablePrincipalProjections.PrincipalProjections; DoubleMatrixAssert.AreEqual( expected: testablePrincipalProjections .Variances, actual: principalProjections .Variances, delta: PrincipalProjectionsTest.Accuracy); Assert.AreEqual( expected: testablePrincipalProjections.Variances.Count, actual: principalProjections.NumberOfDirections); }
/// <summary> /// Tests that the /// <see cref="PrincipalProjections.Contributions"/> /// property has /// been properly implemented. public static void Succeed( TestablePrincipalProjections testablePrincipalProjections) { var principalProjections = testablePrincipalProjections.PrincipalProjections; DoubleMatrixAssert.AreEqual( expected: testablePrincipalProjections .Contributions, actual: principalProjections .Contributions, delta: PrincipalProjectionsTest.Accuracy); Assert.AreEqual( expected: Stat.Sum(testablePrincipalProjections.Contributions), actual: (double)principalProjections.NumberOfDirections, delta: PrincipalProjectionsTest.Accuracy); }
static void Succeed <TData>( Func <TData, SortDirection, SortIndexResults>[] operators, TData data, SortDirection sortDirection, SortIndexResults expected) where TData : class { for (int i = 0; i < operators.Length; i++) { var actual = operators[i](data, sortDirection); DoubleMatrixAssert.AreEqual( expected: expected.SortedData, actual: actual.SortedData, delta: DoubleMatrixTest.Accuracy); IndexCollectionAssert.AreEqual( expected: expected.SortedIndexes, actual: actual.SortedIndexes); } }
/// <summary> /// Tests that the /// <see cref="PrincipalProjections.RegressSupplementaryVariables"/> /// method succeeds when expected. public static void Succeed( TestablePrincipalProjections testablePrincipalProjections) { var principalProjections = testablePrincipalProjections.PrincipalProjections; DoubleMatrixAssert.AreEqual( expected: testablePrincipalProjections .RegressionCoefficients, actual: principalProjections.RegressSupplementaryVariables( (DoubleMatrix)principalProjections.ActiveCloud.Coordinates), delta: PrincipalProjectionsTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testablePrincipalProjections .RegressionCoefficients, actual: principalProjections.RegressSupplementaryVariables( principalProjections.ActiveCloud.Coordinates), delta: PrincipalProjectionsTest.Accuracy); }
/// <summary> /// Tests that the /// <see cref="PrincipalProjections.LocateSupplementaryPoints"/> /// method succeeds when expected. public static void Succeed( TestablePrincipalProjections testablePrincipalProjections) { var principalProjections = testablePrincipalProjections.PrincipalProjections; DoubleMatrixAssert.AreEqual( expected: testablePrincipalProjections .Coordinates, actual: principalProjections.LocateSupplementaryPoints( (DoubleMatrix)principalProjections.ActiveCloud.Coordinates), delta: PrincipalProjectionsTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testablePrincipalProjections .Coordinates, actual: principalProjections.LocateSupplementaryPoints( principalProjections.ActiveCloud.Coordinates), delta: PrincipalProjectionsTest.Accuracy); }
/// Tests that method /// <see cref="SingularValueDecomposition /// .Decompose(DoubleMatrix, out DoubleMatrix, out DoubleMatrix)"/>, /// has been properly implemented. public static void Succeed( TestableSingularValueDecomposition <TestableDoubleMatrix, DoubleMatrix> testableSvd) { var testableMatrix = testableSvd.TestableMatrix; #region Writable // Dense { var actualValues = SingularValueDecomposition.Decompose( testableMatrix.AsDense, out DoubleMatrix actualLeftVectors, out DoubleMatrix actualConjugateTransposedRightVectors); DoubleMatrixAssert.AreEqual( expected: testableSvd .Values, actual: actualValues, delta: SingularValueDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSvd .LeftVectors, actual: actualLeftVectors, delta: SingularValueDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSvd .ConjugateTransposedRightVectors, actual: actualConjugateTransposedRightVectors, delta: SingularValueDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSvd .TestableMatrix.AsDense, actual: actualLeftVectors * actualValues * actualConjugateTransposedRightVectors, delta: SingularValueDecompositionTest.Accuracy); } // Sparse { var actualValues = SingularValueDecomposition.Decompose( testableMatrix.AsSparse, out DoubleMatrix actualLeftVectors, out DoubleMatrix actualConjugateTransposedRightVectors); DoubleMatrixAssert.AreEqual( expected: testableSvd .Values, actual: actualValues, delta: SingularValueDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSvd .LeftVectors, actual: actualLeftVectors, delta: SingularValueDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSvd .ConjugateTransposedRightVectors, actual: actualConjugateTransposedRightVectors, delta: SingularValueDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSvd .TestableMatrix.AsDense, actual: actualLeftVectors * actualValues * actualConjugateTransposedRightVectors, delta: SingularValueDecompositionTest.Accuracy); } #endregion #region ReadOnly // Dense { var actualValues = SingularValueDecomposition.Decompose( testableMatrix.AsDense.AsReadOnly(), out DoubleMatrix actualLeftVectors, out DoubleMatrix actualConjugateTransposedRightVectors); DoubleMatrixAssert.AreEqual( expected: testableSvd .Values, actual: actualValues, delta: SingularValueDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSvd .LeftVectors, actual: actualLeftVectors, delta: SingularValueDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSvd .ConjugateTransposedRightVectors, actual: actualConjugateTransposedRightVectors, delta: SingularValueDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSvd .TestableMatrix.AsDense, actual: actualLeftVectors * actualValues * actualConjugateTransposedRightVectors, delta: SingularValueDecompositionTest.Accuracy); } // Sparse { var actualValues = SingularValueDecomposition.Decompose( testableMatrix.AsSparse.AsReadOnly(), out DoubleMatrix actualLeftVectors, out DoubleMatrix actualConjugateTransposedRightVectors); DoubleMatrixAssert.AreEqual( expected: testableSvd .Values, actual: actualValues, delta: SingularValueDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSvd .LeftVectors, actual: actualLeftVectors, delta: SingularValueDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSvd .ConjugateTransposedRightVectors, actual: actualConjugateTransposedRightVectors, delta: SingularValueDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSvd .TestableMatrix.AsDense, actual: actualLeftVectors * actualValues * actualConjugateTransposedRightVectors, delta: SingularValueDecompositionTest.Accuracy); } #endregion }
/// Tests that method /// <see cref="SpectralDecomposition /// .GetEigenvalues(ComplexMatrix)"/>, /// method has /// been properly implemented. public static void Succeed( TestableSpectralDecomposition <TestableComplexMatrix, ComplexMatrix> testableSD) { var testableMatrix = testableSD.TestableMatrix; #region Writable // Dense, Lower { var actualValues = SpectralDecomposition.GetEigenvalues( testableMatrix.AsDense, lowerTriangularPart: true); DoubleMatrixAssert.AreEqual( expected: GetMainDiagonal(testableSD.Values), actual: actualValues, delta: SpectralDecompositionTest.Accuracy); } // Sparse, Lower { var actualValues = SpectralDecomposition.GetEigenvalues( testableMatrix.AsSparse, lowerTriangularPart: true); DoubleMatrixAssert.AreEqual( expected: GetMainDiagonal(testableSD.Values), actual: actualValues, delta: SpectralDecompositionTest.Accuracy); } // Dense, Upper { var actualValues = SpectralDecomposition.GetEigenvalues( testableMatrix.AsDense, lowerTriangularPart: false); DoubleMatrixAssert.AreEqual( expected: GetMainDiagonal(testableSD.Values), actual: actualValues, delta: SpectralDecompositionTest.Accuracy); } // Sparse, Upper { var actualValues = SpectralDecomposition.GetEigenvalues( testableMatrix.AsSparse, lowerTriangularPart: false); DoubleMatrixAssert.AreEqual( expected: GetMainDiagonal(testableSD.Values), actual: actualValues, delta: SpectralDecompositionTest.Accuracy); } #endregion #region ReadOnly // Dense, Lower { var actualValues = SpectralDecomposition.GetEigenvalues( testableMatrix.AsDense.AsReadOnly(), lowerTriangularPart: true); DoubleMatrixAssert.AreEqual( expected: GetMainDiagonal(testableSD.Values), actual: actualValues, delta: SpectralDecompositionTest.Accuracy); } // Sparse, Lower { var actualValues = SpectralDecomposition.GetEigenvalues( testableMatrix.AsSparse.AsReadOnly(), lowerTriangularPart: true); DoubleMatrixAssert.AreEqual( expected: GetMainDiagonal(testableSD.Values), actual: actualValues, delta: SpectralDecompositionTest.Accuracy); } // Dense, Upper { var actualValues = SpectralDecomposition.GetEigenvalues( testableMatrix.AsDense.AsReadOnly(), lowerTriangularPart: false); DoubleMatrixAssert.AreEqual( expected: GetMainDiagonal(testableSD.Values), actual: actualValues, delta: SpectralDecompositionTest.Accuracy); } // Sparse, Upper { var actualValues = SpectralDecomposition.GetEigenvalues( testableMatrix.AsSparse.AsReadOnly(), lowerTriangularPart: false); DoubleMatrixAssert.AreEqual( expected: GetMainDiagonal(testableSD.Values), actual: actualValues, delta: SpectralDecompositionTest.Accuracy); } #endregion }
/// Tests that method /// <see cref="SpectralDecomposition /// .Decompose(DoubleMatrix, bool, out DoubleMatrix)"/>, /// has been properly implemented. public static void Succeed( TestableSpectralDecomposition <TestableDoubleMatrix, DoubleMatrix> testableSD) { var testableMatrix = testableSD.TestableMatrix; #region Writable // Dense, Lower { var actualValues = SpectralDecomposition.Decompose( testableMatrix.AsDense, lowerTriangularPart: true, out DoubleMatrix actualVectors); DoubleMatrixAssert.AreEqual( expected: testableSD .Values, actual: actualValues, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .VectorsIfLower, actual: actualVectors, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .TestableMatrix.AsDense, actual: actualVectors * actualValues * actualVectors.Transpose(), delta: SpectralDecompositionTest.Accuracy); } // Sparse, Lower { var actualValues = SpectralDecomposition.Decompose( testableMatrix.AsSparse, lowerTriangularPart: true, out DoubleMatrix actualVectors); DoubleMatrixAssert.AreEqual( expected: testableSD .Values, actual: actualValues, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .VectorsIfLower, actual: actualVectors, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .TestableMatrix.AsDense, actual: actualVectors * actualValues * actualVectors.Transpose(), delta: SpectralDecompositionTest.Accuracy); } // Dense, Upper { var actualValues = SpectralDecomposition.Decompose( testableMatrix.AsDense, lowerTriangularPart: false, out DoubleMatrix actualVectors); DoubleMatrixAssert.AreEqual( expected: testableSD .Values, actual: actualValues, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .VectorsIfUpper, actual: actualVectors, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .TestableMatrix.AsDense, actual: actualVectors * actualValues * actualVectors.Transpose(), delta: SpectralDecompositionTest.Accuracy); } // Sparse, Upper { var actualValues = SpectralDecomposition.Decompose( testableMatrix.AsSparse, lowerTriangularPart: false, out DoubleMatrix actualVectors); DoubleMatrixAssert.AreEqual( expected: testableSD .Values, actual: actualValues, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .VectorsIfUpper, actual: actualVectors, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .TestableMatrix.AsDense, actual: actualVectors * actualValues * actualVectors.Transpose(), delta: SpectralDecompositionTest.Accuracy); } #endregion #region ReadOnly // Dense, Lower { var actualValues = SpectralDecomposition.Decompose( testableMatrix.AsDense.AsReadOnly(), lowerTriangularPart: true, out DoubleMatrix actualVectors); DoubleMatrixAssert.AreEqual( expected: testableSD .Values, actual: actualValues, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .VectorsIfLower, actual: actualVectors, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .TestableMatrix.AsDense, actual: actualVectors * actualValues * actualVectors.Transpose(), delta: SpectralDecompositionTest.Accuracy); } // Sparse, Lower { var actualValues = SpectralDecomposition.Decompose( testableMatrix.AsSparse.AsReadOnly(), lowerTriangularPart: true, out DoubleMatrix actualVectors); DoubleMatrixAssert.AreEqual( expected: testableSD .Values, actual: actualValues, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .VectorsIfLower, actual: actualVectors, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .TestableMatrix.AsDense, actual: actualVectors * actualValues * actualVectors.Transpose(), delta: SpectralDecompositionTest.Accuracy); } // Dense, Upper { var actualValues = SpectralDecomposition.Decompose( testableMatrix.AsDense.AsReadOnly(), lowerTriangularPart: false, out DoubleMatrix actualVectors); DoubleMatrixAssert.AreEqual( expected: testableSD .Values, actual: actualValues, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .VectorsIfUpper, actual: actualVectors, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .TestableMatrix.AsDense, actual: actualVectors * actualValues * actualVectors.Transpose(), delta: SpectralDecompositionTest.Accuracy); } // Sparse, Upper { var actualValues = SpectralDecomposition.Decompose( testableMatrix.AsSparse.AsReadOnly(), lowerTriangularPart: false, out DoubleMatrix actualVectors); DoubleMatrixAssert.AreEqual( expected: testableSD .Values, actual: actualValues, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .VectorsIfUpper, actual: actualVectors, delta: SpectralDecompositionTest.Accuracy); DoubleMatrixAssert.AreEqual( expected: testableSD .TestableMatrix.AsDense, actual: actualVectors * actualValues * actualVectors.Transpose(), delta: SpectralDecompositionTest.Accuracy); } #endregion }