コード例 #1
0
ファイル: SVM.cs プロジェクト: oloopy/LibSVMsharp
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool CheckProbabilityModel(SVMModel model)
        {
            IntPtr ptr_model = SVMModel.Allocate(model);
            bool   success   = libsvm.svm_check_probability_model(ptr_model);

            SVMModel.Free(ptr_model);
            return(success);
        }
コード例 #2
0
ファイル: SVM.cs プロジェクト: oloopy/LibSVMsharp
        /// <summary>
        /// This function does classification or regression on a test vector x given a model.
        /// </summary>
        /// <param name="model">SVM model.</param>
        /// <param name="x">Test vector.</param>
        /// <returns>For a classification model, the predicted class for x is returned.
        /// For a regression model, the function value of x calculated using the model is returned.
        /// For an one-class model, +1 or -1 is returned.</returns>
        public static double Predict(SVMModel model, SVMNode[] x)
        {
            IntPtr ptr_model = SVMModel.Allocate(model);
            double result    = Predict(ptr_model, x);

            SVMModel.Free(ptr_model);
            return(result);
        }
コード例 #3
0
ファイル: SVM.cs プロジェクト: oloopy/LibSVMsharp
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="x"></param>
        /// <param name="estimations"></param>
        /// <returns></returns>
        public static double PredictProbability(SVMModel model, SVMNode[] x, out double[] estimations)
        {
            IntPtr ptr_model = SVMModel.Allocate(model);
            double result    = PredictProbability(ptr_model, x, out estimations);

            SVMModel.Free(ptr_model);
            return(result);
        }
コード例 #4
0
ファイル: SVM.cs プロジェクト: oloopy/LibSVMsharp
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="x"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public static double PredictValues(SVMModel model, SVMNode[] x, out double[] values)
        {
            IntPtr ptr_model = SVMModel.Allocate(model);
            double result    = PredictValues(ptr_model, x, out values);

            SVMModel.Free(ptr_model);
            return(result);
        }
コード例 #5
0
ファイル: SVM.cs プロジェクト: tome-beta/FaceJudge
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool CheckProbabilityModel(SVMModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            IntPtr ptr_model = SVMModel.Allocate(model);
            bool   success   = libsvm.svm_check_probability_model(ptr_model);

            SVMModel.Free(ptr_model);
            return(success);
        }
コード例 #6
0
ファイル: SVM.cs プロジェクト: ly774508966/KinectGamePlayer
        /// <summary>
        /// This function does classification or regression on a test vector x given a model.
        /// </summary>
        /// <param name="model">SVM model.</param>
        /// <param name="x">Test vector.</param>
        /// <returns>For a classification model, the predicted class for x is returned.
        /// For a regression model, the function value of x calculated using the model is returned.
        /// For an one-class model, +1 or -1 is returned.</returns>
        public static double Predict(SVMModel model, SVMNode[] x)
        {
            IntPtr         ptr_model = SVMModel.Allocate(model);
            List <SVMNode> nodes     = x.Select(a => a.Clone()).ToList();

            nodes.Add(new SVMNode(-1, 0));
            IntPtr ptr_nodes = SVMNode.Allocate(nodes.ToArray());

            double result = libsvm.svm_predict(ptr_model, ptr_nodes);

            SVMModel.Free(ptr_model);
            SVMNode.Free(ptr_nodes);

            return(result);
        }
コード例 #7
0
ファイル: SVM.cs プロジェクト: oloopy/LibSVMsharp
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static bool SaveModel(SVMModel model, string filename)
        {
            if (String.IsNullOrWhiteSpace(filename) || model == null)
            {
                return(false);
            }

            IntPtr ptr_model    = SVMModel.Allocate(model);
            IntPtr ptr_filename = Marshal.StringToHGlobalAnsi(filename);

            bool success = libsvm.svm_save_model(ptr_filename, ptr_model) == 0;

            Marshal.FreeHGlobal(ptr_filename);
            ptr_filename = IntPtr.Zero;

            return(success);
        }
コード例 #8
0
ファイル: SVM.cs プロジェクト: tome-beta/FaceJudge
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="x"></param>
        /// <param name="estimations"></param>
        /// <returns></returns>
        public static double PredictProbability(SVMModel model, SVMNode[] x, out double[] estimations)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            if (x == null)
            {
                throw new ArgumentNullException("x");
            }

            IntPtr ptr_model = SVMModel.Allocate(model);
            double result    = PredictProbability(ptr_model, x, out estimations);

            SVMModel.Free(ptr_model);
            return(result);
        }
コード例 #9
0
ファイル: SVM.cs プロジェクト: tome-beta/FaceJudge
        /// <summary>
        /// This function does classification or regression on a test vector x given a model.
        /// </summary>
        /// <param name="model">SVM model.</param>
        /// <param name="x">Test vector.</param>
        /// <returns>For a classification model, the predicted class for x is returned.
        /// For a regression model, the function value of x calculated using the model is returned.
        /// For an one-class model, +1 or -1 is returned.</returns>
        public static double Predict(SVMModel model, SVMNode[] x)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            if (x == null)
            {
                throw new ArgumentNullException("x");
            }

            IntPtr ptr_model = SVMModel.Allocate(model);
            double result    = Predict(ptr_model, x);

            SVMModel.Free(ptr_model);
            return(result);
        }
コード例 #10
0
ファイル: SVM.cs プロジェクト: ly774508966/KinectGamePlayer
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="x"></param>
        /// <param name="values"></param>
        /// <returns></returns>
        public static double PredictValues(SVMModel model, SVMNode[] x, out double[] values)
        {
            int            size       = (int)(model.ClassCount * (model.ClassCount - 1) * 0.5);
            IntPtr         ptr_values = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * size);
            IntPtr         ptr_model  = SVMModel.Allocate(model);
            List <SVMNode> nodes      = x.Select(a => a.Clone()).ToList();

            nodes.Add(new SVMNode(-1, 0));
            IntPtr ptr_nodes = SVMNode.Allocate(nodes.ToArray());

            double result = libsvm.svm_predict_values(ptr_model, ptr_nodes, ptr_values);

            values = new double[size];
            Marshal.Copy(ptr_values, values, 0, values.Length);

            SVMModel.Free(ptr_model);
            SVMNode.Free(ptr_nodes);
            Marshal.FreeHGlobal(ptr_values);
            ptr_values = IntPtr.Zero;

            return(result);
        }