Exemple #1
0
            /// <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);
            }
Exemple #2
0
            /// <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);
            }
Exemple #3
0
            /// <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);
            }
Exemple #4
0
        /// <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);
        }
Exemple #5
0
        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
            }
Exemple #7
0
            /// <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);
            }
Exemple #8
0
            /// <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);
            }
 static void Succeed <TOperand>(
     Func <TOperand, DoubleMatrix>[] operators,
     TOperand operand,
     DoubleMatrixState expected)
     where TOperand : class
 {
     for (int i = 0; i < operators.Length; i++)
     {
         var actual = operators[i](operand);
         DoubleMatrixAssert.IsStateAsExpected(
             expectedState: expected,
             actualMatrix: actual,
             delta: DoubleMatrixTest.Accuracy);
     }
 }
Exemple #10
0
 static void Succeed <TData>(
     Func <TData, DataOperation, DoubleMatrix>[] operators,
     TData data,
     DataOperation dataOperation,
     DoubleMatrixState expected)
     where TData : class
 {
     for (int i = 0; i < operators.Length; i++)
     {
         var actual = operators[i](data, dataOperation);
         DoubleMatrixAssert.IsStateAsExpected(
             expectedState: expected,
             actualMatrix: actual,
             delta: DoubleMatrixTest.Accuracy);
     }
 }
Exemple #11
0
            /// <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);
            }
Exemple #12
0
            /// <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);
            }
Exemple #13
0
 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);
     }
 }
Exemple #14
0
            /// <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);
            }
Exemple #15
0
            /// <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);
            }
        static void Succeed <TData>(
            Func <TData, DoubleMatrix, DataOperation, DoubleMatrix[]>[] operators,
            TData data,
            DoubleMatrix probabilities,
            DataOperation dataOperation,
            DoubleMatrixState[] expected)
            where TData : class
        {
            for (int i = 0; i < operators.Length; i++)
            {
                var actual = operators[i](data, probabilities, dataOperation);

                Assert.AreEqual(expected.Length, actual.Length);

                for (int j = 0; j < expected.Length; j++)
                {
                    DoubleMatrixAssert.IsStateAsExpected(
                        expectedState: expected[j],
                        actualMatrix: actual[j],
                        delta: DoubleMatrixTest.Accuracy);
                }
            }
        }
Exemple #17
0
            /// 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
            }
            /// 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
            }
Exemple #19
0
            /// 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
            }