public static void Grid(Problem problem, Problem validation, Parameter parameters, List <double> CValues, List <double> GammaValues, string outputFile, out double C, out double Gamma)
        {
            C     = 0.0;
            Gamma = 0.0;
            double num = -1.7976931348623157E+308;

            if (!string.IsNullOrEmpty(outputFile))
            {
                File.WriteAllText(outputFile, string.Empty);
            }
            for (int i = 0; i < CValues.Count; i++)
            {
                for (int j = 0; j < GammaValues.Count; j++)
                {
                    parameters.C     = CValues[i];
                    parameters.Gamma = GammaValues[j];
                    Model  model = Training.Train(problem, parameters);
                    double num2  = Prediction.Predict(validation, "tmp.txt", model, false, 1);
                    Console.Write("{0} {1} {2}", parameters.C, parameters.Gamma, num2);
                    if (!string.IsNullOrEmpty(outputFile))
                    {
                        File.AppendAllText(outputFile, string.Format("{0} {1} {2}\n", parameters.C, parameters.Gamma, num2));
                    }
                    if (num2 > num)
                    {
                        C     = parameters.C;
                        Gamma = parameters.Gamma;
                        num   = num2;
                        Console.WriteLine(" New Maximum!");
                    }
                    else
                    {
                        Console.WriteLine();
                    }
                }
            }
        }
        public static int SmartGridRegression(Problem problem, Parameter parameter, double C_Start, double C_Multi, double Gamma_Start, double Gamma_Multi, double P_Start, double P_Multi, string outputFile, int nrfold, out double C, out double Gamma, out double P)
        {
            C     = C_Start;
            Gamma = Gamma_Start;
            P     = P_Start;
            double num = -1.7976931348623157E+308;

            if (!string.IsNullOrEmpty(outputFile))
            {
                File.WriteAllText(outputFile, string.Empty);
            }
            int num2 = 0;

            double[] array = new double[21]
            {
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                C_Start,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0
            };
            double[] array2 = new double[21]
            {
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                Gamma_Start,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0
            };
            double[] array3 = new double[21]
            {
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                P_Start,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0
            };
            for (int i = 0; i < 10; i++)
            {
                array[9 - i]   = array[10 - i] / C_Multi;
                array[11 + i]  = array[10 + i] * C_Multi;
                array2[9 - i]  = array2[10 - i] / Gamma_Multi;
                array2[11 + i] = array2[10 + i] * Gamma_Multi;
                array3[9 - i]  = array3[10 - i] / P_Multi;
                array3[11 + i] = array3[10 + i] / P_Multi;
            }
            double[,,] array4 = new double[21, 21, 21];
            Point3D point3D = new Point3D(10, 10, 10);

            Point3D[] array5 = ParameterSelection.FindNeedCompute(array4, point3D);
            while (array5.Length > 0)
            {
                for (int j = 0; j < array5.Length; j++)
                {
                    parameter.C     = array[array5[j].C];
                    parameter.Gamma = array2[array5[j].G];
                    parameter.P     = array3[array5[j].P];
                    double num3 = Training.PerformCrossValidation(problem, parameter, nrfold);
                    array4[array5[j].C, array5[j].G, array5[j].P] = num3;
                    Console.Write(string.Format("{0} {1} {2} {3}", array[array5[j].C], array2[array5[j].G], array3[array5[j].P], num3));
                    if (!string.IsNullOrEmpty(outputFile))
                    {
                        File.AppendAllText(outputFile, string.Format("{0} {1} {2} {3}\n", array[array5[j].C], array2[array5[j].G], array3[array5[j].P], num3));
                    }
                    if (num3 < num)
                    {
                        num       = num3;
                        point3D.C = array5[j].C;
                        point3D.G = array5[j].G;
                        point3D.P = array5[j].P;
                        C         = array[array5[j].C];
                        Gamma     = array2[array5[j].G];
                        P         = array3[array5[j].P];
                        Console.WriteLine(" New Min!");
                    }
                    else
                    {
                        Console.WriteLine();
                    }
                    num2++;
                }
                array5 = ParameterSelection.FindNeedCompute(array4, point3D);
            }
            return(num2);
        }
 private static double GridCompute(GridComputingParameter Para)
 {
     return(Training.PerformCrossValidation(Para.problem, Para.parameter, Para.nrfold));
 }
        public static int SmartGrid(Problem problem, Parameter parameters, double C_Start, double C_Multi, double Gamma_Start, double Gamma_Multi, string outputFile, int nrfold, out double C, out double Gamma, bool Parallel = true)
        {
            C     = C_Start;
            Gamma = Gamma_Start;
            double num = -1.7976931348623157E+308;

            if (!string.IsNullOrEmpty(outputFile))
            {
                File.WriteAllText(outputFile, string.Empty);
            }
            int num2 = 0;

            double[,] array = new double[21, 21];
            double[] array2 = new double[21]
            {
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                C_Start,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0
            };
            double[] array3 = new double[21]
            {
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                Gamma_Start,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0
            };
            for (int i = 0; i < 10; i++)
            {
                array2[9 - i]  = array2[10 - i] / C_Multi;
                array2[11 + i] = array2[10 + i] * C_Multi;
                array3[9 - i]  = array3[10 - i] / Gamma_Multi;
                array3[11 + i] = array3[10 + i] * Gamma_Multi;
            }
            Point p = new Point(10, 10);

            Point[] array4 = ParameterSelection.FindNeedCompute(array, p, TrendLineDirection.LeftBelow_to_RightHigh);
            while (array4.Length > 0)
            {
                Task <double>[] array5 = new Task <double> [array4.Length];
                if (Parallel)
                {
                    for (int j = 0; j < array4.Length; j++)
                    {
                        Parameter parameter = (Parameter)parameters.Clone();
                        parameter.C     = array2[array4[j].X];
                        parameter.Gamma = array3[array4[j].Y];
                        GridComputingParameter state = new GridComputingParameter(problem, parameter, nrfold);
                        array5[j] = new Task <double>((object obj) => ParameterSelection.GridCompute((GridComputingParameter)obj), state);
                        array5[j].Start();
                    }
                }
                for (int k = 0; k < array4.Length; k++)
                {
                    double num3;
                    if (Parallel)
                    {
                        num3 = array5[k].Result;
                    }
                    else
                    {
                        parameters.C     = array2[array4[k].X];
                        parameters.Gamma = array3[array4[k].Y];
                        num3             = Training.PerformCrossValidation(problem, parameters, nrfold);
                    }
                    array[array4[k].X, array4[k].Y] = num3;
                    Console.Write(string.Format("{0} {1} {2}", array2[array4[k].X], array3[array4[k].Y], num3));
                    if (!string.IsNullOrEmpty(outputFile))
                    {
                        File.AppendAllText(outputFile, string.Format("{0} {1} {2}\n", array2[array4[k].X], array3[array4[k].Y], num3));
                    }
                    if (num3 > num)
                    {
                        num   = num3;
                        p.X   = array4[k].X;
                        p.Y   = array4[k].Y;
                        C     = array2[array4[k].X];
                        Gamma = array3[array4[k].Y];
                        Console.WriteLine(" New Maximum!");
                    }
                    else
                    {
                        Console.WriteLine();
                    }
                    num2++;
                }
                array4 = ParameterSelection.FindNeedCompute(array, p, TrendLineDirection.LeftBelow_to_RightHigh);
            }
            return(num2);
        }