예제 #1
0
        /// <summary>
        /// clears memmory for param_ptr
        /// </summary>
        /// <param name="sample_node_ptr"></param>
        private void Free_svm_parameter_ptr(ref IntPtr parameter_ptr)
        {
            svm_parameter parameter = (svm_parameter)Marshal.PtrToStructure(parameter_ptr, typeof(svm_parameter));

            Free_ptr(ref parameter.weight);
            Free_ptr(ref parameter.weight_label);

            Free_ptr(ref parameter_ptr);
        }
예제 #2
0
        private IntPtr libSVM_Parameter_to_svm_parameter_ptr(libSVM_Parameter _parameter)
        {
            if (_parameter == null)
            {
                throw new Exception("libSVMParameter not initialized");
            }
            if (_parameter.weight == null && _parameter.weight_label != null)
            {
                throw new Exception("libSVMParameter.weight = null and libSVMParameter.weight_label != null");
            }
            if (_parameter.weight != null && _parameter.weight_label == null)
            {
                throw new Exception("libSVMParameter.weight_label = null and libSVMParameter.weight != null");
            }
            if (_parameter.weight != null && _parameter.weight_label != null && _parameter.weight_label.Length != _parameter.weight.Length)
            {
                throw new Exception("libSVMParameter.weight_label.Length != libSVMParameter.weight.Length");
            }

            svm_parameter parameter = new svm_parameter();

            parameter.C            = _parameter.C;
            parameter.cache_size   = _parameter.cache_size;
            parameter.coef0        = _parameter.coef0;
            parameter.degree       = _parameter.degree;
            parameter.eps          = _parameter.eps;
            parameter.gamma        = _parameter.gamma;
            parameter.kernel_type  = (int)_parameter.kernel_type;
            parameter.nr_weight    = _parameter.weight.Length;
            parameter.nu           = _parameter.nu;
            parameter.p            = _parameter.p;
            parameter.probability  = _parameter.probability;
            parameter.shrinking    = _parameter.shrinking;
            parameter.svm_type     = (int)_parameter.svm_type;
            parameter.weight       = array_to_ptr(_parameter.weight);
            parameter.weight_label = array_to_ptr(_parameter.weight_label);

            IntPtr parameter_ptr = Alloc_ptr(Marshal.SizeOf(typeof(svm_parameter)));

            Marshal.StructureToPtr(parameter, parameter_ptr, false);

            return(parameter_ptr);
        }