Пример #1
0
        public void DetermineStatusWithDivergence()
        {
            const double Increase   = 0.5;
            const int    Iterations = 10;

            var criterion = new DivergenceStopCriterion <double>(Increase, Iterations);

            // Add residuals. We should not diverge because we'll have one to few iterations
            double previous = 1;

            for (var i = 0; i < Iterations - 1; i++)
            {
                previous *= 1 + Increase + 0.01;
                var status = criterion.DetermineStatus(
                    i,
                    Vector <double> .Build.Dense(new[] { 1.0 }),
                    Vector <double> .Build.Dense(new[] { 1.0 }),
                    Vector <double> .Build.Dense(new[] { previous }));

                Assert.AreEqual(IterationStatus.Continue, status, "Status check fail.");
            }

            // Add the final residual. Now we should have divergence
            previous *= 1 + Increase + 0.01;
            var status2 = criterion.DetermineStatus(
                Iterations - 1,
                Vector <double> .Build.Dense(new[] { 1.0 }),
                Vector <double> .Build.Dense(new[] { 1.0 }),
                Vector <double> .Build.Dense(new[] { previous }));

            Assert.AreEqual(IterationStatus.Diverged, status2, "Status check fail.");
        }
Пример #2
0
        public void DetermineStatusWithDivergence()
        {
            const float Increase   = 0.5f;
            const int   Iterations = 10;

            var criterion = new DivergenceStopCriterion <Complex32>(Increase, Iterations);

            // Add residuals. We should not diverge because we'll have one to few iterations
            float previous = 1;

            for (var i = 0; i < Iterations - 1; i++)
            {
                previous *= 1 + Increase + 0.01f;
                var status = criterion.DetermineStatus(
                    i,
                    new DenseVector(new[] { new Complex32(1.0f, 0) }),
                    new DenseVector(new[] { new Complex32(1.0f, 0) }),
                    new DenseVector(new[] { new Complex32(previous, 0) }));

                Assert.AreEqual(IterationStatus.Continue, status, "Status check fail.");
            }

            // Add the final residual. Now we should have divergence
            previous *= 1 + Increase + 0.01f;
            var status2 = criterion.DetermineStatus(
                Iterations - 1,
                new DenseVector(new[] { new Complex32(1.0f, 0) }),
                new DenseVector(new[] { new Complex32(1.0f, 0) }),
                new DenseVector(new[] { new Complex32(previous, 0) }));

            Assert.AreEqual(IterationStatus.Diverged, status2, "Status check fail.");
        }
Пример #3
0
        public void DetermineStatusWithDivergenceThroughNaN()
        {
            const float Increase   = 0.5f;
            const int   Iterations = 10;

            var criterion = new DivergenceStopCriterion <Complex32>(Increase, Iterations);

            // Add residuals. We should not diverge because we'll have to few iterations
            for (var i = 0; i < Iterations - 5; i++)
            {
                var status = criterion.DetermineStatus(
                    i,
                    new DenseVector(new[] { new Complex32(1.0f, 0) }),
                    new DenseVector(new[] { new Complex32(1.0f, 0) }),
                    new DenseVector(new[] { new Complex32((i + 1) * (Increase - 0.01f), 0) }));

                Assert.AreEqual(IterationStatus.Continue, status, "Status check fail.");
            }

            // Now make it fail by throwing in a NaN
            var status2 = criterion.DetermineStatus(
                Iterations,
                new DenseVector(new[] { new Complex32(1.0f, 0) }),
                new DenseVector(new[] { new Complex32(1.0f, 0) }),
                new DenseVector(new[] { new Complex32(float.NaN, 0) }));

            Assert.AreEqual(IterationStatus.Diverged, status2, "Status check fail.");
        }
