예제 #1
0
        public void OptimizationTruncatedNewton()
        {
            //Rosenbrock banana function
            //f(a,b)=100*(b-a^2)^2+(1-a)^2
            //The minimum is at (1,1) and the  function value is 0.

            //using DotNumerics.Optimization;

            TruncatedNewton tNewton = new TruncatedNewton();

            double[] initialGuess = new double[2];
            initialGuess[0] = 0.1;
            initialGuess[1] = 2;
            double[] minimum = tNewton.ComputeMin(BananaFunction, BananaGradient, initialGuess);

            ObjectDumper.Write("Truncated Newton.");
            ObjectDumper.Write("a = " + minimum[0].ToString() + ",   b = " + minimum[1].ToString());

            //f(a,b) = 100*(b-a^2)^2 + (1-a)^2
            //private double BananaFunction(double[] x)
            //{
            //    double f = 0;
            //    f = 100 * Math.Pow((x[1] - x[0] * x[0]), 2) + Math.Pow((1 - x[0]), 2);
            //    return f;
            //}

            //double[] bananaGrad = new double[2];
            //private double[] BananaGradient(double[] x)
            //{
            //    this.bananaGrad[0] = 200 * (x[1] - x[0] * x[0]) * (-2 * x[0]) - 2 * (1 - x[0]);
            //    this.bananaGrad[1] = 200 * (x[1] - x[0] * x[0]);
            //    return bananaGrad;
            //}
        }
예제 #2
0
        public double[] StartMapping(SpotParsInitBox spotParsInitBox)
        {
            OptBoundVariable[] x = new OptBoundVariable[spotParsInitBox.SpotsNumber * 4];

            for (int i = 0; i < x.Length; i++)
            {
                x[i] = new OptBoundVariable();
            }

            for (int q = 0; q < this.lcObs.Length; q++)
            {
                for (int s = 0; s < spotParsInitBox.SpotsNumber; s++)
                {
                    this.modeller[q].StarM.AddUniformCircularSpot(0.0, 0.0, 1.0, 4000, 30, 90);
                }
            }

            for (int s = 0; s < spotParsInitBox.SpotsNumber; s++)
            {
                x[0 + s * 4].InitialGuess = spotParsInitBox.spots[s].longitude * Math.PI / 180;
                x[0 + s * 4].UpperBound   = spotParsInitBox.spots[s].longitudeUpperLimit * Math.PI / 180;
                x[0 + s * 4].LowerBound   = spotParsInitBox.spots[s].longitudeLowerLimit * Math.PI / 180;
                x[0 + s * 4].Fixed        = spotParsInitBox.spots[s].longitudeFixed;

                x[1 + s * 4].InitialGuess = spotParsInitBox.spots[s].colatutude * Math.PI / 180;
                x[1 + s * 4].UpperBound   = spotParsInitBox.spots[s].colatitudeUpperLimit * Math.PI / 180;
                x[1 + s * 4].LowerBound   = spotParsInitBox.spots[s].colatitudeLowerLimit * Math.PI / 180;
                x[1 + s * 4].Fixed        = spotParsInitBox.spots[s].colatitudeFixed;

                x[2 + s * 4].InitialGuess = spotParsInitBox.spots[s].radius * Math.PI / 180;
                x[2 + s * 4].UpperBound   = spotParsInitBox.spots[s].radiusUpperLimit * Math.PI / 180;
                x[2 + s * 4].LowerBound   = spotParsInitBox.spots[s].radiusLowerLimit * Math.PI / 180;
                x[2 + s * 4].Fixed        = spotParsInitBox.spots[s].radiusFixed;

                x[3 + s * 4].InitialGuess = spotParsInitBox.spots[s].teff;
                x[3 + s * 4].UpperBound   = spotParsInitBox.spots[s].teffUpperLimit;
                x[3 + s * 4].LowerBound   = spotParsInitBox.spots[s].teffLowerLimit;
                x[3 + s * 4].Fixed        = spotParsInitBox.spots[s].teffFixed;
            }

            double[] res;

            Simplex simplex = new Simplex();

            DotNumerics.Optimization.TruncatedNewton tn = new TruncatedNewton();


            //res = simplex.ComputeMin(this.Khi2, x);

            res = tn.ComputeMin(this.Khi2, this.GradKhi2, x);

            this.GenerateModLightCurve();

            return(res);
        }
예제 #3
0
        public void OptimizationTruncatedNewtonConstrained()
        {
            //This example minimize the function
            //f(x0,x2,...,xn)= (x0-0)^2+(x1-1)^2+...(xn-n)^2
            //The minimum is at (0,1,2,3...,n) for the unconstrained case.

            //using DotNumerics.Optimization;

            TruncatedNewton tNewton      = new TruncatedNewton();
            int             numVariables = 5;

            OptBoundVariable[] variables = new OptBoundVariable[numVariables];
            //Constrained Minimization on the interval (-10,10), initial Guess=-2;
            for (int i = 0; i < numVariables; i++)
            {
                variables[i] = new OptBoundVariable("x" + i.ToString(), -2, -10, 10);
            }
            double[] minimum = tNewton.ComputeMin(ObjetiveFunction, Gradient, variables);

            ObjectDumper.Write("Truncated Newton Method. Constrained Minimization on the interval (-10,10)");
            for (int i = 0; i < minimum.Length; i++)
            {
                ObjectDumper.Write("x" + i.ToString() + " = " + minimum[i].ToString());
            }

            //Constrained Minimization on the interval (-10,3), initial Guess=-2;
            for (int i = 0; i < numVariables; i++)
            {
                variables[i].UpperBound = 3;
            }
            minimum = tNewton.ComputeMin(ObjetiveFunction, Gradient, variables);

            ObjectDumper.Write("Truncated Newton Method. Constrained Minimization on the interval (-10,3)");
            for (int i = 0; i < minimum.Length; i++)
            {
                ObjectDumper.Write("x" + i.ToString() + " = " + minimum[i].ToString());
            }

            //f(a,b) = 100*(b-a^2)^2 + (1-a)^2
            //private double BananaFunction(double[] x)
            //{
            //    double f = 0;
            //    f = 100 * Math.Pow((x[1] - x[0] * x[0]), 2) + Math.Pow((1 - x[0]), 2);
            //    return f;
            //}

            //double[] bananaGrad = new double[2];
            //private double[] BananaGradient(double[] x)
            //{
            //    this.bananaGrad[0] = 200 * (x[1] - x[0] * x[0]) * (-2 * x[0]) - 2 * (1 - x[0]);
            //    this.bananaGrad[1] = 200 * (x[1] - x[0] * x[0]);
            //    return bananaGrad;
            //}
        }