• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# LIBSVM.svm_parameter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Encog.MathUtil.LIBSVM.svm_parameter的典型用法代码示例。如果您正苦于以下问题:C# svm_parameter类的具体用法?C# svm_parameter怎么用?C# svm_parameter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



svm_parameter类属于Encog.MathUtil.LIBSVM命名空间,在下文中一共展示了svm_parameter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: xa68541a68dd6f460

 internal xa68541a68dd6f460(svm_problem prob, svm_parameter param, sbyte[] y_)
     : base(prob.l, prob.x, param)
 {
     this.x1e218ceaee1bb583 = new sbyte[y_.Length];
     y_.CopyTo(this.x1e218ceaee1bb583, 0);
     this.x1f31bf6ca58166a1 = new xb730a77005d16cc1(prob.l, (int) (param.cache_size * 1048576.0));
 }
开发者ID:neismit,项目名称:emds,代码行数:7,代码来源:xa68541a68dd6f460.cs


示例2: xfbfe48e5ee40f893

 internal xfbfe48e5ee40f893(svm_problem prob, svm_parameter param)
     : base(prob.l, prob.x, param)
 {
     int num;
     int num2;
     if (((uint) num) > uint.MaxValue)
     {
         goto Label_005C;
     }
     this.x9fc3ee03a439f6f0 = prob.l;
     if ((((uint) num) - ((uint) num2)) > uint.MaxValue)
     {
         if ((((uint) num2) + ((uint) num)) > uint.MaxValue)
         {
             goto Label_0115;
         }
     }
     else
     {
         goto Label_0115;
     }
     Label_0024:
     this.x5cafa8d49ea71ea1[num2] = new float[2 * this.x9fc3ee03a439f6f0];
     num2++;
     Label_003D:
     if (num2 < 2)
     {
         goto Label_0024;
     }
     this.xafb0a999075e2e6a = 0;
     if (0 == 0)
     {
         return;
     }
     goto Label_00C0;
     Label_005C:
     num2 = 0;
     goto Label_003D;
     Label_00C0:
     this.xc0c4c459c6ccbd00 = new int[2 * this.x9fc3ee03a439f6f0];
     for (num = 0; num < this.x9fc3ee03a439f6f0; num++)
     {
         this.x32dce50116aa0f1e[num] = 1;
         this.x32dce50116aa0f1e[num + this.x9fc3ee03a439f6f0] = -1;
         this.xc0c4c459c6ccbd00[num] = num;
         this.xc0c4c459c6ccbd00[num + this.x9fc3ee03a439f6f0] = num;
     }
     this.x5cafa8d49ea71ea1 = new float[2][];
     goto Label_005C;
     Label_0115:
     this.x1f31bf6ca58166a1 = new xb730a77005d16cc1(this.x9fc3ee03a439f6f0, (int) (param.cache_size * 1048576.0));
     this.x32dce50116aa0f1e = new sbyte[2 * this.x9fc3ee03a439f6f0];
     goto Label_00C0;
 }
开发者ID:neismit,项目名称:emds,代码行数:54,代码来源:xfbfe48e5ee40f893.cs


示例3: xf094e3229d63c9be

 internal xf094e3229d63c9be(int l, svm_node[][] x_, svm_parameter param)
 {
     int num;
     Label_00C5:
     this.xbcd9612004129925 = param.kernel_type;
     Label_0075:
     if ((((uint) num) | 0x80000000) != 0)
     {
         this.x83735b10b6a3d76d = param.degree;
         do
         {
             this.xc7c4e9c099884228 = param.gamma;
             this.x987b3666f8a37f90 = param.coef0;
             if (0xff != 0)
             {
                 this.x08db3aeabb253cb1 = (svm_node[][]) x_.Clone();
                 if (this.xbcd9612004129925 != 2)
                 {
                     this.x4f9e236643454e9f = null;
                     if (0 == 0)
                     {
                         if (0 == 0)
                         {
                             return;
                         }
                         goto Label_00C5;
                     }
                     goto Label_0075;
                 }
                 this.x4f9e236643454e9f = new double[l];
             }
         }
         while (2 == 0);
     }
     for (num = 0; num < l; num++)
     {
         this.x4f9e236643454e9f[num] = x99240096a9e3842c(this.x08db3aeabb253cb1[num], this.x08db3aeabb253cb1[num]);
     }
 }