Пример #4
0
        public void DetermineStatusWithDivergenceThroughNaN()
        {
            const double Increase   = 0.5;
            const int    Iterations = 10;

            var criterion = new DivergenceStopCriterion <double>(Increase, Iterations);

            // Add residuals. We should not diverge because we'll have to few iterations
            for (var i = 0; i < Iterations - 5; i++)
            {
                var status = criterion.DetermineStatus(
                    i,
                    Vector <double> .Build.Dense(new[] { 1.0 }),
                    Vector <double> .Build.Dense(new[] { 1.0 }),
                    Vector <double> .Build.Dense(new[] { (i + 1) * (Increase - 0.01) }));

                Assert.AreEqual(IterationStatus.Continue, status, "Status check fail.");
            }

            // Now make it fail by throwing in a NaN
            var status2 = criterion.DetermineStatus(
                Iterations,
                Vector <double> .Build.Dense(new[] { 1.0 }),
                Vector <double> .Build.Dense(new[] { 1.0 }),
                Vector <double> .Build.Dense(new[] { double.NaN }));

            Assert.AreEqual(IterationStatus.Diverged, status2, "Status check fail.");
        }
 public void DetermineStatusWithIllegalIterationNumberThrowsArgumentOutOfRangeException()
 {
     var criterion = new DivergenceStopCriterion<double>(0.5, 15);
     Assert.That(() => criterion.DetermineStatus(
         -1,
         Vector<double>.Build.Dense(3, 4),
         Vector<double>.Build.Dense(3, 5),
         Vector<double>.Build.Dense(3, 6)), Throws.TypeOf<ArgumentOutOfRangeException>());
 }
Пример #6
0
        public void DetermineStatusWithIllegalIterationNumberThrowsArgumentOutOfRangeException()
        {
            var criterion = new DivergenceStopCriterion <double>(0.5, 15);

            Assert.That(() => criterion.DetermineStatus(
                            -1,
                            Vector <double> .Build.Dense(3, 4),
                            Vector <double> .Build.Dense(3, 5),
                            Vector <double> .Build.Dense(3, 6)), Throws.TypeOf <ArgumentOutOfRangeException>());
        }
Пример #7
0
        public void DetermineStatusWithTooFewIterations()
        {
            const float Increase   = 0.5f;
            const int   Iterations = 10;

            var criterion = new DivergenceStopCriterion <Complex32>(Increase, Iterations);

            // Add residuals. We should not diverge because we'll have to few iterations
            for (var i = 0; i < Iterations - 1; i++)
            {
                var status = criterion.DetermineStatus(
                    i,
                    new DenseVector(new[] { new Complex32(1.0f, 0) }),
                    new DenseVector(new[] { new Complex32(1.0f, 0) }),
                    new DenseVector(new[] { new Complex32((i + 1) * (Increase + 0.1f), 0) }));
                Assert.AreEqual(IterationStatus.Continue, status, "Status check fail.");
            }
        }
Пример #8
0
        public void DetermineStatusWithTooFewIterations()
        {
            const double Increase   = 0.5;
            const int    Iterations = 10;

            var criterion = new DivergenceStopCriterion <double>(Increase, Iterations);

            // Add residuals. We should not diverge because we'll have to few iterations
            for (var i = 0; i < Iterations - 1; i++)
            {
                var status = criterion.DetermineStatus(
                    i,
                    Vector <double> .Build.Dense(new[] { 1.0 }),
                    Vector <double> .Build.Dense(new[] { 1.0 }),
                    Vector <double> .Build.Dense(new[] { (i + 1) * (Increase + 0.1) }));

                Assert.AreEqual(IterationStatus.Continue, status, "Status check fail.");
            }
        }
        public void DetermineStatusWithNoDivergence()
        {
            const float Increase   = 0.5f;
            const int   Iterations = 10;

            var criterion = new DivergenceStopCriterion <float>(Increase, Iterations);

            // Add residuals. We should not diverge because we won't have enough increase
            for (var i = 0; i < Iterations * 2; i++)
            {
                var status = criterion.DetermineStatus(
                    i,
                    new DenseVector(new[] { 1.0f }),
                    new DenseVector(new[] { 1.0f }),
                    new DenseVector(new[] { (i + 1) * (Increase - 0.01f) }));

                Assert.AreEqual(IterationStatus.Continue, status, "Status check fail.");
            }
        }
