Esempio n. 1
0
 public void MinBrent2()
 {
     double xmin = 0;
     //local minimum
     double realXmin = 4.057968;
     double eps = 1e-5;
     int maxCount = 50;
     LineSearch ls = new LineSearch();
     TestFunction1 f = new TestFunction1();
     int counter = ls.FindMinimumViaBrent(f,1,4,5,maxCount,eps,ref xmin);
     Assert.IsTrue(counter<maxCount);
     Assert.IsTrue (System.Math.Abs(xmin-realXmin)<eps);
 }
Esempio n. 2
0
 public void MinBrent3()
 {
     double xmin=0;
     double eps = 1e-5;
     double realXmin = -0.75;
     int maxCount = 50;
     LineSearch ls = new LineSearch();
     TestFunction2 f = new TestFunction2();
     double[] res = new double[3];
     int counter = ls.FindMinInterval(f,-10,1,30,ref res);
     counter = ls.FindMinimumViaBrent(f,res[0],res[1],res[2],maxCount,eps, ref xmin);
     Assert.IsTrue(counter<maxCount);
     Assert.IsTrue (System.Math.Abs(xmin-realXmin)<eps);
 }
Esempio n. 3
0
        public void MinBrent2()
        {
            double xmin = 0;
            //local minimum
            double        realXmin = 4.057968;
            double        eps      = 1e-5;
            int           maxCount = 50;
            LineSearch    ls       = new LineSearch();
            TestFunction1 f        = new TestFunction1();
            int           counter  = ls.FindMinimumViaBrent(f, 1, 4, 5, maxCount, eps, ref xmin);

            Assert.IsTrue(counter < maxCount);
            Assert.IsTrue(System.Math.Abs(xmin - realXmin) < eps);
        }
Esempio n. 4
0
        public void MinBrent4()
        {
            double        xmin     = 0;
            double        eps      = 1e-5;
            double        realXmin = -0.75;
            int           maxCount = 50;
            LineSearch    ls       = new LineSearch();
            TestFunction2 f        = new TestFunction2();

            double[] res     = new double[3];
            int      counter = ls.FindMinInterval(f, 1000, 1, 30, ref res);

            counter = ls.FindMinimumViaBrent(f, res[0], res[1], res[2], 50, eps, ref xmin);
            Assert.IsTrue(counter < maxCount);
            Assert.IsTrue(System.Math.Abs(xmin - realXmin) < eps);
        }
Esempio n. 5
0
        public void MinBrent1()
        {
            double        xmin     = 0;
            int           maxCount = 50;
            double        realXmin = -1.364641;
            double        eps      = 1e-5;
            LineSearch    ls       = new LineSearch();
            TestFunction1 f        = new TestFunction1();

            double[] res     = new double[3];
            int      counter = ls.FindMinInterval(f, -10, 1, maxCount, ref res);

            counter = ls.FindMinimumViaBrent(f, res[0], res[1], res[2], maxCount, eps, ref xmin);
            Assert.IsTrue(counter < maxCount);
            Assert.IsTrue(System.Math.Abs(xmin - realXmin) < eps);
        }
Esempio n. 6
0
        private double[] CalculateNextPoint(double[] pX, double[] pGrad, GeneralMatrix hessian)
        {
            int i=0;
            double xmin=0;
            double step = _step;
            GeneralMatrix alfaX = new GeneralMatrix(_nDim,1);
            GeneralMatrix prevX = new GeneralMatrix(pX,_nDim);
            GeneralMatrix prevGrad = new GeneralMatrix(pGrad,_nDim);
            double[] intermediate = new double[_nDim];;

            alfaX = hessian.Multiply(prevGrad);

            //doing a line search to minimize alpha
            OneDWrapper wrapper = new OneDWrapper(_f,prevX,alfaX);
            LineSearch search = new LineSearch();
            double[] interval = new double[Constants.BRACKET_POINTS];
            int it1 = search.FindMinInterval(wrapper,_alpha,step,50,ref interval);
            int it2 = search.FindMinimumViaBrent(wrapper,interval[0],interval[1],interval[2],50,_epsilon, ref xmin);

            for (i=0;i<_nDim; i++)
                intermediate[i] = prevX.GetElement(i,0) - xmin*alfaX.GetElement(i,0);

            _alpha = xmin;

            return intermediate;
        }