亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? solver.cs

?? SVM的一個源程序
?? CS
?? 第 1 頁 / 共 5 頁
字號:
//Copyright (C) 2007 Matthew Johnson

//This program is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License along
//with this program; if not, write to the Free Software Foundation, Inc.,
//51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace SVM
{
    //
    // Kernel evaluation
    //
    // the static method k_function is for doing single kernel evaluation
    // the constructor of Kernel prepares to calculate the l*l kernel matrix
    // the member function get_Q is for getting one column from the Q Matrix
    //
    internal abstract class QMatrix
    {
        public abstract float[] get_Q(int column, int len);
        public abstract float[] get_QD();
        public abstract void swap_index(int i, int j);
    }

    internal abstract class Kernel : QMatrix
    {
        private Node[][] _x;
        private double[] _x_square;

        // Parameter
        private KernelType kernel_type;
        private int degree;
        private double gamma;
        private double coef0;

        public override void swap_index(int i, int j)
        {
            do { Node[] _ = _x[i]; _x[i] = _x[j]; _x[j] = _; } while (false);
            if (_x_square != null) do { double _ = _x_square[i]; _x_square[i] = _x_square[j]; _x_square[j] = _; } while (false);
        }

        private static double powi(double baseValue, int times)
        {
            double tmp = baseValue, ret = 1.0;

            for (int t = times; t > 0; t /= 2)
            {
                if (t % 2 == 1) ret *= tmp;
                tmp = tmp * tmp;
            }
            return ret;
        }

        private static double tanh(double x)
        {
            double e = Math.Exp(x);
            return 1.0 - 2.0 / (e * e + 1);
        }

        public double kernel_function(int i, int j)
        {
            switch (kernel_type)
            {
                case KernelType.LINEAR:
                    return dot(_x[i], _x[j]);
                case KernelType.POLY:
                    return powi(gamma * dot(_x[i], _x[j]) + coef0, degree);
                case KernelType.RBF:
                    return Math.Exp(-gamma * (_x_square[i] + _x_square[j] - 2 * dot(_x[i], _x[j])));
                case KernelType.SIGMOID:
                    return tanh(gamma * dot(_x[i], _x[j]) + coef0);
                case KernelType.PRECOMPUTED:
                    return _x[i][(int)(_x[j][0].Value)].Value;
                default:
                    return 0;
            }
        }

        public Kernel(int l, Node[][] x_, Parameter param)
        {
            this.kernel_type = param.KernelType;
            this.degree = param.Degree;
            this.gamma = param.Gamma;
            this.coef0 = param.Coefficient0;

            _x = (Node[][])x_.Clone();

            if (kernel_type == KernelType.RBF)
            {
                _x_square = new double[l];
                for (int i = 0; i < l; i++)
                    _x_square[i] = dot(_x[i], _x[i]);
            }
            else _x_square = null;
        }

        public static double dot(Node[] x, Node[] y)
        {
            double sum = 0;
            int xlen = x.Length;
            int ylen = y.Length;
            int i = 0;
            int j = 0;
            while (i < xlen && j < ylen)
            {
                if (x[i].Index == y[j].Index)
                    sum += x[i++].Value * y[j++].Value;
                else
                {
                    if (x[i].Index > y[j].Index)
                        ++j;
                    else
                        ++i;
                }
            }
            return sum;
        }

        public static double k_function(Node[] x, Node[] y, Parameter param)
        {
            switch (param.KernelType)
            {
                case KernelType.LINEAR:
                    return dot(x, y);
                case KernelType.POLY:
                    return powi(param.Gamma * dot(x, y) + param.Coefficient0, param.Degree);
                case KernelType.RBF:
                    {
                        double sum = 0;
                        int xlen = x.Length;
                        int ylen = y.Length;
                        int i = 0;
                        int j = 0;
                        while (i < xlen && j < ylen)
                        {
                            if (x[i].Index == y[j].Index)
                            {
                                double d = x[i++].Value - y[j++].Value;
                                sum += d * d;
                            }
                            else if (x[i].Index > y[j].Index)
                            {
                                sum += y[j].Value * y[j].Value;
                                ++j;
                            }
                            else
                            {
                                sum += x[i].Value * x[i].Value;
                                ++i;
                            }
                        }

                        while (i < xlen)
                        {
                            sum += x[i].Value * x[i].Value;
                            ++i;
                        }

                        while (j < ylen)
                        {
                            sum += y[j].Value * y[j].Value;
                            ++j;
                        }

                        return Math.Exp(-param.Gamma * sum);
                    }
                case KernelType.SIGMOID:
                    return tanh(param.Gamma * dot(x, y) + param.Coefficient0);
                case KernelType.PRECOMPUTED:
                    return x[(int)(y[0].Value)].Value;
                default:
                    return 0;
            }
        }
    }

    // An SMO algorithm in Fan et al., JMLR 6(2005), p. 1889--1918
    // Solves:
    //
    //	min 0.5(\alpha^T Q \alpha) + p^T \alpha
    //
    //		y^T \alpha = \delta
    //		y_i = +1 or -1
    //		0 <= alpha_i <= Cp for y_i = 1
    //		0 <= alpha_i <= Cn for y_i = -1
    //
    // Given:
    //
    //	Q, p, y, Cp, Cn, and an initial feasible point \alpha
    //	l is the size of vectors and matrices
    //	eps is the stopping tolerance
    //
    // solution will be put in \alpha, objective value will be put in obj
    //
    internal class Solver
    {
        protected int active_size;
        protected short[] y;
        protected double[] G;		// gradient of objective function
        protected const byte LOWER_BOUND = 0;
        protected const byte UPPER_BOUND = 1;
        protected const byte FREE = 2;
        protected byte[] alpha_status;	// LOWER_BOUND, UPPER_BOUND, FREE
        protected double[] alpha;
        protected QMatrix Q;
        protected float[] QD;
        protected double eps;
        protected double Cp, Cn;
        protected double[] p;
        protected int[] active_set;
        protected double[] G_bar;		// gradient, if we treat free variables as 0
        protected int l;
        protected bool unshrinked;	// XXX

        protected const double INF = double.PositiveInfinity;

        protected double get_C(int i)
        {
            return (y[i] > 0) ? Cp : Cn;
        }
        protected void update_alpha_status(int i)
        {
            if (alpha[i] >= get_C(i))
                alpha_status[i] = UPPER_BOUND;
            else if (alpha[i] <= 0)
                alpha_status[i] = LOWER_BOUND;
            else alpha_status[i] = FREE;
        }
        protected bool is_upper_bound(int i) { return alpha_status[i] == UPPER_BOUND; }
        protected bool is_lower_bound(int i) { return alpha_status[i] == LOWER_BOUND; }
        protected bool is_free(int i) { return alpha_status[i] == FREE; }

        // java: information about solution except alpha,
        // because we cannot return multiple values otherwise...
        internal class SolutionInfo
        {
            public double obj;
            public double rho;
            public double upper_bound_p;
            public double upper_bound_n;
            public double r;	// for Solver_NU
        }

        protected void swap_index(int i, int j)
        {
            Q.swap_index(i, j);
            do { short _ = y[i]; y[i] = y[j]; y[j] = _; } while (false);
            do { double _ = G[i]; G[i] = G[j]; G[j] = _; } while (false);
            do { byte _ = alpha_status[i]; alpha_status[i] = alpha_status[j]; alpha_status[j] = _; } while (false);
            do { double _ = alpha[i]; alpha[i] = alpha[j]; alpha[j] = _; } while (false);
            do { double _ = p[i]; p[i] = p[j]; p[j] = _; } while (false);
            do { int _ = active_set[i]; active_set[i] = active_set[j]; active_set[j] = _; } while (false);
            do { double _ = G_bar[i]; G_bar[i] = G_bar[j]; G_bar[j] = _; } while (false);
        }

        protected void reconstruct_gradient()
        {
            // reconstruct inactive elements of G from G_bar and free variables

            if (active_size == l) return;

            int i;
            for (i = active_size; i < l; i++)
                G[i] = G_bar[i] + p[i];

            for (i = 0; i < active_size; i++)
                if (is_free(i))
                {
                    float[] Q_i = Q.get_Q(i, l);
                    double alpha_i = alpha[i];
                    for (int j = active_size; j < l; j++)
                        G[j] += alpha_i * Q_i[j];
                }
        }

        public virtual void Solve(int l, QMatrix Q, double[] p_, short[] y_,
               double[] alpha_, double Cp, double Cn, double eps, SolutionInfo si, bool shrinking)
        {
            this.l = l;
            this.Q = Q;
            QD = Q.get_QD();
            p = (double[])p_.Clone();
            y = (short[])y_.Clone();
            alpha = (double[])alpha_.Clone();
            this.Cp = Cp;
            this.Cn = Cn;
            this.eps = eps;
            this.unshrinked = false;

            // initialize alpha_status
            {
                alpha_status = new byte[l];
                for (int i = 0; i < l; i++)
                    update_alpha_status(i);
            }

            // initialize active set (for shrinking)
            {
                active_set = new int[l];
                for (int i = 0; i < l; i++)
                    active_set[i] = i;
                active_size = l;
            }

            // initialize gradient
            {
                G = new double[l];
                G_bar = new double[l];
                int i;
                for (i = 0; i < l; i++)
                {
                    G[i] = p[i];
                    G_bar[i] = 0;
                }
                for (i = 0; i < l; i++)
                    if (!is_lower_bound(i))
                    {
                        float[] Q_i = Q.get_Q(i, l);
                        double alpha_i = alpha[i];
                        int j;
                        for (j = 0; j < l; j++)
                            G[j] += alpha_i * Q_i[j];
                        if (is_upper_bound(i))
                            for (j = 0; j < l; j++)
                                G_bar[j] += get_C(i) * Q_i[j];
                    }
            }

            // optimization step

            int iter = 0;
            int counter = Math.Min(l, 1000) + 1;
            int[] working_set = new int[2];

            while (true)
            {
                // show progress and do shrinking

                if (--counter == 0)
                {
                    counter = Math.Min(l, 1000);
                    if (shrinking) do_shrinking();
                    Debug.Write(".");
                }

                if (select_working_set(working_set) != 0)
                {
                    // reconstruct the whole gradient
                    reconstruct_gradient();
                    // reset active set size and check
                    active_size = l;
                    Debug.Write("*");
                    if (select_working_set(working_set) != 0)
                        break;
                    else
                        counter = 1;	// do shrinking next iteration
                }

                int i = working_set[0];
                int j = working_set[1];

                ++iter;

                // update alpha[i] and alpha[j], handle bounds carefully

                float[] Q_i = Q.get_Q(i, active_size);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
678五月天丁香亚洲综合网| 一本色道久久加勒比精品 | 成人aa视频在线观看| 最好看的中文字幕久久| 欧美性色黄大片| 国产一区二区三区四区五区入口| 久久这里只有精品首页| www.欧美精品一二区| 日韩高清在线不卡| 国产欧美日韩中文久久| 欧美日韩亚洲综合| 国产久卡久卡久卡久卡视频精品| 亚洲欧美在线视频| 日韩三区在线观看| 91蜜桃在线观看| 久久成人羞羞网站| 亚洲大尺度视频在线观看| 久久嫩草精品久久久久| 欧美日韩一区二区三区在线看| 国产在线一区二区综合免费视频| 一区二区三区四区亚洲| 精品国产乱码久久久久久浪潮| 在线欧美小视频| 丁香天五香天堂综合| 精品亚洲国产成人av制服丝袜| 亚洲精品中文字幕乱码三区| 精品国产精品网麻豆系列| 91成人免费网站| 成人晚上爱看视频| 精品一区二区免费在线观看| 亚洲成a人片在线观看中文| 国产精品久久影院| 欧美国产禁国产网站cc| 久久亚洲一区二区三区四区| 欧美精品免费视频| 欧美日韩国产乱码电影| 91女神在线视频| eeuss影院一区二区三区| 国产不卡高清在线观看视频| 国产呦精品一区二区三区网站| 日韩av高清在线观看| 亚洲综合999| 亚洲自拍偷拍网站| 337p粉嫩大胆色噜噜噜噜亚洲| 欧美一区二区三区日韩| 欧美一区二区三区日韩视频| 日韩欧美在线综合网| 日韩一级完整毛片| 日韩欧美在线影院| 2020日本不卡一区二区视频| 欧美日韩一区二区三区不卡| 欧美男人的天堂一二区| 欧美色男人天堂| 欧美精品xxxxbbbb| 欧美一二三区在线| 精品剧情v国产在线观看在线| 久久久久久久久久电影| 国产亚洲精品中文字幕| 亚洲视频免费看| 亚洲自拍与偷拍| 欧美a级理论片| 久久66热偷产精品| 国产一区不卡视频| 91丨porny丨在线| 欧美精品久久久久久久多人混战 | 欧美精品xxxxbbbb| 精品国产第一区二区三区观看体验| 久久综合国产精品| 亚洲永久精品大片| 久久精品国内一区二区三区| 国产成人av在线影院| 在线欧美日韩精品| 精品美女一区二区| 亚洲成a人片综合在线| 日韩精品久久理论片| 欧美久久久久久久久久| 欧美午夜电影在线播放| 精品国精品国产尤物美女| 国产精品视频第一区| 亚洲国产精品久久艾草纯爱| 国产超碰在线一区| 91久久香蕉国产日韩欧美9色| 在线观看视频一区二区欧美日韩| 精品国产乱码久久久久久夜甘婷婷| 亚洲欧洲韩国日本视频 | 日韩一级黄色片| 亚洲最色的网站| 成人福利视频网站| 久久视频一区二区| 亚洲成人免费影院| 91日韩一区二区三区| 久久影院午夜论| 一区二区三区日韩精品| 99久久婷婷国产| 国产三级欧美三级日产三级99| 日日夜夜精品视频免费| 欧美视频一区二区| 中文字幕日韩精品一区| 国产成人精品综合在线观看| 欧美不卡一区二区| 日本欧洲一区二区| 欧美日韩精品一区二区三区| 一区二区三区影院| 色又黄又爽网站www久久| 亚洲少妇屁股交4| 99精品久久99久久久久| 亚洲欧洲99久久| 97成人超碰视| 亚洲激情图片qvod| 欧美无乱码久久久免费午夜一区| 亚洲狠狠丁香婷婷综合久久久| 成人av电影在线网| 国产精品乱人伦| 97久久精品人人做人人爽| 中文字幕av不卡| 在线免费亚洲电影| 男男gaygay亚洲| 精品国产免费视频| 激情综合五月天| 中文在线一区二区| 91一区在线观看| 亚洲国产视频在线| 欧美大白屁股肥臀xxxxxx| 国产一区二三区| 亚洲视频在线一区二区| 精品视频一区二区三区免费| 天堂成人免费av电影一区| 精品国一区二区三区| 成人a免费在线看| 日韩在线一区二区三区| 久久久综合精品| 欧美在线看片a免费观看| 久久aⅴ国产欧美74aaa| 国产精品亲子乱子伦xxxx裸| 欧美性生活大片视频| 福利一区二区在线观看| 天天影视网天天综合色在线播放| 26uuu久久天堂性欧美| 色www精品视频在线观看| 久久不见久久见免费视频1| 最新国产成人在线观看| 日韩亚洲欧美高清| 日本韩国一区二区三区视频| 国产剧情av麻豆香蕉精品| 五月天欧美精品| 亚洲精品大片www| 国产婷婷一区二区| 日韩免费在线观看| 欧美专区亚洲专区| av不卡免费电影| 国产精品888| 黄色资源网久久资源365| 性做久久久久久免费观看欧美| 成人欧美一区二区三区1314| 日韩精品中午字幕| 久久aⅴ国产欧美74aaa| 亚洲第一精品在线| 亚洲欧洲精品一区二区三区不卡| 久久综合久久综合亚洲| 欧美日韩专区在线| 91亚洲男人天堂| 国产综合色在线| 极品少妇一区二区| 性久久久久久久久久久久| 综合网在线视频| 国产精品家庭影院| 中文字幕高清一区| 久久亚洲捆绑美女| 国产午夜久久久久| 久久亚洲私人国产精品va媚药| 日韩一区二区三区四区 | 怡红院av一区二区三区| 亚洲欧美一区二区视频| 久久精品人人做人人综合| 国产亚洲成aⅴ人片在线观看| 久久久蜜桃精品| 久久奇米777| 中文字幕在线观看不卡| 国产精品免费丝袜| 国产精品国模大尺度视频| 国产精品久久毛片a| 一色桃子久久精品亚洲| 亚洲图片另类小说| 天堂影院一区二区| 天堂av在线一区| 韩国欧美国产一区| 99re这里只有精品6| 色综合久久综合| 日本道精品一区二区三区| 成人在线视频首页| 91丨porny丨户外露出| 在线观看免费成人| 久久综合色8888| 国产精品不卡在线观看| 亚洲一卡二卡三卡四卡五卡| 日本中文字幕不卡| 国产成人av电影在线播放| 色天天综合久久久久综合片| 欧美一级在线视频| 欧美国产精品劲爆|