Пример #1
0
        public double[] Train()
        {
            var startingThetas = new double[this.featuresCount + 1]; // add one column for intercept

            var o = new QuasiNewtonOptimizer();

            return(o.Minimize(this.CostFunction, startingThetas));
        }
Пример #2
0
        private Array generateEval(int rennAbteilungsAnzahl)
        {
            Random rtmp = new Random();

            double[] digit = new double[rennAbteilungsAnzahl];
            for (int i = digit.Length - 1; i >= 0; i--)
            {
                digit[i] = rtmp.Next(1, maxValue);
            }

            Extreme.Mathematics.Vector <double> initialGuess = Extreme.Mathematics.Vector.Create(digit);

            Func <Extreme.Mathematics.Vector <double>, double> f = evalFunctionfromVector;
            // Which method is used, is specified by a constructor
            // parameter of type QuasiNewtonMethod:
            var bfgs = new QuasiNewtonOptimizer(QuasiNewtonMethod.Bfgs);

            bfgs.InitialGuess = initialGuess;
            bfgs.ExtremumType = ExtremumType.Minimum;

            // Set the ObjectiveFunction:
            bfgs.ObjectiveFunction = f;
            // The FindExtremum method does all the hard work:
            bfgs.FindExtremum();

            Console.WriteLine("BFGS Method:");
            Console.WriteLine("  Solution: {0}", bfgs.Extremum);
            Console.WriteLine("  Estimated error: {0}", bfgs.EstimatedError);
            Console.WriteLine("  # iterations: {0}", bfgs.IterationsNeeded);
            // Optimizers return the number of function evaluations
            // and the number of gradient evaluations needed:
            Console.WriteLine("  # function evaluations: {0}", bfgs.EvaluationsNeeded);
            Console.WriteLine("  # gradient evaluations: {0}", bfgs.GradientEvaluationsNeeded);

            return(digit);
        }