亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
国内精品伊人久久久久av影院| 99re6这里只有精品视频在线观看| 亚洲最快最全在线视频| 国产欧美视频一区二区| 日韩一级大片在线| 91精品国产色综合久久ai换脸| 91成人看片片| 91久久线看在观草草青青| 99国产精品一区| 色综合天天做天天爱| 99热在这里有精品免费| 成人福利在线看| 99久久婷婷国产| 91丨九色丨蝌蚪富婆spa| 91女人视频在线观看| 一本在线高清不卡dvd| 日本道精品一区二区三区| 欧美三级在线视频| 欧美精品久久天天躁| 亚洲与欧洲av电影| 亚洲国产欧美另类丝袜| 五月天激情综合网| 精品影院一区二区久久久| 国内精品伊人久久久久av一坑| 国产一区欧美二区| 懂色av一区二区三区蜜臀| 成人精品免费网站| 91精品1区2区| 欧美电影在线免费观看| 欧美大白屁股肥臀xxxxxx| 久久久久久久久久久久久女国产乱| 久久精品视频免费| 亚洲男人的天堂在线aⅴ视频| 一区二区三区电影在线播| 婷婷夜色潮精品综合在线| 久久99精品一区二区三区三区| 国产一区不卡在线| a在线欧美一区| 欧美日韩免费高清一区色橹橹| 欧美一级免费观看| 欧美国产日本韩| 亚洲综合色丁香婷婷六月图片| 日日噜噜夜夜狠狠视频欧美人| 国产在线视频精品一区| 99这里只有久久精品视频| 欧洲一区二区三区免费视频| 日韩一级免费一区| 国产精品毛片a∨一区二区三区| 亚洲精品中文在线观看| 青青草97国产精品免费观看无弹窗版| 国产一区二区三区在线观看免费| 99久久婷婷国产综合精品电影 | 91免费看片在线观看| 亚洲影视在线播放| 日韩影院免费视频| 国产69精品久久久久毛片| 在线观看av一区| 久久蜜桃av一区精品变态类天堂| 亚洲少妇屁股交4| 蜜桃av一区二区在线观看| av电影天堂一区二区在线观看| 91精品久久久久久蜜臀| 中文字幕一区二区三区不卡| 日韩成人免费电影| 91一区二区在线| 精品国产乱码久久久久久1区2区 | 亚洲成人在线免费| 成人在线视频一区二区| 91麻豆精品国产自产在线观看一区| 国产精品视频免费看| 日韩不卡手机在线v区| 97久久人人超碰| 精品国产99国产精品| 亚洲图片欧美一区| 不卡一区二区在线| 久久综合精品国产一区二区三区 | 奇米影视在线99精品| 91亚洲午夜精品久久久久久| 欧美精品一区二区精品网| 午夜伦欧美伦电影理论片| 99精品久久99久久久久| 久久伊人中文字幕| 日韩成人精品在线观看| 色狠狠色噜噜噜综合网| 国产精品欧美一级免费| 久久精品国产亚洲一区二区三区| 在线观看免费亚洲| 中文字幕一区二区三区在线播放| 日韩精品一区二区在线观看| 亚洲午夜免费视频| 91猫先生在线| 日韩美女视频一区二区| 国产成人av电影免费在线观看| 日韩欧美www| 日韩经典一区二区| 欧美日韩视频在线第一区 | 国产偷国产偷亚洲高清人白洁| 日韩中文字幕亚洲一区二区va在线 | 成人黄色软件下载| 久久精品男人的天堂| 久久91精品久久久久久秒播| 欧美剧情片在线观看| 亚洲国产乱码最新视频 | 欧美变态tickling挠脚心| 视频一区视频二区中文| 欧美猛男男办公室激情| 亚洲一区二区在线免费看| 96av麻豆蜜桃一区二区| 国产精品久久久久9999吃药| 国产成人精品免费网站| 久久久精品2019中文字幕之3| 久久国产麻豆精品| 日韩精品一区二区三区三区免费| 欧美96一区二区免费视频| 欧美日韩极品在线观看一区| 亚洲国产日韩在线一区模特| 欧美三片在线视频观看| 亚洲成人自拍网| 在线成人免费视频| 日本欧美久久久久免费播放网| 日韩一级黄色大片| 国产一区二区三区精品欧美日韩一区二区三区| 欧美刺激午夜性久久久久久久 | 欧美人伦禁忌dvd放荡欲情| 亚洲va天堂va国产va久| 欧美嫩在线观看| 久久成人免费日本黄色| 久久精品一区二区三区av| 精品国产乱码91久久久久久网站| 青椒成人免费视频| 久久综合久久综合亚洲| 大白屁股一区二区视频| 亚洲女厕所小便bbb| 欧美精品一级二级三级| 麻豆成人av在线| 久久久高清一区二区三区| 丁香激情综合国产| 一片黄亚洲嫩模| 欧美一区二区在线免费播放| 国产美女娇喘av呻吟久久| 国产精品麻豆网站| 欧美日韩成人综合在线一区二区| 久久99精品一区二区三区三区| 国产精品久久久久久久裸模| 欧美专区亚洲专区| 麻豆免费精品视频| 综合亚洲深深色噜噜狠狠网站| 欧美日韩国产成人在线免费| 国模娜娜一区二区三区| 1区2区3区欧美| 日韩一区二区电影| 成人国产精品免费观看视频| 午夜精品成人在线视频| 国产三级一区二区| 欧美视频在线不卡| 国产精品一区二区三区网站| 一区二区三区视频在线看| 日韩免费看的电影| 一本色道综合亚洲| 久久国产福利国产秒拍| 中文字幕一区二区不卡| 717成人午夜免费福利电影| 高清不卡一区二区| 日韩激情在线观看| 亚洲欧美日韩国产另类专区| 麻豆精品一区二区av白丝在线| 国产精品五月天| 欧美一区二区三区喷汁尤物| 99国产精品久久久久| 老色鬼精品视频在线观看播放| 亚洲欧美一区二区不卡| 精品成人免费观看| 欧美日韩一区二区三区四区五区 | 久久免费精品国产久精品久久久久| 91麻豆精品在线观看| 国内精品不卡在线| 午夜影视日本亚洲欧洲精品| 国产精品亲子乱子伦xxxx裸| 日韩一级高清毛片| 欧美日韩五月天| 色999日韩国产欧美一区二区| 国产自产高清不卡| 视频在线在亚洲| 亚洲精品中文字幕乱码三区| 亚洲国产精品传媒在线观看| 91精品久久久久久久久99蜜臂| 色成人在线视频| 成人综合在线观看| 国内精品嫩模私拍在线| 蜜桃一区二区三区在线观看| 亚洲午夜精品在线| 亚洲欧洲日产国码二区| 国产日韩欧美高清在线| 精品播放一区二区| 91精品国产91久久综合桃花| 欧美亚洲综合色| 在线欧美小视频| 91亚洲精品一区二区乱码| 白白色 亚洲乱淫| 国产成a人无v码亚洲福利|