Пример #1
0
        public void ParabolaEdge()
        {
            // minimizes x(x-2) in [5, 6]
            Status status = MinimizeGolden.Min(x => x * (x - 2.0), 5, 6);

            Assert.True(status.converged);
            Assert.AreEqual(5.0, status.argmin, EPS);
        }
Пример #2
0
        public void Hyperbola()
        {
            // Minimizes 1 / (x - 1) in [0, 2]
            Status status = MinimizeGolden.Min(x => 1.0 / (x - 1.0), 0, 2);

            Assert.AreEqual(1.0d, status.argmin, EPS);
            Assert.True(status.converged);
        }
Пример #3
0
        public void Sqrt()
        {
            // Minimizes sqrt(x) in [0, inf)
            Status status = MinimizeGolden.Min(x => Math.Sqrt(x), 0, 300);

            Assert.True(status.converged);
            Assert.AreEqual(0.0, status.argmin, EPS);
        }
Пример #4
0
        public void Basic()
        {
            Status status = MinimizeGolden.Min(x => x * x, -1.0, 1.0, 1e-3, 100);
            double res    = status.argmin;

            Assert.AreEqual(0, res, 1e-3);
            Assert.True(status.converged);
        }
Пример #5
0
        public void Cusp()
        {
            // minimizes a cusp
            Status status = MinimizeGolden.Min(x => Math.Sqrt(Math.Abs(x - 5)), 0, 10);

            Assert.True(status.converged);
            Assert.AreEqual(5, status.argmin, EPS);
        }
Пример #6
0
        public void Cos()
        {
            // minimizes cosine
            Status status = MinimizeGolden.Min(x => Math.Cos(x), -10, 10);

            Assert.True(status.converged);
            Assert.AreEqual(-1, Math.Cos(status.argmin), EPS);
        }
Пример #7
0
        public void BoundedCubic()
        {
            // minimizes a cubic against bounds
            Status status = MinimizeGolden.Min(x => x * (x - 2) * (x - 1), 5, 6);

            Assert.True(status.converged);
            Assert.AreEqual(5, status.argmin, EPS);
        }
Пример #8
0
        public void NegCubic()
        {
            // maximizes a cubic
            Status status = MinimizeGolden.Min(x => - x * (x - 2) * (x - 1), 0, 3);

            Assert.True(status.converged);
            Assert.AreEqual(3, status.argmin, EPS);
        }
Пример #9
0
        public void SqrtAbs()
        {
            // Minimizes sqrt(|x|)
            Status status = MinimizeGolden.Min(x => Math.Sqrt(Math.Abs(x)), -3, 3);

            Assert.True(status.converged);
            Assert.AreEqual(0.0, status.argmin, EPS);
            Assert.AreEqual(0.0, status.minimum, 1e-3);
        }
Пример #10
0
        public void Parabola()
        {
            // Succeeds out on bounded minimization of -x^2
            Status status = MinimizeGolden.Min(x => - x * x, -1, 2);

            Assert.AreEqual(2, status.argmin, EPS);
            Assert.AreEqual(-4, status.minimum, EPS);
            Assert.True(status.converged);
        }
Пример #11
0
        public void NegHyperbola()
        {
            // Minimizes -1 / (x - 1) in [0, 2]
            Status status = MinimizeGolden.Min(x => - 1.0f / (x - 1.0f), 0, 2);

            Assert.AreEqual(1.0, status.argmin, EPS);
            Assert.True(status.converged);
            Assert.AreEqual(41, status.iterations);
        }
Пример #12
0
        public void Tol()
        {
            // returns answer if tolerance not met
            Status status = MinimizeGolden.Min(x => x * (x - 2.0), 0, 3, 0, 200);

            Assert.AreEqual(200, status.iterations);
            Assert.AreEqual(-1.0, status.minimum, EPS);
            Assert.AreEqual(1.0, status.argmin, EPS);
            Assert.False(status.converged);
        }