开发者ID:neismit,项目名称:emds,代码行数:39,代码来源:xf094e3229d63c9be.cs


示例4: svm_check_parameter

        public static String svm_check_parameter(svm_problem prob, svm_parameter param)
        {
            // svm_type

            int svm_type = param.svm_type;
            if (svm_type != svm_parameter.C_SVC && svm_type != svm_parameter.NU_SVC &&
                svm_type != svm_parameter.ONE_CLASS && svm_type != svm_parameter.EPSILON_SVR &&
                svm_type != svm_parameter.NU_SVR)
                return "unknown svm type";

            // kernel_type

            int kernel_type = param.kernel_type;
            if (kernel_type != svm_parameter.LINEAR && kernel_type != svm_parameter.POLY &&
                kernel_type != svm_parameter.RBF && kernel_type != svm_parameter.SIGMOID)
                return "unknown kernel type";

            // cache_size,eps,C,nu,p,shrinking

            if (param.cache_size <= 0)
                return "cache_size <= 0";

            if (param.eps <= 0)
                return "eps <= 0";

            if (svm_type == svm_parameter.C_SVC || svm_type == svm_parameter.EPSILON_SVR ||
                svm_type == svm_parameter.NU_SVR)
                if (param.C <= 0)
                    return "C <= 0";

            if (svm_type == svm_parameter.NU_SVC || svm_type == svm_parameter.ONE_CLASS ||
                svm_type == svm_parameter.NU_SVR)
                if (param.nu < 0 || param.nu > 1)
                    return "nu < 0 or nu > 1";

            if (svm_type == svm_parameter.EPSILON_SVR)
                if (param.p < 0)
                    return "p < 0";

            if (param.shrinking != 0 && param.shrinking != 1)
                return "shrinking != 0 and shrinking != 1";

            if (param.probability != 0 && param.probability != 1)
                return "probability != 0 and probability != 1";

            if (param.probability == 1 && svm_type == svm_parameter.ONE_CLASS)
                return "one-class SVM probability output not supported yet";

            // check whether nu-svc is feasible

            if (svm_type == svm_parameter.NU_SVC)
            {
                int l = prob.l;
                int max_nr_class = 16;
                int nr_class = 0;
                var label = new int[max_nr_class];
                var count = new int[max_nr_class];

                int i;
                for (i = 0; i < l; i++)
                {
                    //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042_3"'
                    var this_label = (int) prob.y[i];
                    int j;
                    for (j = 0; j < nr_class; j++)
                        if (this_label == label[j])
                        {
                            ++count[j];
                            break;
                        }

                    if (j == nr_class)
                    {
                        if (nr_class == max_nr_class)
                        {
                            max_nr_class *= 2;
                            var new_data = new int[max_nr_class];
                            Array.Copy(label, 0, new_data, 0, label.Length);
                            label = new_data;

                            new_data = new int[max_nr_class];
                            Array.Copy(count, 0, new_data, 0, count.Length);
                            count = new_data;
                        }
                        label[nr_class] = this_label;
                        count[nr_class] = 1;
                        ++nr_class;
                    }
                }

                for (i = 0; i < nr_class; i++)
                {
                    int n1 = count[i];
                    for (int j = i + 1; j < nr_class; j++)
                    {
                        int n2 = count[j];
                        if (param.nu*(n1 + n2)/2 > Math.Min(n1, n2))
                            return "specified nu is infeasible";
                    }
                }
//.........这里部分代码省略.........
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:101,代码来源:svm.cs


示例5: svm_load_model

        public static svm_model svm_load_model(StringReader fp)
        {
            // read parameters

            var model = new svm_model();
            var param = new svm_parameter();
            model.param = param;
            model.rho = null;
            model.probA = null;
            model.probB = null;
            model.label = null;
            model.nSV = null;

            while (true)
            {
                String cmd = fp.ReadLine();
                String arg = cmd.Substring(cmd.IndexOf(' ') + 1);

                if (cmd.StartsWith("svm_type"))
                {
                    int i;
                    for (i = 0; i < svm_type_table.Length; i++)
                    {
                        if (arg.IndexOf(svm_type_table[i]) != -1)
                        {
                            param.svm_type = i;
                            break;
                        }
                    }
                    if (i == svm_type_table.Length)
                    {
                        Console.Error.Write("unknown svm type.\n");
                        return null;
                    }
                }
                else if (cmd.StartsWith("kernel_type"))
                {
                    int i;
                    for (i = 0; i < kernel_type_table.Length; i++)
                    {
                        if (arg.IndexOf(kernel_type_table[i]) != -1)
                        {
                            param.kernel_type = i;
                            break;
                        }
                    }
                    if (i == kernel_type_table.Length)
                    {
                        Console.Error.Write("unknown kernel function.\n");
                        return null;
                    }
                }
                else if (cmd.StartsWith("degree"))
                    param.degree = atof(arg);
                else if (cmd.StartsWith("gamma"))
                    param.gamma = atof(arg);
                else if (cmd.StartsWith("coef0"))
                    param.coef0 = atof(arg);
                else if (cmd.StartsWith("nr_class"))
                    model.nr_class = atoi(arg);
                else if (cmd.StartsWith("total_sv"))
                    model.l = atoi(arg);
                else if (cmd.StartsWith("rho"))
                {
                    int n = model.nr_class*(model.nr_class - 1)/2;
                    model.rho = new double[n];
                    var st = new SupportClass.Tokenizer(arg);
                    for (int i = 0; i < n; i++)
                        model.rho[i] = atof(st.NextToken());
                }
                else if (cmd.StartsWith("label"))
                {
                    int n = model.nr_class;
                    model.label = new int[n];
                    var st = new SupportClass.Tokenizer(arg);
                    for (int i = 0; i < n; i++)
                        model.label[i] = atoi(st.NextToken());
                }
                else if (cmd.StartsWith("probA"))
                {
                    int n = model.nr_class*(model.nr_class - 1)/2;
                    model.probA = new double[n];
                    var st = new SupportClass.Tokenizer(arg);
                    for (int i = 0; i < n; i++)
                        model.probA[i] = atof(st.NextToken());
                }
                else if (cmd.StartsWith("probB"))
                {
                    int n = model.nr_class*(model.nr_class - 1)/2;
                    model.probB = new double[n];
                    var st = new SupportClass.Tokenizer(arg);
                    for (int i = 0; i < n; i++)
                        model.probB[i] = atof(st.NextToken());
                }
                else if (cmd.StartsWith("nr_sv"))
                {
                    int n = model.nr_class;
                    model.nSV = new int[n];
                    var st = new SupportClass.Tokenizer(arg);
                    for (int i = 0; i < n; i++)
//.........这里部分代码省略.........
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:101,代码来源:svm.cs


示例6: svm_train

        //
        // Interface functions
        //
        public static svm_model svm_train(svm_problem prob, svm_parameter param)
        {
            var model = new svm_model();
            model.param = param;

            if (param.svm_type == svm_parameter.ONE_CLASS || param.svm_type == svm_parameter.EPSILON_SVR ||
                param.svm_type == svm_parameter.NU_SVR)
            {
                // regression or one-class-svm
                model.nr_class = 2;
                model.label = null;
                model.nSV = null;
                model.probA = null;
                model.probB = null;
                model.sv_coef = new double[1][];

                if (param.probability == 1 &&
                    (param.svm_type == svm_parameter.EPSILON_SVR || param.svm_type == svm_parameter.NU_SVR))
                {
                    model.probA = new double[1];
                    model.probA[0] = svm_svr_probability(prob, param);
                }

                decision_function f = svm_train_one(prob, param, 0, 0);
                model.rho = new double[1];
                model.rho[0] = f.rho;

                int nSV = 0;
                int i;
                for (i = 0; i < prob.l; i++)
                    if (Math.Abs(f.alpha[i]) > 0)
                        ++nSV;
                model.l = nSV;
                model.SV = new svm_node[nSV][];
                model.sv_coef[0] = new double[nSV];
                int j = 0;
                for (i = 0; i < prob.l; i++)
                    if (Math.Abs(f.alpha[i]) > 0)
                    {
                        model.SV[j] = prob.x[i];
                        model.sv_coef[0][j] = f.alpha[i];
                        ++j;
                    }
            }
            else
            {
                // classification
                // find out the number of classes
                int l = prob.l;
                int max_nr_class = 16;
                int nr_class = 0;
                var label = new int[max_nr_class];
                var count = new int[max_nr_class];
                var index = new int[l];

                int i;
                for (i = 0; i < l; i++)
                {
                    //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042_3"'
                    var this_label = (int) prob.y[i];
                    int j;
                    for (j = 0; j < nr_class; j++)
                        if (this_label == label[j])
                        {
                            ++count[j];
                            break;
                        }
                    index[i] = j;
                    if (j == nr_class)
                    {
                        if (nr_class == max_nr_class)
                        {
                            max_nr_class *= 2;
                            var new_data = new int[max_nr_class];
                            Array.Copy(label, 0, new_data, 0, label.Length);
                            label = new_data;

                            new_data = new int[max_nr_class];
                            Array.Copy(count, 0, new_data, 0, count.Length);
                            count = new_data;
                        }
                        label[nr_class] = this_label;
                        count[nr_class] = 1;
                        ++nr_class;
                    }
                }

                // group training data of the same class

                var start = new int[nr_class];
                start[0] = 0;
                for (i = 1; i < nr_class; i++)
                    start[i] = start[i - 1] + count[i - 1];

                var x = new svm_node[l][];

                for (i = 0; i < l; i++)
//.........这里部分代码省略.........
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:101,代码来源:svm.cs


示例7: svm_binary_svc_probability

        // Cross-validation decision values for probability estimates
        private static void svm_binary_svc_probability(svm_problem prob, svm_parameter param, double Cp, double Cn,
                                                       double[] probAB)
        {
            int i;
            int nr_fold = 5;
            var perm = new int[prob.l];
            var dec_values = new double[prob.l];

            // random shuffle
            for (i = 0; i < prob.l; i++)
                perm[i] = i;
            for (i = 0; i < prob.l; i++)
            {
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042_3"'
                int j = i + (int) (SupportClass.Random.NextDouble()*(prob.l - i));
                do
                {
                    int _ = perm[i];
                    perm[i] = perm[j];
                    perm[j] = _;
                } while (false);
            }
            for (i = 0; i < nr_fold; i++)
            {
                int begin = i*prob.l/nr_fold;
                int end = (i + 1)*prob.l/nr_fold;
                int j, k;
                var subprob = new svm_problem();

                subprob.l = prob.l - (end - begin);
                subprob.x = new svm_node[subprob.l][];
                subprob.y = new double[subprob.l];

                k = 0;
                for (j = 0; j < begin; j++)
                {
                    subprob.x[k] = prob.x[perm[j]];
                    subprob.y[k] = prob.y[perm[j]];
                    ++k;
                }
                for (j = end; j < prob.l; j++)
                {
                    subprob.x[k] = prob.x[perm[j]];
                    subprob.y[k] = prob.y[perm[j]];
                    ++k;
                }
                int p_count = 0, n_count = 0;
                for (j = 0; j < k; j++)
                    if (subprob.y[j] > 0)
                        p_count++;
                    else
                        n_count++;

                if (p_count == 0 && n_count == 0)
                    for (j = begin; j < end; j++)
                        dec_values[perm[j]] = 0;
                else if (p_count > 0 && n_count == 0)
                    for (j = begin; j < end; j++)
                        dec_values[perm[j]] = 1;
                else if (p_count == 0 && n_count > 0)
                    for (j = begin; j < end; j++)
                        dec_values[perm[j]] = - 1;
                else
                {
                    var subparam = (svm_parameter) param.Clone();
                    subparam.probability = 0;
                    subparam.C = 1.0;
                    subparam.nr_weight = 2;
                    subparam.weight_label = new int[2];
                    subparam.weight = new double[2];
                    subparam.weight_label[0] = + 1;
                    subparam.weight_label[1] = - 1;
                    subparam.weight[0] = Cp;
                    subparam.weight[1] = Cn;
                    svm_model submodel = svm_train(subprob, subparam);
                    for (j = begin; j < end; j++)
                    {
                        var dec_value = new double[1];
                        svm_predict_values(submodel, prob.x[perm[j]], dec_value);
                        dec_values[perm[j]] = dec_value[0];
                        // ensure +1 -1 order; reason not using CV subroutine
                        dec_values[perm[j]] *= submodel.label[0];
                    }
                }
            }
            sigmoid_train(prob.l, dec_values, prob.y, probAB);
        }
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:88,代码来源:svm.cs


示例8: solve_nu_svr

        private static void solve_nu_svr(svm_problem prob, svm_parameter param, double[] alpha, Solver.SolutionInfo si)
        {
            int l = prob.l;
            double C = param.C;
            var alpha2 = new double[2*l];
            var linear_term = new double[2*l];
            var y = new sbyte[2*l];
            int i;

            double sum = C*param.nu*l/2;
            for (i = 0; i < l; i++)
            {
                alpha2[i] = alpha2[i + l] = Math.Min(sum, C);
                sum -= alpha2[i];

                linear_term[i] = - prob.y[i];
                y[i] = 1;

                linear_term[i + l] = prob.y[i];
                y[i + l] = - 1;
            }

            var s = new Solver_NU();
            s.Solve(2*l, new SVR_Q(prob, param), linear_term, y, alpha2, C, C, param.eps, si, param.shrinking);

            Console.Out.Write("epsilon = " + (- si.r) + "\n");

            for (i = 0; i < l; i++)
                alpha[i] = alpha2[i] - alpha2[i + l];
        }
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:30,代码来源:svm.cs


示例9: solve_one_class

        private static void solve_one_class(svm_problem prob, svm_parameter param, double[] alpha,
                                            Solver.SolutionInfo si)
        {
            int l = prob.l;
            var zeros = new double[l];
            var ones = new sbyte[l];
            int i;

            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042_3"'
            var n = (int) (param.nu*prob.l); // # of alpha's at upper bound

            for (i = 0; i < n; i++)
                alpha[i] = 1;
            alpha[n] = param.nu*prob.l - n;
            for (i = n + 1; i < l; i++)
                alpha[i] = 0;

            for (i = 0; i < l; i++)
            {
                zeros[i] = 0;
                ones[i] = 1;
            }

            var s = new Solver();
            s.Solve(l, new ONE_CLASS_Q(prob, param), zeros, ones, alpha, 1.0, 1.0, param.eps, si, param.shrinking);
        }
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:26,代码来源:svm.cs


示例10: HandleModels

        /// <summary>
        /// Load the models. 
        /// </summary>
        /// <param name="xmlin">Where to read the models from.</param>
        /// <param name="network">Where the models are read into.</param>
        private void HandleModels(ReadXML xmlin, SVMNetwork network)
        {

            int index = 0;
            while (xmlin.ReadToTag())
            {
                if (xmlin.IsIt(SVMNetworkPersistor.TAG_MODEL, true))
                {
                    svm_parameter param = new svm_parameter();
                    svm_model model = new svm_model();
                    model.param = param;
                    network.Models[index] = model;
                    HandleModel(xmlin, network.Models[index]);
                    index++;
                }
                else if (xmlin.IsIt(SVMNetworkPersistor.TAG_MODELS, false))
                {
                    break;
                }
            }

        }
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:27,代码来源:SVMNetworkPersistor.cs


示例11: Evaluate

        /// <summary>
        /// Evaluate the error for the specified model.
        /// </summary>
        ///
        /// <param name="param">The params for the SVN.</param>
        /// <param name="prob">The problem to evaluate.</param>
        /// <param name="target">The output values from the SVN.</param>
        /// <returns>The calculated error.</returns>
        private static double Evaluate(svm_parameter param, svm_problem prob,
                                double[] target)
        {
            int totalCorrect = 0;

            var error = new ErrorCalculation();

            if ((param.svm_type == svm_parameter.EPSILON_SVR)
                || (param.svm_type == svm_parameter.NU_SVR))
            {
                for (int i = 0; i < prob.l; i++)
                {
                    double ideal = prob.y[i];
                    double actual = target[i];
                    error.UpdateError(actual, ideal);
                }
                return error.Calculate();
            }
            for (int i = 0; i < prob.l; i++)
            {
                if (target[i] == prob.y[i])
                {
                    ++totalCorrect;
                }
            }

            return Format.HundredPercent*totalCorrect/prob.l;
        }
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:36,代码来源:SVMTrain.cs


示例12: x308cb2f3483de2a6

 private static double x308cb2f3483de2a6(svm_parameter x0d173b5435b4d6ad, svm_problem xdee3898b83df48b4, double[] x11d58b056c032b03)
 {
     ErrorCalculation calculation;
     int num2;
     double num3;
     int num5;
     int num = 0;
     if (0 == 0)
     {
         if ((((uint) num3) & 0) != 0)
         {
             goto Label_0134;
         }
         goto Label_0108;
     }
     goto Label_008C;
     Label_0055:
     if (num2 >= xdee3898b83df48b4.l)
     {
         return calculation.Calculate();
     }
     Label_008C:
     num3 = xdee3898b83df48b4.y[num2];
     double actual = x11d58b056c032b03[num2];
     if (((uint) num3) < 0)
     {
         goto Label_0108;
     }
     calculation.UpdateError(actual, num3);
     num2++;
     if ((((uint) num3) - ((uint) num3)) >= 0)
     {
         goto Label_0055;
     }
     Label_00D4:
     if ((((uint) num5) & 0) == 0)
     {
         while (num5 < xdee3898b83df48b4.l)
         {
             while (x11d58b056c032b03[num5] == xdee3898b83df48b4.y[num5])
             {
                 num++;
                 if ((((uint) actual) + ((uint) actual)) <= uint.MaxValue)
                 {
                     break;
                 }
             }
             num5++;
         }
     }
     goto Label_0134;
     Label_0108:
     calculation = new ErrorCalculation();
     if (((x0d173b5435b4d6ad.svm_type != 3) && ((((uint) num5) | 3) != 0)) && (x0d173b5435b4d6ad.svm_type != 4))
     {
         num5 = 0;
         if ((((uint) num3) + ((uint) actual)) <= uint.MaxValue)
         {
             goto Label_00D4;
         }
         goto Label_008C;
     }
     num2 = 0;
     goto Label_0055;
     Label_0134:
     return ((100.0 * num) / ((double) xdee3898b83df48b4.l));
 }
开发者ID:neismit,项目名称:emds,代码行数:67,代码来源:SVMTrain.cs


示例13: SVMNetwork

        /// <summary>
        /// Construct a SVM network. 
        /// </summary>
        /// <param name="inputCount">The input count.</param>
        /// <param name="outputCount">The output count.</param>
        /// <param name="svmType">The type of SVM.</param>
        /// <param name="kernelType">The SVM kernal type.</param>
        public SVMNetwork(int inputCount, int outputCount, SVMType svmType,
                KernelType kernelType)
        {
            this.inputCount = inputCount;
            this.outputCount = outputCount;
            this.kernelType = kernelType;
            this.svmType = svmType;

            models = new svm_model[outputCount];
            parameters = new svm_parameter[outputCount];

            for (int i = 0; i < outputCount; i++)
            {
                parameters[i] = new svm_parameter();

                switch (svmType)
                {
                    case SVMType.SupportVectorClassification:
                        parameters[i].svm_type = svm_parameter.C_SVC;
                        break;
                    case SVMType.NewSupportVectorClassification:
                        parameters[i].svm_type = svm_parameter.NU_SVC;
                        break;
                    case SVMType.SupportVectorOneClass:
                        parameters[i].svm_type = svm_parameter.ONE_CLASS;
                        break;
                    case SVMType.EpsilonSupportVectorRegression:
                        parameters[i].svm_type = svm_parameter.EPSILON_SVR;
                        break;
                    case SVMType.NewSupportVectorRegression:
                        parameters[i].svm_type = svm_parameter.NU_SVR;
                        break;
                }

                switch (kernelType)
                {
                    case KernelType.Linear:
                        parameters[i].kernel_type = svm_parameter.LINEAR;
                        break;
                    case KernelType.Poly:
                        parameters[i].kernel_type = svm_parameter.POLY;
                        break;
                    case KernelType.RadialBasisFunction:
                        parameters[i].kernel_type = svm_parameter.RBF;
                        break;
                    case KernelType.Sigmoid:
                        parameters[i].kernel_type = svm_parameter.SIGMOID;
                        break;
                }

                parameters[i].kernel_type = svm_parameter.RBF;
                parameters[i].degree = 3;
                parameters[i].coef0 = 0;
                parameters[i].nu = 0.5;
                parameters[i].cache_size = 100;
                parameters[i].C = 1;
                parameters[i].eps = 1e-3;
                parameters[i].p = 0.1;
                parameters[i].shrinking = 1;
                parameters[i].probability = 0;
                parameters[i].nr_weight = 0;
                parameters[i].weight_label = new int[0];
                parameters[i].weight = new double[0];
                parameters[i].gamma = 1.0 / inputCount;
            }
        }
开发者ID:OperatorOverload,项目名称:encog-cs,代码行数:73,代码来源:SVMNetwork.cs


示例14: solve_c_svc

        //
        // construct and solve various formulations
        //
        private static void solve_c_svc(svm_problem prob, svm_parameter param, double[] alpha, Solver.SolutionInfo si,
                                        double Cp, double Cn)
        {
            int l = prob.l;
            var minus_ones = new double[l];
            var y = new sbyte[l];

            int i;

            for (i = 0; i < l; i++)
            {
                alpha[i] = 0;
                minus_ones[i] = - 1;
                if (prob.y[i] > 0)
                    y[i] = (+ 1);
                else
                    y[i] = - 1;
            }

            var s = new Solver();
            s.Solve(l, new SVC_Q(prob, param, y), minus_ones, y, alpha, Cp, Cn, param.eps, si, param.shrinking);

            double sum_alpha = 0;
            for (i = 0; i < l; i++)
                sum_alpha += alpha[i];

            if (Cp == Cn)
                Console.Out.Write("nu = " + sum_alpha/(Cp*prob.l) + "\n");

            for (i = 0; i < l; i++)
                alpha[i] *= y[i];
        }
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:35,代码来源:svm.cs


示例15: solve_nu_svc

        private static void solve_nu_svc(svm_problem prob, svm_parameter param, double[] alpha, Solver.SolutionInfo si)
        {
            int i;
            int l = prob.l;
            double nu = param.nu;

            var y = new sbyte[l];

            for (i = 0; i < l; i++)
                if (prob.y[i] > 0)
                    y[i] = (+ 1);
                else
                    y[i] = - 1;

            double sum_pos = nu*l/2;
            double sum_neg = nu*l/2;

            for (i = 0; i < l; i++)
                if (y[i] == + 1)
                {
                    alpha[i] = Math.Min(1.0, sum_pos);
                    sum_pos -= alpha[i];
                }
                else
                {
                    alpha[i] = Math.Min(1.0, sum_neg);
                    sum_neg -= alpha[i];
                }

            var zeros = new double[l];

            for (i = 0; i < l; i++)
                zeros[i] = 0;

            var s = new Solver_NU();
            s.Solve(l, new SVC_Q(prob, param, y), zeros, y, alpha, 1.0, 1.0, param.eps, si, param.shrinking);
            double r = si.r;

            Console.Out.Write("C = " + 1/r + "\n");

            for (i = 0; i < l; i++)
                alpha[i] *= y[i]/r;

            si.rho /= r;
            si.obj /= (r*r);
            si.upper_bound_p = 1/r;
            si.upper_bound_n = 1/r;
        }
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:48,代码来源:svm.cs


示例16: SupportVectorMachine

 /// <summary>
 /// Construct the SVM.
 /// </summary>
 ///
 public SupportVectorMachine()
 {
     _paras = new svm_parameter();
 }
开发者ID:firestrand,项目名称:encog-dotnet-core,代码行数:8,代码来源:SupportVectorMachine.cs


示例17: solve_epsilon_svr

        private static void solve_epsilon_svr(svm_problem prob, svm_parameter param, double[] alpha,
                                              Solver.SolutionInfo si)
        {
            int l = prob.l;
            var alpha2 = new double[2*l];
            var linear_term = new double[2*l];
            var y = new sbyte[2*l];
            int i;

            for (i = 0; i < l; i++)
            {
                alpha2[i] = 0;
                linear_term[i] = param.p - prob.y[i];
                y[i] = 1;

                alpha2[i + l] = 0;
                linear_term[i + l] = param.p + prob.y[i];
                y[i + l] = - 1;
            }

            var s = new Solver();
            s.Solve(2*l, new SVR_Q(prob, param), linear_term, y, alpha2, param.C, param.C, param.eps, si,
                    param.shrinking);

            double sum_alpha = 0;
            for (i = 0; i < l; i++)
            {
                alpha[i] = alpha2[i] - alpha2[i + l];
                sum_alpha += Math.Abs(alpha[i]);
            }
            Console.Out.Write("nu = " + sum_alpha/(param.C*l) + "\n");
        }
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:32,代码来源:svm.cs


示例18: svm_train_one

        internal static decision_function svm_train_one(svm_problem prob, svm_parameter param, double Cp, double Cn)
        {
            var alpha = new double[prob.l];
            var si = new Solver.SolutionInfo();
            switch (param.svm_type)
            {
                case svm_parameter.C_SVC:
                    solve_c_svc(prob, param, alpha, si, Cp, Cn);
                    break;

                case svm_parameter.NU_SVC:
                    solve_nu_svc(prob, param, alpha, si);
                    break;

                case svm_parameter.ONE_CLASS:
                    solve_one_class(prob, param, alpha, si);
                    break;

                case svm_parameter.EPSILON_SVR:
                    solve_epsilon_svr(prob, param, alpha, si);
                    break;

                case svm_parameter.NU_SVR:
                    solve_nu_svr(prob, param, alpha, si);
                    break;
            }

            Console.Out.Write("obj = " + si.obj + ", rho = " + si.rho + "\n");

            // output SVs

            int nSV = 0;
            int nBSV = 0;
            for (int i = 0; i < prob.l; i++)
            {
                if (Math.Abs(alpha[i]) > 0)
                {
                    ++nSV;
                    if (prob.y[i] > 0)
                    {
                        if (Math.Abs(alpha[i]) >= si.upper_bound_p)
                            ++nBSV;
                    }
                    else
                    {
                        if (Math.Abs(alpha[i]) >= si.upper_bound_n)
                            ++nBSV;
                    }
                }
            }

            Console.Out.Write("nSV = " + nSV + ", nBSV = " + nBSV + "\n");

            var f = new decision_function();
            f.alpha = alpha;
            f.rho = si.rho;
            return f;
        }
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:58,代码来源:svm.cs


示例19: svm_svr_probability

        // Return parameter of a Laplace distribution 
        private static double svm_svr_probability(svm_problem prob, svm_parameter param)
        {
            int i;
            int nr_fold = 5;
            var ymv = new double[prob.l];
            double mae = 0;

            var newparam = (svm_parameter) param.Clone();
            newparam.probability = 0;
            svm_cross_validation(prob, newparam, nr_fold, ymv);
            for (i = 0; i < prob.l; i++)
            {
                ymv[i] = prob.y[i] - ymv[i];
                mae += Math.Abs(ymv[i]);
            }
            mae /= prob.l;
            double std = Math.Sqrt(2*mae*mae);
            int count = 0;
            mae = 0;
            for (i = 0; i < prob.l; i++)
                if (Math.Abs(ymv[i]) > 5*std)
                    count = count + 1;
                else
                    mae += Math.Abs(ymv[i]);
            mae /= (prob.l - count);
            Console.Error.Write(
                "Prob. model for test data: target value = predicted value + z,\nz: Laplace distribution e^(-|z|/sigma)/(2sigma),sigma=" +
                mae + "\n");
            return mae;
        }
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:31,代码来源:svm.cs


示例20: SVC_Q

 internal SVC_Q(svm_problem prob, svm_parameter param, sbyte[] y_) : base(prob.l, prob.x, param)
 {
     y = new sbyte[y_.Length];
     y_.CopyTo(y, 0);
     //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042_3"'
     cache = new Cache(prob.l, (int) (param.cache_size*(1 << 20)));
 }
开发者ID:encog,项目名称:encog-silverlight-core,代码行数:7,代码来源:svm.cs



注:本文中的Encog.MathUtil.LIBSVM.svm_parameter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# LIBSVM.svm_problem类代码示例发布时间:2022-05-24
下一篇:
C# Specific.BiPolarMLData类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap