예제 #1
0
 /// <summary>
 /// this is a static duplicate of LoadModel. at some point i need to remove this duplicate..
 /// </summary>
 /// <param name="filename"></param>
 /// <returns></returns>
 public static bool loadModelStatic(string filename)
 {
     try
     {
         Preferences.Instance.modelLoaded = false;
         if (GuiPreferences.Instance.TrainType != TrainingType.CrossValidation)
         {
             libSVM _svm = libSVM.Load("ori.svm");
             if (_svm != null)
             {
                 Preferences.Instance.modelLoaded = true;
                 GuiPreferences.Instance.setLog("new loaded model overwritten the old model if there was any");
                 Preferences.Instance.svmModel = _svm;
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             GuiPreferences.Instance.setLog("cant load a model for cross validation (it has K models)");
             return(false);
         }
     }
     catch (Exception e)
     {
         GuiPreferences.Instance.setLog("loadModel: " + e.ToString());
         return(false);
     }
 }
예제 #2
0
파일: libSVM.cs 프로젝트: uaqeel/ZeusXL
        /// <summary>
        ///  Load model from file
        /// </summary>
        /// <param name="_filename">Model file</param>
        public static libSVM Load(string _filename)
        {
            libSVM svm = new libSVM();

            svm.Reload(_filename);

            return(svm);
        }
예제 #3
0
        /// <summary>
        /// wrapper function for GetAccuracy, the name was not logical and i have to maintain a subversion pristine copy.
        /// </summary>
        /// <param name="problem">problem</param>
        /// <returns>accuracy in %</returns>
        ///
        public double GetAccuracyFromTestSingleSample(libSVM_Problem problem, libSVM svmModel)
        {
            if (problem.samples == null || problem.samples.Length == 0)
            {
                throw new Exception("GetAccuracy no samples");
            }
            if (problem.labels == null || problem.labels.Length == 0)
            {
                throw new Exception("GetAccuracy no labels");
            }

            if (problem.samples.Length != problem.labels.Length)
            {
                throw new Exception("GetAccuracy labels.length!=samples.length");
            }

            output = new libSVM_output();

            int    correctPredictions = 0;
            double pred;

            int index = problem.samples.Length - 1;

            if (problem.samples[index] != null && problem.samples[index].Count > 0)
            {
                pred = svmModel.Predict(problem.samples[index]);
                return(pred);

                /*output.setValue(index, pred);
                 * if (pred == problem.labels[index])
                 *  correctPredictions++;*/
            }


            output.accuracy = correctPredictions / (double)problem.samples.Length * 100.0;
            return(1.0);
        }