private double getErrorOfArimaModel()
        {
            // or to predict a specified number of values:
            Vector nextValues = arimaModel.Forecast(numberOfTests);
            int    selected   = 0;

            Dispatcher.Invoke(new Action(() => selected = CompareComboBox.SelectedIndex));
            switch (selected)
            {
            case 0:     // MSE
                double mse = 0;
                for (int i = 0; i < numberOfTests; i++)
                {
                    mse += Math.Pow(nextValues[i] - testArima[i], 2);
                }
                mse /= numberOfTests;
                return(-1 * mse);

            case 1:     // ERROR %

                double errorPercent = 0;
                double sumTargets   = 0;
                for (int i = 0; i < numberOfTests; i++)
                {
                    errorPercent += Math.Abs(nextValues[i] - testArima[i]);
                    sumTargets   += Math.Abs(testArima[i]);
                }
                errorPercent /= sumTargets;
                return(-1 * errorPercent * 100);
            }
            return(-9999999999); // a very bad fitness when error occured
        }
        private double getErrorOfArimaModel()
        {
            // or to predict a specified number of values:
            Extreme.Mathematics.Vector nextValues = arimaModel.Forecast(NUMBER_OF_HYBRID_TEST);

            switch (CompareComboBox.SelectedIndex)
            {
            case 0:     // MSE
                double mse = 0;
                for (int i = 0; i < NUMBER_OF_HYBRID_TEST; i++)
                {
                    mse += Math.Pow(nextValues[i] - testArima[i], 2);
                }
                mse /= NUMBER_OF_HYBRID_TEST;
                return(-1 * mse);

            case 1:     // ERROR %

                double errorPercent = 0;
                double sumTargets   = 0;
                for (int i = 0; i < NUMBER_OF_HYBRID_TEST; i++)
                {
                    errorPercent += Math.Abs(nextValues[i] - testArima[i]);
                    sumTargets   += testArima[i];
                }
                errorPercent /= sumTargets;
                return(-1 * errorPercent);
            }
            return(-9999999999); // a very bad fitness when error occured
        }
        private double getErrorOfArimaModel(int selected)
        {
            // or to predict a specified number of values:
            Vector nextValues = arimaModel.Forecast(numberOfTests);

            switch (selected)
            {
            case 0:     // MSE
                return(-1 * MyErrorParameters.MSE(nextValues.ToArray(), testArima));

            case 1:     // ERROR %
                return(-1 * MyErrorParameters.ERROR_Percent(nextValues.ToArray(), testArima));
            }
            return(-9999999999); // a very bad fitness when error occured
        }
Example #4
0
        private double evalFunctionfromVector(Extreme.Mathematics.Vector <double> x)
        {
            List <string>[] arrayListejeAbteilung = new List <string> [maxValue];
            for (int i = 0; i < x.Count; i++)
            {
                arrayListejeAbteilung[Convert.ToInt32(x.GetValue(i))].Add(konfliktRennID[i]);
            }
            int anzahlderKonflikte = 0;

            foreach (List <string> ltmp in arrayListejeAbteilung)
            {
                anzahlderKonflikte += DataAccess.AnzahlderKonflikte(ltmp);
            }

            /*
             * int rennbooteInLauf = 0;
             * rennbooteInLauf += DataAccess.RennbooteInLauf(list[0]);
             * rennbooteInLauf += DataAccess.RennbooteInLauf(list[1]);
             */
            return(anzahlderKonflikte * 10000);
            // + rennbooteInLauf*10 + DataAccess.KinderInLauf1(list[0];
        }
Example #5
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);
        }