Example #1
0
        /// <summary>
        /// SVM パラメータのためのグリッドを生成する
        /// </summary>
        /// <param name="paramId"></param>
        /// <returns></returns>
#else
        /// <summary>
        /// Generates a grid for SVM parameters
        /// </summary>
        /// <param name="paramId"></param>
        /// <returns></returns>
#endif
        public static CvParamGrid GetDefaultGrid(SVMParamType paramId)
        {
            var grid = new CvParamGrid();

            NativeMethods.ml_CvSVM_get_default_grid(ref grid, (int)paramId);
            return(grid);
        }
Example #2
0
        /// <summary>
        /// SVMを最適なパラメータで学習する
        /// </summary>
        /// <param name="trainData"></param>
        /// <param name="responses"></param>
        /// <param name="varIdx"></param>
        /// <param name="sampleIdx"></param>
        /// <param name="param"></param>
        /// <param name="kFold">交差検定(Cross-validation)パラメータ.学習集合は,k_foldの部分集合に分割され,一つの部分集合がモデルの学習に用いられ,その他の部分集合はテスト集合となる.つまり,SVM アルゴリズムは,k_fold回実行される.</param>
        /// <param name="cGrid"></param>
        /// <param name="gammaGrid"></param>
        /// <param name="pGrid"></param>
        /// <param name="nuGrid"></param>
        /// <param name="coefGrid"></param>
        /// <param name="degreeGrid"></param>
        /// <param name="balanced"></param>
        /// <returns></returns>
#else
        /// <summary>
        /// Trains SVM with optimal parameters
        /// </summary>
        /// <param name="trainData"></param>
        /// <param name="responses"></param>
        /// <param name="varIdx"></param>
        /// <param name="sampleIdx"></param>
        /// <param name="param"></param>
        /// <param name="kFold">Cross-validation parameter. The training set is divided into k_fold subsets, one subset being used to train the model, the others forming the test set. So, the SVM algorithm is executed k_fold times. </param>
        /// <param name="cGrid"></param>
        /// <param name="gammaGrid"></param>
        /// <param name="pGrid"></param>
        /// <param name="nuGrid"></param>
        /// <param name="coefGrid"></param>
        /// <param name="degreeGrid"></param>
        /// <param name="balanced"></param>
        /// <returns></returns>
#endif
        public virtual bool TrainAuto(
            Mat trainData,
            Mat responses,
            Mat varIdx,
            Mat sampleIdx,
            CvSVMParams param,
            int kFold = 10,
            CvParamGrid? cGrid = null,
            CvParamGrid? gammaGrid = null,
            CvParamGrid? pGrid = null,
            CvParamGrid? nuGrid = null,
            CvParamGrid? coefGrid = null,
            CvParamGrid? degreeGrid = null,
            bool balanced = false)
        {
            if (trainData == null)
                throw new ArgumentNullException("trainData");
            if (responses == null)
                throw new ArgumentNullException("responses");
            if (varIdx == null)
                throw new ArgumentNullException("varIdx");
            if (sampleIdx == null)
                throw new ArgumentNullException("sampleIdx");
            trainData.ThrowIfDisposed();
            responses.ThrowIfDisposed();
            varIdx.ThrowIfDisposed();
            sampleIdx.ThrowIfDisposed();

            if (param == null)
                param = new CvSVMParams();
            var defaultGrid = GetDefaultGrid(SVMParamType.C);
            var cGrid0 = cGrid.GetValueOrDefault(defaultGrid);
            var gammaGrid0 = gammaGrid.GetValueOrDefault(defaultGrid);
            var pGrid0 = pGrid.GetValueOrDefault(defaultGrid);
            var nuGrid0 = nuGrid.GetValueOrDefault(defaultGrid);
            var coefGrid0 = coefGrid.GetValueOrDefault(defaultGrid);
            var degreeGrid0 = degreeGrid.GetValueOrDefault(defaultGrid);

            return NativeMethods.ml_CvSVM_train_auto_CvMat(
                ptr,
                trainData.CvPtr,
                responses.CvPtr,
                varIdx.CvPtr,
                sampleIdx.CvPtr,
                param.NativeStruct,
                kFold,
                cGrid0,
                gammaGrid0,
                pGrid0,
                nuGrid0,
                coefGrid0,
                degreeGrid0,
                balanced ? 1 : 0) != 0;
        }
Example #3
0
 public static extern int ml_CvSVM_train_auto_Mat(
     IntPtr model, IntPtr trainData, IntPtr responses, IntPtr varIdx,
     IntPtr sampleIdx, WCvSVMParams param, int kFold, CvParamGrid cGrid,
     CvParamGrid gammaGrid, CvParamGrid pGrid, CvParamGrid nuGrid,
     CvParamGrid coefGrid, CvParamGrid degreeGrid, int balanced);
Example #4
0
        /// <summary>
	    /// SVM パラメータのためのグリッドを生成する
	    /// </summary>
        /// <param name="paramId"></param>
	    /// <returns></returns>
#else
		/// <summary>
	    /// Generates a grid for SVM parameters
	    /// </summary>
	    /// <param name="paramId"></param>
	    /// <returns></returns>
#endif
	    public static CvParamGrid GetDefaultGrid(SVMParamType paramId)
	    {
            var grid = new CvParamGrid();
			NativeMethods.ml_CvSVM_get_default_grid(ref grid, (int)paramId);
            return grid;
	    }
Example #5
0
 public static extern int ml_CvParamGrid_check(CvParamGrid grid);
Example #6
0
 public static extern void ml_CvSVM_get_default_grid(
     ref CvParamGrid grid, int paramId);
 public static extern int ml_CvSVM_train_auto_Mat(
     IntPtr model, IntPtr trainData, IntPtr responses, IntPtr varIdx,
     IntPtr sampleIdx, WCvSVMParams param, int kFold, CvParamGrid cGrid,
     CvParamGrid gammaGrid, CvParamGrid pGrid, CvParamGrid nuGrid,
     CvParamGrid coefGrid, CvParamGrid degreeGrid, int balanced);
 public static extern int ml_CvParamGrid_check(CvParamGrid grid);
 public static extern void ml_CvSVM_get_default_grid(
     ref CvParamGrid grid, int paramId);