Пример #1
0
        public void TestRosenbrock()
        {
            Rosenbrock        cf    = new Rosenbrock();
            EndCriteria       ec    = new EndCriteria();
            ConjugateGradient optim = new ConjugateGradient(cf, ec);
            //  new SecantLineSearch(cf,ec));

            DoubleVector x0 = new DoubleVector(new double[5] {
                1.3, 0.7, 0.8, 1.9, 1.2
            });

            optim.Minimize(x0);

            //Console.WriteLine(optim.IterationVectors[0].ToString());
            //Console.WriteLine(optim.IterationVectors[1].ToString());
            //Console.WriteLine(optim.IterationVectors[2].ToString());

            //Console.WriteLine(optim.SolutionVector.ToString());

            Assert.AreEqual(optim.SolutionValue, 0.0, 0.1);
            Assert.AreEqual(optim.SolutionVector[0], 1.0, 0.1);
            Assert.AreEqual(optim.SolutionVector[1], 1.0, 0.1);
            Assert.AreEqual(optim.SolutionVector[2], 1.0, 0.1);
            Assert.AreEqual(optim.SolutionVector[3], 1.0, 0.2);
            Assert.AreEqual(optim.SolutionVector[4], 1.0, 0.4);
        }
Пример #2
0
        public void TestInitializeMethod()
        {
            var cf    = new Rosenbrock();
            var optim = new NelderMead(cf);
            var x0    = new DoubleVector(new double[4] {
                0, 1, 2, 3
            });

            optim.SimplexDelta     = 0.1;
            optim.SimplexZeroDelta = 0.0001;

            optim.InitializeMethod(x0);

            Assert.AreEqual(optim.Simplex.Length, 5);
            for (int i = 0; i < optim.Simplex.Length; i++)
            {
                Assert.AreEqual(optim.Simplex[i][0], x0[0], optim.SimplexZeroDelta);
                Assert.AreEqual(optim.Simplex[i][1], x0[1], optim.SimplexDelta * x0[1] + 0.001);
                Assert.AreEqual(optim.Simplex[i][2], x0[2], optim.SimplexDelta * x0[2] + 0.001);
                Assert.AreEqual(optim.Simplex[i][3], x0[3], optim.SimplexDelta * x0[3] + 0.001);
            }
            for (int i = 1; i < optim.Simplex.Length; i++)
            {
                Assert.IsTrue(cf.Value(optim.Simplex[i - 1]) < cf.Value(optim.Simplex[i]));
            }
        }
Пример #3
0
        public void TestRosenbrock()
        {
            var cf    = new Rosenbrock();
            var optim = new NelderMead(cf);

            var x0 = new DoubleVector(new double[5] {
                1.3, 0.7, 0.8, 1.9, 1.2
            });

            optim.Minimize(x0);

            Assert.AreEqual(optim.SolutionValue, 0.0, 0.0001);
            Assert.AreEqual(optim.SolutionVector[0], 1.0, 0.0001);
            Assert.AreEqual(optim.SolutionVector[1], 1.0, 0.0001);
            Assert.AreEqual(optim.SolutionVector[2], 1.0, 0.0001);
            Assert.AreEqual(optim.SolutionVector[3], 1.0, 0.0001);
            Assert.AreEqual(optim.SolutionVector[4], 1.0, 0.0001);
        }
Пример #4
0
		public void TestRosenbrock()
		{
			Rosenbrock cf = new Rosenbrock();
			EndCriteria ec = new EndCriteria();
			ConjugateGradient optim = new ConjugateGradient(cf, ec);
			//  new SecantLineSearch(cf,ec));

			DoubleVector x0 = new DoubleVector(new double[5] { 1.3, 0.7, 0.8, 1.9, 1.2 });

			optim.Minimize(x0);

			Assert.AreEqual(optim.SolutionValue, 0.0, 0.1);
			Assert.AreEqual(optim.SolutionVector[0], 1.0, 0.1);
			Assert.AreEqual(optim.SolutionVector[1], 1.0, 0.1);
			Assert.AreEqual(optim.SolutionVector[2], 1.0, 0.1);
			Assert.AreEqual(optim.SolutionVector[3], 1.0, 0.2);
			Assert.AreEqual(optim.SolutionVector[4], 1.0, 0.4);
		}
Пример #5
0
        public void TestRosenbrock()
        {
            var cf    = new Rosenbrock();
            var ec    = new EndCriteria();
            var optim = new ConjugateGradient(cf, ec);
            //  new SecantLineSearch(cf,ec));

            var x0 = new DoubleVector(new double[5] {
                1.3, 0.7, 0.8, 1.9, 1.2
            });

            optim.Minimize(x0);

            Assert.AreEqual(optim.SolutionValue, 0.0, 0.1);
            Assert.AreEqual(optim.SolutionVector[0], 1.0, 0.1);
            Assert.AreEqual(optim.SolutionVector[1], 1.0, 0.1);
            Assert.AreEqual(optim.SolutionVector[2], 1.0, 0.1);
            Assert.AreEqual(optim.SolutionVector[3], 1.0, 0.2);
            Assert.AreEqual(optim.SolutionVector[4], 1.0, 0.4);
        }
Пример #6
0
 public void TestInitializeMethod()
 {
   Rosenbrock cf = new Rosenbrock();
   NelderMead optim = new NelderMead(cf);
   DoubleVector x0 = new DoubleVector(new double[4]{0,1,2,3});
   
   optim.SimplexDelta = 0.1;
   optim.SimplexZeroDelta = 0.0001;
   
   optim.InitializeMethod(x0);
   
   Assert.AreEqual(optim.Simplex.Length,5);
   for (int i=0; i<optim.Simplex.Length; i++) 
   {
     Assert.AreEqual(optim.Simplex[i][0],x0[0],optim.SimplexZeroDelta);
     Assert.AreEqual(optim.Simplex[i][1],x0[1],optim.SimplexDelta*x0[1]+0.001);
     Assert.AreEqual(optim.Simplex[i][2],x0[2],optim.SimplexDelta*x0[2]+0.001);
     Assert.AreEqual(optim.Simplex[i][3],x0[3],optim.SimplexDelta*x0[3]+0.001);
   }
   for (int i=1; i<optim.Simplex.Length; i++) 
   {
     Assert.IsTrue(cf.Value(optim.Simplex[i-1])<cf.Value(optim.Simplex[i]));
   }
 }
Пример #7
0
    public void TestRosenbrock() 
    {
      Rosenbrock cf = new Rosenbrock();
      NelderMead optim = new NelderMead(cf);
      
      DoubleVector x0 = new DoubleVector(new double[5]{1.3,0.7,0.8,1.9,1.2});
      
      optim.Minimize(x0);

      Assert.AreEqual(optim.SolutionValue,0.0,0.0001);
      Assert.AreEqual(optim.SolutionVector[0],1.0,0.0001);
      Assert.AreEqual(optim.SolutionVector[1],1.0,0.0001);
      Assert.AreEqual(optim.SolutionVector[2],1.0,0.0001);
      Assert.AreEqual(optim.SolutionVector[3],1.0,0.0001);
      Assert.AreEqual(optim.SolutionVector[4],1.0,0.0001);
    }