Пример #10
0
        public void ResetCalculationState()
        {
            const double Increase   = 0.5;
            const int    Iterations = 10;

            var criterion = new DivergenceStopCriterion <double>(Increase, Iterations);

            // Add residuals. Blow it up instantly
            var status = criterion.DetermineStatus(
                1,
                Vector <double> .Build.Dense(new[] { 1.0 }),
                Vector <double> .Build.Dense(new[] { 1.0 }),
                Vector <double> .Build.Dense(new[] { double.NaN }));

            Assert.AreEqual(IterationStatus.Diverged, status, "Status check fail.");

            // Reset the state
            criterion.Reset();

            Assert.AreEqual(Increase, criterion.MaximumRelativeIncrease, "Incorrect maximum");
            Assert.AreEqual(Iterations, criterion.MinimumNumberOfIterations, "Incorrect iteration count");
            Assert.AreEqual(IterationStatus.Continue, criterion.Status, "Status check fail.");
        }
Пример #11
0
        public void ResetCalculationState()
        {
            const float Increase   = 0.5f;
            const int   Iterations = 10;

            var criterion = new DivergenceStopCriterion <Complex32>(Increase, Iterations);

            // Add residuals. Blow it up instantly
            var status = criterion.DetermineStatus(
                1,
                new DenseVector(new[] { new Complex32(1.0f, 0) }),
                new DenseVector(new[] { new Complex32(1.0f, 0) }),
                new DenseVector(new[] { new Complex32(float.NaN, 0) }));

            Assert.AreEqual(IterationStatus.Diverged, status, "Status check fail.");

            // Reset the state
            criterion.Reset();

            Assert.AreEqual(Increase, criterion.MaximumRelativeIncrease, "Incorrect maximum");
            Assert.AreEqual(Iterations, criterion.MinimumNumberOfIterations, "Incorrect iteration count");
            Assert.AreEqual(IterationStatus.Continue, criterion.Status, "Status check fail.");
        }
        public void DetermineStatusWithDivergenceThroughNaN()
        {
            const double Increase = 0.5;
            const int Iterations = 10;

            var criterion = new DivergenceStopCriterion<Complex>(Increase, Iterations);

            // Add residuals. We should not diverge because we'll have to few iterations
            for (var i = 0; i < Iterations - 5; i++)
            {
                var status = criterion.DetermineStatus(
                    i,
                    new DenseVector(new[] { new Complex(1.0, 0) }),
                    new DenseVector(new[] { new Complex(1.0, 0) }),
                    new DenseVector(new[] { new Complex((i + 1)*(Increase - 0.01), 0) }));

                Assert.AreEqual(IterationStatus.Continue, status, "Status check fail.");
            }

            // Now make it fail by throwing in a NaN
            var status2 = criterion.DetermineStatus(
                Iterations,
                new DenseVector(new[] { new Complex(1.0, 0) }),
                new DenseVector(new[] { new Complex(1.0, 0) }),
                new DenseVector(new[] { new Complex(double.NaN, 0) }));

            Assert.AreEqual(IterationStatus.Diverged, status2, "Status check fail.");
        }
        public void DetermineStatusWithNoDivergence()
        {
            const double Increase = 0.5;
            const int Iterations = 10;

            var criterion = new DivergenceStopCriterion<Complex>(Increase, Iterations);

            // Add residuals. We should not diverge because we won't have enough increase
            for (var i = 0; i < Iterations*2; i++)
            {
                var status = criterion.DetermineStatus(
                    i,
                    new DenseVector(new[] { new Complex(1.0, 0) }),
                    new DenseVector(new[] { new Complex(1.0, 0) }),
                    new DenseVector(new[] { new Complex((i + 1)*(Increase - 0.01), 0) }));

                Assert.AreEqual(IterationStatus.Continue, status, "Status check fail.");
            }
        }
        public void DetermineStatusWithTooFewIterations()
        {
            const double Increase = 0.5;
            const int Iterations = 10;

            var criterion = new DivergenceStopCriterion<double>(Increase, Iterations);

            // Add residuals. We should not diverge because we'll have to few iterations
            for (var i = 0; i < Iterations - 1; i++)
            {
                var status = criterion.DetermineStatus(
                    i,
                    Vector<double>.Build.Dense(new[] { 1.0 }),
                    Vector<double>.Build.Dense(new[] { 1.0 }),
                    Vector<double>.Build.Dense(new[] { (i + 1)*(Increase + 0.1) }));

                Assert.AreEqual(IterationStatus.Continue, status, "Status check fail.");
            }
        }
        public void DetermineStatusWithDivergence()
        {
            const double Increase = 0.5;
            const int Iterations = 10;

            var criterion = new DivergenceStopCriterion<Complex>(Increase, Iterations);

            // Add residuals. We should not diverge because we'll have one to few iterations
            double previous = 1;
            for (var i = 0; i < Iterations - 1; i++)
            {
                previous *= 1 + Increase + 0.01;
                var status = criterion.DetermineStatus(
                    i,
                    new DenseVector(new[] { new Complex(1.0, 0) }),
                    new DenseVector(new[] { new Complex(1.0, 0) }),
                    new DenseVector(new[] { new Complex(previous, 0) }));

                Assert.AreEqual(IterationStatus.Continue, status, "Status check fail.");
            }

            // Add the final residual. Now we should have divergence
            previous *= 1 + Increase + 0.01;
            var status2 = criterion.DetermineStatus(
                Iterations - 1,
                new DenseVector(new[] { new Complex(1.0, 0) }),
                new DenseVector(new[] { new Complex(1.0, 0) }),
                new DenseVector(new[] { new Complex(previous, 0) }));

            Assert.AreEqual(IterationStatus.Diverged, status2, "Status check fail.");
        }
        public void ResetCalculationState()
        {
            const double Increase = 0.5;
            const int Iterations = 10;

            var criterion = new DivergenceStopCriterion<Complex>(Increase, Iterations);

            // Add residuals. Blow it up instantly
            var status = criterion.DetermineStatus(
                1,
                new DenseVector(new[] { new Complex(1.0, 0) }),
                new DenseVector(new[] { new Complex(1.0, 0) }),
                new DenseVector(new[] { new Complex(double.NaN, 0) }));

            Assert.AreEqual(IterationStatus.Diverged, status, "Status check fail.");

            // Reset the state
            criterion.Reset();

            Assert.AreEqual(Increase, criterion.MaximumRelativeIncrease, "Incorrect maximum");
            Assert.AreEqual(Iterations, criterion.MinimumNumberOfIterations, "Incorrect iteration count");
            Assert.AreEqual(IterationStatus.Continue, criterion.Status, "Status check fail.");
        }
        public void DetermineStatusWithTooFewIterations()
        {
            const float Increase = 0.5f;
            const int Iterations = 10;

            var criterion = new DivergenceStopCriterion<Complex32>(Increase, Iterations);

            // Add residuals. We should not diverge because we'll have to few iterations
            for (var i = 0; i < Iterations - 1; i++)
            {
                var status = criterion.DetermineStatus(
                    i,
                    new DenseVector(new[] { new Complex32(1.0f, 0) }),
                    new DenseVector(new[] { new Complex32(1.0f, 0) }),
                    new DenseVector(new[] { new Complex32((i + 1)*(Increase + 0.1f), 0) }));
                Assert.AreEqual(IterationStatus.Continue, status, "Status check fail.");
            }
        }