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

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

?? svm.java

?? 支持向量機初學者可以
?? JAVA
?? 第 1 頁 / 共 5 頁
字號:
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		size = Math.max(size, 2*l);  // cache must be large enough for two columns		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 QMatrix {	abstract float[] get_Q(int column, int len);	abstract float[] get_QD();	abstract void swap_index(int i, int j);};abstract class Kernel extends QMatrix {	private svm_node[][] x;	private final double[] x_square;	// svm_parameter	private final int kernel_type;	private final int degree;	private final double gamma;	private final double coef0;	abstract float[] get_Q(int column, int len);	abstract float[] get_QD();	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 powi(double base, int times)	{	        double tmp = base, 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);	}	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 powi(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);			case svm_parameter.PRECOMPUTED:				return x[i][(int)(x[j][0].value)].value;			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 powi(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);			case svm_parameter.PRECOMPUTED:				return 	x[(int)(y[0].value)].value;			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;	QMatrix Q;	float[] QD;	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, QMatrix Q, double[] b_, byte[] y_,		   double[] alpha_, double Cp, double Cn, double eps, SolutionInfo si, int shrinking)	{		this.l = l;		this.Q = Q;		QD = Q.get_QD();		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 quad_coef = Q_i[i]+Q_j[j]+2*Q_i[j];				if (quad_coef <= 0)					quad_coef = 1e-12;				double delta = (-G[i]-G[j])/quad_coef;				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 quad_coef = Q_i[i]+Q_j[j]-2*Q_i[j];				if (quad_coef <= 0)					quad_coef = 1e-12;				double delta = (G[i]-G[j])/quad_coef;				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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美美女一区二区三区| 欧美一区国产二区| 丁香激情综合五月| 激情综合色播激情啊| 日韩精品一级中文字幕精品视频免费观看 | 蜜臀99久久精品久久久久久软件| 亚洲高清中文字幕| 亚洲亚洲精品在线观看| 亚洲已满18点击进入久久| 伊人夜夜躁av伊人久久| 一区二区三区四区亚洲| 亚洲免费观看高清完整版在线观看 | 欧美三级午夜理伦三级中视频| 2023国产一二三区日本精品2022| 国内精品国产三级国产a久久| 欧美日韩亚洲国产综合| 激情深爱一区二区| 国产另类ts人妖一区二区| 国产美女娇喘av呻吟久久| 国产成人免费xxxxxxxx| 高清成人免费视频| 不卡在线视频中文字幕| 91视频com| 欧美日韩视频不卡| 欧美一级艳片视频免费观看| 久久久久九九视频| 亚洲色欲色欲www| 亚洲国产精品一区二区久久恐怖片| 午夜av电影一区| 激情文学综合网| 99久久精品国产观看| 欧美亚洲图片小说| 日韩视频一区二区三区在线播放| 久久久久99精品一区| 亚洲欧洲在线观看av| 亚洲精品高清视频在线观看| 日本色综合中文字幕| 国产91在线观看| 亚洲一本大道在线| 91久久精品一区二区二区| 国产成人av资源| 欧美在线啊v一区| 日韩免费观看高清完整版在线观看| 久久久久久夜精品精品免费| 亚洲三级免费电影| 日本亚洲欧美天堂免费| 国产成人综合在线观看| 91福利精品第一导航| 精品少妇一区二区三区视频免付费| 中文字幕国产一区| 石原莉奈在线亚洲二区| 国产精品2024| 欧美性大战xxxxx久久久| 精品伦理精品一区| 亚洲黄色小视频| 激情综合网天天干| 在线免费不卡视频| 久久综合丝袜日本网| 亚洲精品一二三四区| 激情六月婷婷久久| 日本韩国欧美国产| 国产日韩av一区| 日韩中文字幕91| 91首页免费视频| 久久婷婷成人综合色| 一区二区三区中文字幕精品精品| 国产综合色视频| 欧美猛男男办公室激情| 136国产福利精品导航| 精品一二线国产| 欧美日韩久久久一区| 国产精品丝袜黑色高跟| 蜜桃在线一区二区三区| 欧美无砖砖区免费| 日韩一区欧美一区| 国产一区二区免费看| 欧美一区二区视频在线观看 | 欧美一区永久视频免费观看| 国产精品久久一级| 久久99精品国产91久久来源| 欧美日韩国产一二三| 亚洲天堂av老司机| 国产精品一区二区黑丝| 精品美女被调教视频大全网站| 亚洲va中文字幕| 日本高清不卡在线观看| 最好看的中文字幕久久| 国产黄色91视频| 精品国产91亚洲一区二区三区婷婷| 亚洲va天堂va国产va久| 91福利国产成人精品照片| 自拍偷自拍亚洲精品播放| 国产黄人亚洲片| 久久久蜜桃精品| 国产精品中文有码| 精品福利一区二区三区| 麻豆91在线播放免费| 欧美日本乱大交xxxxx| 一区二区高清免费观看影视大全| 99久久伊人精品| 国产精品美女久久久久久久| 国产成人av一区二区三区在线 | 久久精品亚洲麻豆av一区二区| 天天综合网天天综合色| 欧美日韩亚洲国产综合| 亚洲国产精品一区二区www | 欧美精品v日韩精品v韩国精品v| 亚洲蜜臀av乱码久久精品| 91小宝寻花一区二区三区| 国产精品国产自产拍高清av| 岛国av在线一区| 国产精品网曝门| 26uuu色噜噜精品一区二区| 久久草av在线| 久久天堂av综合合色蜜桃网| 国产精品一区二区在线观看不卡| 久久久午夜精品| 国产成人啪午夜精品网站男同| 国产日韩精品一区二区三区 | 日韩三级av在线播放| 久久激情五月激情| 久久这里只有精品首页| 国产一区二区三区综合 | 老司机精品视频导航| 久久亚洲精品国产精品紫薇| 国产一区91精品张津瑜| 国产精品视频观看| 色婷婷久久久久swag精品| 亚洲高清免费观看 | 欧美成人乱码一区二区三区| 国产一区二区三区不卡在线观看| 中文字幕欧美国产| 91豆麻精品91久久久久久| 日韩高清一级片| 日韩欧美在线影院| 成人美女在线观看| 亚洲综合精品久久| 日韩欧美亚洲国产精品字幕久久久| 国产精品99久久久久久久vr| 亚洲欧洲性图库| 欧美日韩国产大片| 国产一区 二区 三区一级| 日韩理论电影院| 91精品国产综合久久精品性色| 精品综合免费视频观看| 国产精品久久久久久福利一牛影视| 色天天综合色天天久久| 视频一区在线播放| 中文字幕高清不卡| 6080国产精品一区二区| 国产精品影视在线观看| 亚洲精品中文在线观看| 欧美白人最猛性xxxxx69交| 99久久精品免费看| 麻豆国产欧美日韩综合精品二区| 国产精品拍天天在线| 欧美精品高清视频| 暴力调教一区二区三区| 麻豆视频一区二区| 亚洲视频免费在线| xfplay精品久久| 欧美性生活一区| 国产一区二区三区在线观看免费视频 | 久久久精品黄色| 欧美日韩免费在线视频| 国产成人精品在线看| 天天亚洲美女在线视频| 国产精品福利一区| 欧美电视剧免费观看| 成人中文字幕在线| 26uuu久久天堂性欧美| 亚洲欧美日韩中文字幕一区二区三区| 一区二区三区影院| 97国产一区二区| 久久成人av少妇免费| 一区二区三区在线看| 久久综合成人精品亚洲另类欧美| 色婷婷久久久久swag精品| 国产精品99精品久久免费| 日韩成人午夜电影| 亚洲天堂av一区| 国产欧美日韩不卡免费| 日韩欧美不卡在线观看视频| 一本到高清视频免费精品| 国产福利一区在线观看| 日本不卡视频在线| 亚洲第一激情av| 一区二区视频在线| 国产欧美日韩在线观看| 日韩欧美一级在线播放| 欧美私人免费视频| 色综合一区二区三区| 国产成人久久精品77777最新版本| 久久国产精品99精品国产| 偷拍日韩校园综合在线| 亚洲综合视频在线观看| 国产精品久久777777| 亚洲国产高清aⅴ视频| 国产欧美一区二区精品性| 日韩午夜激情电影|