public void Create_RebonatoJaeckelExample2_BenchmarkResult()
        {
            int n = 3;
            var rawCorrelationMatrix = new DenseMatrix(n, n, new[] { 1.0, 0.9, 0.7, 0.9, 1.0, 0.3, 0.7, 0.3, 1.0 });

            OrdinaryMultiDimOptimizer multiDimOptimizer = new PowellOptimizer();
            var matrixDecomposer = new SapMatrixDecomposer(multiDimOptimizer);

            PseudoSqrtMatrixDecomposer.State state;
            var b = matrixDecomposer.Create(rawCorrelationMatrix, out state);

            int expectedRank = 2;

            Assert.That(state.Rank, Is.EqualTo(expectedRank), String.Format("Rank should be {0}, but was {1}.", expectedRank, state.Rank));

            var actual = b * b.T;

            var expected = new DenseMatrix(n, n, new[] {
                1.0, 0.89458, 0.69662,
                0.89458, 1.0, 0.30254,
                0.69662, 0.30254, 1.0
            });

            Assert.That(actual.Data, Is.EqualTo(expected.Data).AsCollection.Within(1E-4));
        }
        public void Create_RebonatoJaeckelExample1_BenchmarkResult()
        {
            int n = 3;
            var rawCorrelationMatrix = new DenseMatrix(n, n, new[] {
                1.0, 0.9, 0.7,
                0.9, 1.0, 0.4,
                0.7, 0.4, 1.0
            });

            OrdinaryMultiDimOptimizer multiDimOptimizer = new PowellOptimizer();

            var matrixDecomposer = new SapMatrixDecomposer(multiDimOptimizer);

            PseudoSqrtMatrixDecomposer.State state;
            var actual = matrixDecomposer.Create(rawCorrelationMatrix, out state);

            Assert.That(state.Rank, Is.EqualTo(n), String.Format("Rank should be {0}, but was {1}.", n, state.Rank));

            var expected = new DenseMatrix(n, n, new[] {  // the values taken from the reference are re-ordered and some columns are multiplied with -1.0
                0.13192, -0.10021, -0.05389,
                -0.08718, -0.45536, 0.63329,
                -0.98742, -0.88465, -0.77203
            });

            Assert.That(actual.Data, Is.EqualTo(expected.Data).AsCollection.Within(1E-4));
        }