Ejemplo n.º 1
0
        public static Problem Read(string filename)
        {
            FileStream fileStream = File.OpenRead(filename);

            try
            {
                return(Problem.Read(fileStream));
            }
            finally
            {
                fileStream.Close();
            }
        }
Ejemplo n.º 2
0
        private static void parseCommandLine(string[] args, out Parameter parameters, out Problem problem, out bool crossValidation, out int nrfold, out string modelFilename)
        {
            parameters      = new Parameter();
            crossValidation = false;
            nrfold          = 0;
            int num = 0;

            while (num < args.Length && args[num][0] == '-')
            {
                num++;
                switch (args[num - 1][1])
                {
                case 's':
                    parameters.SvmType = (SvmType)int.Parse(args[num]);
                    break;

                case 't':
                    parameters.KernelType = (KernelType)int.Parse(args[num]);
                    break;

                case 'd':
                    parameters.Degree = int.Parse(args[num]);
                    break;

                case 'g':
                    parameters.Gamma = double.Parse(args[num]);
                    break;

                case 'r':
                    parameters.Coefficient0 = double.Parse(args[num]);
                    break;

                case 'n':
                    parameters.Nu = double.Parse(args[num]);
                    break;

                case 'm':
                    parameters.CacheSize = double.Parse(args[num]);
                    break;

                case 'c':
                    parameters.C = double.Parse(args[num]);
                    break;

                case 'e':
                    parameters.EPS = double.Parse(args[num]);
                    break;

                case 'p':
                    parameters.P = double.Parse(args[num]);
                    break;

                case 'h':
                    parameters.Shrinking = (int.Parse(args[num]) == 1);
                    break;

                case 'b':
                    parameters.Probability = (int.Parse(args[num]) == 1);
                    break;

                case 'v':
                    crossValidation = true;
                    nrfold          = int.Parse(args[num]);
                    if (nrfold >= 2)
                    {
                        break;
                    }
                    throw new ArgumentException("n-fold cross validation: n must >= 2");

                case 'w':
                    parameters.Weights[int.Parse(args[num - 1].Substring(2))] = double.Parse(args[1]);
                    break;

                default:
                    throw new ArgumentException("Unknown Parameter");
                }
                num++;
            }
            if (num >= args.Length)
            {
                throw new ArgumentException("No input file specified");
            }
            problem = Problem.Read(args[num]);
            if (parameters.Gamma == 0.0)
            {
                parameters.Gamma = 1.0 / (double)problem.MaxIndex;
            }
            if (num < args.Length - 1)
            {
                modelFilename = args[num + 1];
            }
            else
            {
                int startIndex = args[num].LastIndexOf('/') + 1;
                modelFilename = args[num].Substring(startIndex) + ".model";
            }
        }