コード例 #1
0
        public static IntPtr Allocate(SVMParameter x)
        {
            if (x == null)
                return IntPtr.Zero;

            svm_parameter y = new svm_parameter();
            y.svm_type = (int)x.Type;
            y.kernel_type = (int)x.Kernel;
            y.degree = x.Degree;
            y.gamma = x.Gamma;
            y.coef0 = x.Coef0;
            y.cache_size = x.CacheSize;
            y.eps = x.Eps;
            y.C = x.C;
            y.nu = x.Nu;
            y.p = x.P;
            y.shrinking = x.Shrinking ? 1 : 0;
            y.probability = x.Probability ? 1 : 0;
            y.nr_weight = x.WeightLabels.Length;

            y.weight_label = IntPtr.Zero;
            if (y.nr_weight > 0)
            {
                y.weight_label = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(int)) * x.WeightLabels.Length);
                Marshal.Copy(x.WeightLabels, 0, y.weight_label, x.WeightLabels.Length);
            }

            y.weight = IntPtr.Zero;
            if (y.nr_weight > 0)
            {
                y.weight = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * x.Weights.Length);
                Marshal.Copy(x.Weights, 0, y.weight, x.Weights.Length);
            }

            int size = Marshal.SizeOf(y);
            IntPtr ptr = Marshal.AllocHGlobal(size);
            Marshal.StructureToPtr(y, ptr, true);

            return ptr;
        }
コード例 #2
0
        public static void Free(svm_parameter x)
        {
            Marshal.FreeHGlobal(x.weight);
            x.weight = IntPtr.Zero;

            Marshal.FreeHGlobal(x.weight_label);
            x.weight_label = IntPtr.Zero;
        }
コード例 #3
0
        public static SVMParameter Convert(svm_parameter x)
        {
            SVMParameter y = new SVMParameter();
            y.Type = (SVMType)x.svm_type;
            y.Kernel = (SVMKernelType)x.kernel_type;
            y.Degree = x.degree;
            y.Gamma = x.gamma;
            y.Coef0 = x.coef0;
            y.CacheSize = x.cache_size;
            y.Eps = x.eps;
            y.C = x.C;
            y.Nu = x.nu;
            y.P = x.p;
            y.Shrinking = x.shrinking != 0;
            y.Probability = x.probability != 0;

            int length = x.nr_weight;
            y.WeightLabels = new int[length];
            if (length > 0)
                Marshal.Copy(x.weight_label, y.WeightLabels, 0, length);

            y.Weights = new double[length];
            if (length > 0)
                Marshal.Copy(x.weight, y.Weights, 0, length);

            return y;
        }