예제 #1
0
        public void TestReflection()
        {
            var cf    = new Poly();
            var optim = new NelderMead(cf);

            var simplex = new DoubleVector[3];

            simplex[0] = new DoubleVector(new double[2] {
                1, 1
            });
            simplex[1] = new DoubleVector(new double[2] {
                1, -1
            });
            simplex[2] = new DoubleVector(new double[2] {
                2, 0
            });

            optim.Rho = 1.5;
            optim.InitializeMethod(simplex);
            optim.IterateMethod();

            DoubleVector xr = (1 + optim.Rho) * (new DoubleVector(new double[2] {
                1, 0
            })) - optim.Rho * simplex[2];

            Assert.IsTrue(optim.LastStep == NelderMead.Step.Reflection);
            Assert.AreEqual(optim.Simplex[0][0], xr[0]);
            Assert.AreEqual(optim.Simplex[0][1], xr[1]);
        }
예제 #2
0
        public void TestInsideContraction()
        {
            Poly       cf    = new Poly();
            NelderMead optim = new NelderMead(cf);

            DoubleVector[] simplex = new DoubleVector[3];
            simplex[0] = new DoubleVector(new double[2] {
                1, 1
            });
            simplex[1] = new DoubleVector(new double[2] {
                1, -1
            });
            simplex[2] = new DoubleVector(new double[2] {
                2, 0
            });

            optim.Rho = 10;
            optim.Psi = 0.5;
            optim.InitializeMethod(simplex);
            optim.IterateMethod();

            DoubleVector xr = (1 - optim.Psi) * (new DoubleVector(new double[2] {
                1, 0
            })) + optim.Psi * simplex[2];

            Assert.IsTrue(optim.LastStep == NelderMead.Step.InsideContraction);
            Assert.AreEqual(optim.Simplex[2][0], xr[0]);
            Assert.AreEqual(optim.Simplex[2][1], xr[1]);
        }
예제 #3
0
        public void TestExpansion()
        {
            Poly       cf    = new Poly();
            NelderMead optim = new NelderMead(cf);

            DoubleVector[] simplex = new DoubleVector[3];
            simplex[0] = new DoubleVector(new double[2] {
                1, 1
            });
            simplex[1] = new DoubleVector(new double[2] {
                1, -1
            });
            simplex[2] = new DoubleVector(new double[2] {
                2, 0
            });


            optim.InitializeMethod(simplex);
            optim.Rho = 1.5;
            optim.Chi = 1 / 1.5;
            optim.IterateMethod();

            DoubleVector xr = (1 + optim.Rho * optim.Chi) * (new DoubleVector(new double[2] {
                1, 0
            })) - optim.Rho * optim.Chi * simplex[2];

            Assert.IsTrue(optim.LastStep == NelderMead.Step.Expansion);
            Assert.AreEqual(optim.Simplex[0][0], xr[0]);
            Assert.AreEqual(optim.Simplex[0][1], xr[1]);
        }
예제 #4
0
        public void TestShrink()
        {
            Poly       cf    = new Poly();
            NelderMead optim = new NelderMead(cf);

            DoubleVector[] simplex = new DoubleVector[3];
            simplex[0] = new DoubleVector(new double[2] {
                1, 1
            });
            simplex[1] = new DoubleVector(new double[2] {
                1, -1
            });
            simplex[2] = new DoubleVector(new double[2] {
                2, 0
            });

            optim.Rho = 10;
            optim.Psi = 1.5;
            optim.InitializeMethod(simplex);
            optim.IterateMethod();

            Assert.IsTrue(optim.LastStep == NelderMead.Step.Shrink);
        }