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

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

?? svm.java

?? 機器學習支持向量機的代碼libsvm 2.36版
?? JAVA
?? 第 1 頁 / 共 3 頁
字號:
package libsvm;import java.io.*;import java.util.*;//// Kernel Cache//// l is the number of total data items// size is the cache size limit in bytes//class Cache {	private final int l;	private int size;	private final class head_t	{		head_t prev, next;	// a cicular list		float[] data;		int len;		// data[0,len) is cached in this entry	}	private final head_t[] head;	private head_t lru_head;	Cache(int l_, int size_)	{		l = l_;		size = size_;		head = new head_t[l];		for(int i=0;i<l;i++) head[i] = new head_t();		size /= 4;		size -= l * (16/4);	// sizeof(head_t) == 16		lru_head = new head_t();		lru_head.next = lru_head.prev = lru_head;	}	private void lru_delete(head_t h)	{		// delete from current location		h.prev.next = h.next;		h.next.prev = h.prev;	}	private void lru_insert(head_t h)	{		// insert to last position		h.next = lru_head;		h.prev = lru_head.prev;		h.prev.next = h;		h.next.prev = h;	}	// request data [0,len)	// return some position p where [p,len) need to be filled	// (p >= len if nothing needs to be filled)	// java: simulate pointer using single-element array	int get_data(int index, float[][] data, int len)	{		head_t h = head[index];		if(h.len > 0) lru_delete(h);		int more = len - h.len;		if(more > 0)		{			// free old space			while(size < more)			{				head_t old = lru_head.next;				lru_delete(old);				size += old.len;				old.data = null;				old.len = 0;			}			// allocate new space			float[] new_data = new float[len];			if(h.data != null) System.arraycopy(h.data,0,new_data,0,h.len);			h.data = new_data;			size -= more;			do {int _=h.len; h.len=len; len=_;} while(false);		}		lru_insert(h);		data[0] = h.data;		return len;	}	void swap_index(int i, int j)	{		if(i==j) return;				if(head[i].len > 0) lru_delete(head[i]);		if(head[j].len > 0) lru_delete(head[j]);		do {float[] _=head[i].data; head[i].data=head[j].data; head[j].data=_;} while(false);		do {int _=head[i].len; head[i].len=head[j].len; head[j].len=_;} while(false);		if(head[i].len > 0) lru_insert(head[i]);		if(head[j].len > 0) lru_insert(head[j]);		if(i>j) do {int _=i; i=j; j=_;} while(false);		for(head_t h = lru_head.next; h!=lru_head; h=h.next)		{			if(h.len > i)			{				if(h.len > j)					do {float _=h.data[i]; h.data[i]=h.data[j]; h.data[j]=_;} while(false);				else				{					// give up					lru_delete(h);					size += h.len;					h.data = null;					h.len = 0;				}			}		}	}}//// 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//abstract class Kernel {	private svm_node[][] x;	private final double[] x_square;	// svm_parameter	private final int kernel_type;	private final double degree;	private final double gamma;	private final double coef0;	abstract float[] get_Q(int column, int len);	void swap_index(int i, int j)	{		do {svm_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 tanh(double x)	{		double e = Math.exp(x);		return 1.0-2.0/(e*e+1);	}	double kernel_function(int i, int j)	{		switch(kernel_type)		{			case svm_parameter.LINEAR:				return dot(x[i],x[j]);			case svm_parameter.POLY:				return Math.pow(gamma*dot(x[i],x[j])+coef0,degree);			case svm_parameter.RBF:				return Math.exp(-gamma*(x_square[i]+x_square[j]-2*dot(x[i],x[j])));			case svm_parameter.SIGMOID:				return tanh(gamma*dot(x[i],x[j])+coef0);			default:				return 0;	// java		}	}	Kernel(int l, svm_node[][] x_, svm_parameter param)	{		this.kernel_type = param.kernel_type;		this.degree = param.degree;		this.gamma = param.gamma;		this.coef0 = param.coef0;		x = (svm_node[][])x_.clone();		if(kernel_type == svm_parameter.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;	}	static double dot(svm_node[] x, svm_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;	}	static double k_function(svm_node[] x, svm_node[] y,					svm_parameter param)	{		switch(param.kernel_type)		{			case svm_parameter.LINEAR:				return dot(x,y);			case svm_parameter.POLY:				return Math.pow(param.gamma*dot(x,y)+param.coef0,param.degree);			case svm_parameter.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 svm_parameter.SIGMOID:				return tanh(param.gamma*dot(x,y)+param.coef0);			default:				return 0;	// java		}	}}// Generalized SMO+SVMlight algorithm// Solves:////	min 0.5(\alpha^T Q \alpha) + b^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, b, y, Cp, Cn, and an initial feasible point \alpha//	l is the size of vectors and matrices//	eps is the stopping criterion//// solution will be put in \alpha, objective value will be put in obj//class Solver {	int active_size;	byte[] y;	double[] G;		// gradient of objective function	static final byte LOWER_BOUND = 0;	static final byte UPPER_BOUND = 1;	static final byte FREE = 2;	byte[] alpha_status;	// LOWER_BOUND, UPPER_BOUND, FREE	double[] alpha;	Kernel Q;	double eps;	double Cp,Cn;	double[] b;	int[] active_set;	double[] G_bar;		// gradient, if we treat free variables as 0	int l;	boolean unshrinked;	// XXX		static final double INF = java.lang.Double.POSITIVE_INFINITY;	double get_C(int i)	{		return (y[i] > 0)? Cp : Cn;	}	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;	}	boolean is_upper_bound(int i) { return alpha_status[i] == UPPER_BOUND; }	boolean is_lower_bound(int i) { return alpha_status[i] == LOWER_BOUND; }	boolean is_free(int i) {  return alpha_status[i] == FREE; }	// java: information about solution except alpha,	// because we cannot return multiple values otherwise...	static class SolutionInfo {		double obj;		double rho;		double upper_bound_p;		double upper_bound_n;		double r;	// for Solver_NU	}	void swap_index(int i, int j)	{		Q.swap_index(i,j);		do {byte _=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 _=b[i]; b[i]=b[j]; b[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);	}	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] + b[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];			}	}	void Solve(int l, Kernel Q, double[] b_, byte[] y_,		   double[] alpha_, double Cp, double Cn, double eps, SolutionInfo si, int shrinking)	{		this.l = l;		this.Q = Q;		b = (double[])b_.clone();		y = (byte[])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] = b[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!=0) do_shrinking();				System.err.print(".");			}			if(select_working_set(working_set)!=0)			{				// reconstruct the whole gradient				reconstruct_gradient();				// reset active set size and check				active_size = l;				System.err.print("*");				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);			float[] Q_j = Q.get_Q(j,active_size);			double C_i = get_C(i);			double C_j = get_C(j);			double old_alpha_i = alpha[i];			double old_alpha_j = alpha[j];			if(y[i]!=y[j])			{				double delta = (-G[i]-G[j])/(Q_i[i]+Q_j[j]+2*Q_i[j]);				double diff = alpha[i] - alpha[j];				alpha[i] += delta;				alpha[j] += delta;							if(diff > 0)				{					if(alpha[j] < 0)					{						alpha[j] = 0;						alpha[i] = diff;					}				}				else				{					if(alpha[i] < 0)					{						alpha[i] = 0;						alpha[j] = -diff;					}				}				if(diff > C_i - C_j)				{					if(alpha[i] > C_i)					{						alpha[i] = C_i;						alpha[j] = C_i - diff;					}				}				else				{					if(alpha[j] > C_j)					{						alpha[j] = C_j;						alpha[i] = C_j + diff;					}				}			}			else			{				double delta = (G[i]-G[j])/(Q_i[i]+Q_j[j]-2*Q_i[j]);				double sum = alpha[i] + alpha[j];				alpha[i] -= delta;				alpha[j] += delta;				if(sum > C_i)				{					if(alpha[i] > C_i)					{						alpha[i] = C_i;						alpha[j] = sum - C_i;					}				}				else				{					if(alpha[j] < 0)					{						alpha[j] = 0;						alpha[i] = sum;					}				}				if(sum > C_j)				{					if(alpha[j] > C_j)					{						alpha[j] = C_j;						alpha[i] = sum - C_j;					}				}				else				{					if(alpha[i] < 0)					{						alpha[i] = 0;						alpha[j] = sum;					}				}			}			// update G			double delta_alpha_i = alpha[i] - old_alpha_i;			double delta_alpha_j = alpha[j] - old_alpha_j;			for(int k=0;k<active_size;k++)			{				G[k] += Q_i[k]*delta_alpha_i + Q_j[k]*delta_alpha_j;			}			// update alpha_status and G_bar			{				boolean ui = is_upper_bound(i);				boolean uj = is_upper_bound(j);				update_alpha_status(i);				update_alpha_status(j);				int k;				if(ui != is_upper_bound(i))				{					Q_i = Q.get_Q(i,l);					if(ui)						for(k=0;k<l;k++)							G_bar[k] -= C_i * Q_i[k];					else						for(k=0;k<l;k++)							G_bar[k] += C_i * Q_i[k];				}				if(uj != is_upper_bound(j))				{					Q_j = Q.get_Q(j,l);					if(uj)						for(k=0;k<l;k++)							G_bar[k] -= C_j * Q_j[k];					else						for(k=0;k<l;k++)							G_bar[k] += C_j * Q_j[k];				}			}		}		// calculate rho		si.rho = calculate_rho();		// calculate objective value		{			double v = 0;			int i;			for(i=0;i<l;i++)				v += alpha[i] * (G[i] + b[i]);			si.obj = v/2;		}		// put back the solution		{			for(int i=0;i<l;i++)				alpha_[active_set[i]] = alpha[i];		}		si.upper_bound_p = Cp;		si.upper_bound_n = Cn;		System.out.print("\noptimization finished, #iter = "+iter+"\n");	}	// return 1 if already optimal, return 0 otherwise	int select_working_set(int[] working_set)	{		// return i,j which maximize -grad(f)^T d , under constraint		// if alpha_i == C, d != +1		// if alpha_i == 0, d != -1		double Gmax1 = -INF;		// max { -grad(f)_i * d | y_i*d = +1 }		int Gmax1_idx = -1;		double Gmax2 = -INF;		// max { -grad(f)_i * d | y_i*d = -1 }		int Gmax2_idx = -1;		for(int i=0;i<active_size;i++)		{			if(y[i]==+1)	// y = +1			{				if(!is_upper_bound(i))	// d = +1				{					if(-G[i] > Gmax1)					{						Gmax1 = -G[i];						Gmax1_idx = i;					}				}				if(!is_lower_bound(i))	// d = -1				{					if(G[i] > Gmax2)					{						Gmax2 = G[i];						Gmax2_idx = i;					}				}			}			else		// y = -1			{				if(!is_upper_bound(i))	// d = +1				{					if(-G[i] > Gmax2)					{						Gmax2 = -G[i];						Gmax2_idx = i;					}				}				if(!is_lower_bound(i))	// d = -1				{					if(G[i] > Gmax1)					{						Gmax1 = G[i];						Gmax1_idx = i;					}				}			}		}		if(Gmax1+Gmax2 < eps)

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久亚洲一区二区三区明星换脸 | 成人免费高清视频| 97精品久久久午夜一区二区三区| 欧美日韩久久久| 中文字幕一区二区三区四区不卡 | 偷窥少妇高潮呻吟av久久免费| 九九在线精品视频| 欧美亚洲日本国产| 国产精品卡一卡二卡三| 国内精品伊人久久久久av一坑 | 91麻豆精品视频| 精品国产乱码久久久久久老虎| 亚洲高清视频的网址| 95精品视频在线| 91.com视频| 欧美成人精品高清在线播放| 国产精品欧美久久久久无广告| 日韩综合一区二区| 欧美亚洲精品一区| 亚洲精品中文在线影院| 成人爱爱电影网址| 国产欧美va欧美不卡在线| 国产中文一区二区三区| 欧美一区二区三区视频免费播放| 亚洲自拍偷拍九九九| 一本色道久久综合亚洲aⅴ蜜桃| 欧美韩国日本综合| www.在线欧美| 国产精品久久久久久久久久免费看| 国产成人综合网| 国产午夜亚洲精品午夜鲁丝片| 久久综合综合久久综合| 欧美一区二区三区公司| 麻豆精品精品国产自在97香蕉| 7777精品伊人久久久大香线蕉| 调教+趴+乳夹+国产+精品| 欧美优质美女网站| 亚洲成人精品一区二区| 91精品国产综合久久精品图片| 亚洲国产aⅴ成人精品无吗| 777色狠狠一区二区三区| 日韩av电影免费观看高清完整版 | 精品一区二区精品| 精品国产乱码久久久久久久久| 国内精品伊人久久久久影院对白| 精品国产麻豆免费人成网站| 国产黄色精品网站| 国产精品传媒入口麻豆| 一本到不卡精品视频在线观看| 亚洲啪啪综合av一区二区三区| 在线免费不卡电影| 免费xxxx性欧美18vr| 久久婷婷久久一区二区三区| 99在线热播精品免费| 亚洲综合激情网| 欧美电影免费观看高清完整版在| 国产精品一级在线| 亚洲蜜臀av乱码久久精品| 91精品中文字幕一区二区三区| 精品无人码麻豆乱码1区2区| 国产精品久久777777| 欧美日韩一区二区三区四区 | 麻豆精品国产传媒mv男同| 2欧美一区二区三区在线观看视频| 国产成人精品一区二区三区网站观看| 亚洲精选免费视频| 欧美电影免费观看高清完整版在线观看 | 成人激情校园春色| 亚洲一卡二卡三卡四卡五卡| 亚洲精品一区二区三区福利| 色天天综合色天天久久| 老司机精品视频线观看86| 国产精品国产三级国产aⅴ入口| 欧美日韩成人在线| 大白屁股一区二区视频| 午夜精品免费在线观看| 中文欧美字幕免费| 91精品国产综合久久小美女| 99久久久国产精品| 韩国精品主播一区二区在线观看 | 7777精品伊人久久久大香线蕉| 国产激情一区二区三区| 视频在线观看一区| 亚洲免费在线观看视频| 亚洲精品在线网站| 欧美久久高跟鞋激| 91在线观看美女| 国产69精品久久99不卡| 奇米色一区二区三区四区| 亚洲欧美日韩小说| 欧美经典三级视频一区二区三区| 51精品国自产在线| 色婷婷综合久久| 成人av在线看| 国产成人免费在线观看| 久久精品国产秦先生| 亚洲成人免费观看| 一区二区三区日韩精品视频| 中文字幕欧美日韩一区| 精品国产一区二区三区忘忧草| 欧美日韩亚洲国产综合| 色综合欧美在线| 99在线热播精品免费| 丁香婷婷综合色啪| 国产成人亚洲综合色影视| 狠狠狠色丁香婷婷综合激情| 丝袜亚洲精品中文字幕一区| 亚洲一区二区av在线| 一区二区三区产品免费精品久久75| 欧美韩国日本不卡| 久久久久久久av麻豆果冻| 日韩区在线观看| 欧美一区二区视频在线观看 | 亚洲欧美激情视频在线观看一区二区三区 | 国产精品国产a级| 久久久久国产精品厨房| 久久日韩粉嫩一区二区三区| 久久影院视频免费| 久久青草欧美一区二区三区| 精品成人a区在线观看| 欧美成人艳星乳罩| 欧美精品一区二区三区在线播放 | 日韩精品一区二区三区视频| 日韩免费看的电影| 亚洲精品在线观看网站| 亚洲国产岛国毛片在线| 9191久久久久久久久久久| 日韩欧美一级在线播放| 久久综合九色综合久久久精品综合 | 日韩精彩视频在线观看| 蜜臀va亚洲va欧美va天堂| 精品一区二区久久| 成人激情黄色小说| 色999日韩国产欧美一区二区| 欧美三级一区二区| 精品国产三级a在线观看| 国产精品久久久久久亚洲毛片| 一区二区三区在线播| 蜜桃久久av一区| 国产成人高清视频| 欧美性欧美巨大黑白大战| 欧美一区二区不卡视频| 国产亚洲视频系列| 亚洲乱码国产乱码精品精98午夜| 亚洲成人你懂的| 国产麻豆视频精品| 日本高清无吗v一区| 欧美一区二区女人| 中文字幕永久在线不卡| 日韩精品电影在线| 成人福利电影精品一区二区在线观看| 91一区二区在线| 精品国产第一区二区三区观看体验| 国产精品你懂的| 日韩成人一区二区三区在线观看| 国产成人一区二区精品非洲| 欧美色综合久久| 久久久99免费| 亚洲成人免费视频| 波多野结衣中文字幕一区 | 中文字幕视频一区| 日本不卡视频在线| 99久久久无码国产精品| 日韩免费高清av| 亚洲男女毛片无遮挡| 国产精品88av| 日韩精品一区二区三区中文精品| 国产精品美女久久久久aⅴ| 亚洲va韩国va欧美va| 成人在线一区二区三区| 日韩亚洲欧美综合| 亚洲综合另类小说| 97精品国产露脸对白| 久久网站热最新地址| 日韩在线观看一区二区| 色拍拍在线精品视频8848| 国产拍揄自揄精品视频麻豆| 美女国产一区二区| 欧美偷拍一区二区| 国产精品的网站| 成人激情综合网站| 国产日产精品1区| 国产一区在线观看视频| 91精品在线免费观看| 亚洲一区二区av在线| 在线免费不卡电影| 一区二区三区在线免费观看| 97成人超碰视| 国产精品国产三级国产普通话三级| 国产精品一二三区在线| 精品国产人成亚洲区| 久久草av在线| 欧美成va人片在线观看| 麻豆国产精品777777在线| 欧美久久久久久久久久| 日本三级亚洲精品| 日韩无一区二区| 麻豆精品在线视频| 精品国产污污免费网站入口| 久久精品72免费观看|