Ejemplo n.º 1
0
        public SVMModel readModelFile(string modelFile)
        {
            SVMModel mm = new SVMModel();
            string   posClassName;
            string   negClassName;

            double[] weight;
            double   b;

            string[] allLines          = File.ReadAllLines(modelFile);
            string[] posClassLineParts = allLines[0].Split(' ');
            posClassName = posClassLineParts[1];
            string[] negClassLineParts = allLines[1].Split(' ');
            negClassName = negClassLineParts[1];

            string[] wtstr = allLines[2].Split(' ');
            weight = new double[wtstr.Count()];
            for (int w = 0; w < wtstr.Count(); w++)
            {
                if (!string.IsNullOrWhiteSpace(wtstr[w]))
                {
                    weight[w] = double.Parse(wtstr[w]);
                }
            }

            string bstr = allLines[3];

            b = 0.0;
            if (!string.IsNullOrWhiteSpace(bstr))
            {
                b = double.Parse(bstr);
            }

            mm.b            = b;
            mm.weight       = weight;
            mm.posClassName = posClassName;
            mm.negClassName = negClassName;
            return(mm);
        }
Ejemplo n.º 2
0
        public string classifyUsingModel(List <feature> featurevalues, SVMModel sm)
        {
            double svmOut = weightDotProduct(sm.weight, featurevalues);

            return((svmOut - sm.b) > Double.Epsilon ? sm.posClassName : sm.negClassName);
        }