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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? svm.m4

?? 一個(gè)Java實(shí)現(xiàn)的支持向量機(jī)(含源碼),SVM算法比較復(fù)雜
?? M4
?? 第 1 頁 / 共 4 頁
字號:
define(`swap',`do {$1 _=$2; $2=$3; $3=_;} while(false)')define(`Qfloat',`float')define(`SIZE_OF_QFLOAT',4)define(`TAU',1e-12)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		Qfloat[] 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 /= SIZE_OF_QFLOAT;		size -= l * (16/SIZE_OF_QFLOAT);	// 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, Qfloat[][] 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			Qfloat[] new_data = new Qfloat[len];			if(h.data != null) System.arraycopy(h.data,0,new_data,0,h.len);			h.data = new_data;			size -= more;			swap(int,h.len,len);		}		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]);		swap(Qfloat[],head[i].data,head[j].data);		swap(int,head[i].len,head[j].len);		if(head[i].len > 0) lru_insert(head[i]);		if(head[j].len > 0) lru_insert(head[j]);		if(i>j) swap(int,i,j);		for(head_t h = lru_head.next; h!=lru_head; h=h.next)		{			if(h.len > i)			{				if(h.len > j)					swap(Qfloat,h.data[i],h.data[j]);				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 Qfloat[] get_Q(int column, int len);	abstract Qfloat[] 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 double degree;	private final double gamma;	private final double coef0;	abstract Qfloat[] get_Q(int column, int len);	abstract Qfloat[] get_QD();	void swap_index(int i, int j)	{		swap(svm_node[],x[i],x[j]);		if(x_square != null) swap(double,x_square[i],x_square[j]);	}	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;	QMatrix Q;	Qfloat[] 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);		swap(byte,	y[i],y[j]);		swap(double,	G[i],G[j]);		swap(byte,	alpha_status[i],alpha_status[j]);		swap(double,	alpha[i],alpha[j]);		swap(double,	b[i],b[j]);		swap(int,	active_set[i],active_set[j]);		swap(double,	G_bar[i],G_bar[j]);	}	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))			{				Qfloat[] 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))				{					Qfloat[] 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			Qfloat[] Q_i = Q.get_Q(i,active_size);			Qfloat[] 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 = TAU;				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 = TAU;				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				{					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 such that		// i: maximizes -y_i * grad(f)_i, i in I_up(\alpha)		// j: mimimizes the decrease of obj value		//    (if quadratic coefficeint <= 0, replace it with tau)		//    -y_j*grad(f)_j < -y_i*grad(f)_i, j in I_low(\alpha)				double Gmax = -INF;		double Gmax2 = -INF;		int Gmax_idx = -1;		int Gmin_idx = -1;		double obj_diff_min = INF;			for(int t=0;t<active_size;t++)			if(y[t]==+1)				{				if(!is_upper_bound(t))					if(-G[t] >= Gmax)					{						Gmax = -G[t];						Gmax_idx = t;					}			}			else			{				if(!is_lower_bound(t))					if(G[t] >= Gmax)					{						Gmax = G[t];						Gmax_idx = t;					}			}			int i = Gmax_idx;		Qfloat[] Q_i = null;		if(i != -1) // null Q_i not accessed: Gmax=-INF if i=-1			Q_i = Q.get_Q(i,active_size);			for(int j=0;j<active_size;j++)		{			if(y[j]==+1)			{				if (!is_lower_bound(j))				{					double grad_diff=Gmax+G[j];					if (G[j] >= Gmax2)						Gmax2 = G[j];					if (grad_diff > 0)					{						double obj_diff; 						double quad_coef=Q_i[i]+QD[j]-2*y[i]*Q_i[j];						if (quad_coef > 0)							obj_diff = -(grad_diff*grad_diff)/quad_coef;						else							obj_diff = -(grad_diff*grad_diff)/TAU;							if (obj_diff <= obj_diff_min)						{							Gmin_idx=j;							obj_diff_min = obj_diff;						}					}				}			}			else			{				if (!is_upper_bound(j))				{					double grad_diff= Gmax-G[j];					if (-G[j] >= Gmax2)						Gmax2 = -G[j];

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
韩国精品一区二区| 欧美成人bangbros| 91极品视觉盛宴| 91网站黄www| 色综合久久66| 色猫猫国产区一区二在线视频| 99精品欧美一区二区三区小说| 丁香亚洲综合激情啪啪综合| 国产91综合网| 成人国产电影网| 99在线视频精品| 色一情一伦一子一伦一区| 色吧成人激情小说| 欧美日韩免费一区二区三区 | 在线一区二区三区四区五区| 91一区一区三区| 欧美日韩中文国产| 91精品国产综合久久福利软件| 制服丝袜激情欧洲亚洲| 欧美mv日韩mv国产| 国产日韩精品一区二区三区在线| 国产精品国产a| 午夜久久久影院| 久久精品国产在热久久| 国产69精品久久久久毛片| 色菇凉天天综合网| 欧美一级生活片| 国产日韩精品一区二区三区| 亚洲欧美在线观看| 日韩制服丝袜先锋影音| 激情久久五月天| 色综合久久88色综合天天免费| 欧美理论在线播放| 2021久久国产精品不只是精品| 国产精品无码永久免费888| 亚洲综合丁香婷婷六月香| 伦理电影国产精品| 不卡一区二区在线| 欧美精品日韩精品| 国产亚洲欧美激情| 亚洲v精品v日韩v欧美v专区| 国产一区视频导航| 91国产成人在线| 日韩精品一区二区三区在线| 国产精品国产三级国产三级人妇| 日韩精品五月天| 国产成人精品免费一区二区| 欧美日韩国产另类不卡| 日本一区二区在线不卡| 天天综合天天做天天综合| 国产成人在线看| 91精品免费在线观看| 中文字幕中文乱码欧美一区二区| 午夜不卡av在线| 成人午夜短视频| 日韩一区二区三区免费看 | 午夜影院久久久| 成人国产亚洲欧美成人综合网| 欧美一级欧美三级| 亚洲视频你懂的| 国产电影一区在线| 欧美一区二区三区免费在线看 | 国产精品超碰97尤物18| 免费一级片91| 欧美性受极品xxxx喷水| 欧美激情在线观看视频免费| 蜜桃一区二区三区在线观看| 91年精品国产| 国产精品视频yy9299一区| 日本欧美韩国一区三区| 在线视频欧美精品| 国产精品初高中害羞小美女文| 男男视频亚洲欧美| 欧美美女一区二区| 亚洲一区二区欧美| 91天堂素人约啪| 国产日韩欧美在线一区| 激情综合色综合久久| 91精品国产入口在线| 亚洲小少妇裸体bbw| 99re视频精品| 国产精品毛片高清在线完整版| 韩国成人精品a∨在线观看| 欧美一区二区三区视频免费播放| 亚洲一区二区三区四区五区中文| www.在线成人| 日本一区二区三区国色天香| 国产麻豆精品久久一二三| 日韩精品一区二区三区蜜臀| 亚洲一区日韩精品中文字幕| 色久综合一二码| 亚洲另类色综合网站| 91视频在线观看免费| 日韩码欧中文字| 成人av资源下载| 国产精品国产三级国产普通话蜜臀 | 亚洲午夜视频在线观看| 成人伦理片在线| 国产精品欧美极品| aaa国产一区| 亚洲欧洲综合另类| 91免费观看国产| 一区二区高清在线| 欧美日韩在线一区二区| 亚洲韩国精品一区| 欧美人伦禁忌dvd放荡欲情| 午夜欧美大尺度福利影院在线看| 欧美日韩免费观看一区三区| 亚洲不卡av一区二区三区| 欧美一区二区精品| 捆绑调教一区二区三区| 久久先锋资源网| 国产成人精品aa毛片| 欧美激情一区二区三区四区 | 国产日产亚洲精品系列| 成人动漫在线一区| 国产精品青草综合久久久久99| 北岛玲一区二区三区四区| 亚洲日本va午夜在线电影| 一本久道久久综合中文字幕 | 欧美性大战xxxxx久久久| 亚洲超碰97人人做人人爱| 91精品在线一区二区| 激情图区综合网| 中文字幕免费不卡| 欧洲日韩一区二区三区| 秋霞影院一区二区| 国产日韩欧美一区二区三区综合| 成人激情免费视频| 亚洲在线视频网站| 日韩欧美综合在线| 国产ts人妖一区二区| 亚洲男人的天堂在线观看| 欧美视频三区在线播放| 麻豆国产一区二区| 亚洲欧洲国产专区| 91精品婷婷国产综合久久竹菊| 国产一区二区三区精品欧美日韩一区二区三区 | 欧美日韩你懂的| 国产一区二区精品在线观看| 亚洲色图色小说| 日韩欧美一卡二卡| 99免费精品视频| 乱一区二区av| 亚洲美女偷拍久久| 欧美一激情一区二区三区| 国产盗摄精品一区二区三区在线| 一区二区三区四区蜜桃| 久久亚洲综合色一区二区三区| 色香色香欲天天天影视综合网| 老司机午夜精品| 亚洲美女在线一区| 久久久亚洲精品一区二区三区| 欧美最新大片在线看| 激情久久久久久久久久久久久久久久| 亚洲少妇屁股交4| 337p日本欧洲亚洲大胆精品| 欧洲视频一区二区| 国产黑丝在线一区二区三区| 婷婷亚洲久悠悠色悠在线播放| 国产女人水真多18毛片18精品视频| 欧美三区在线视频| 成人免费视频国产在线观看| 日本女人一区二区三区| 亚洲男同性恋视频| 国产三级欧美三级| 日韩午夜在线播放| 在线日韩一区二区| 懂色av一区二区在线播放| 裸体健美xxxx欧美裸体表演| 一区二区三区中文字幕精品精品| 精品美女在线播放| 欧美精品高清视频| 日本韩国欧美在线| 成人视屏免费看| 免费在线观看一区| 亚洲大型综合色站| 亚洲美女偷拍久久| 亚洲欧洲日韩一区二区三区| 久久蜜臀中文字幕| 日韩午夜三级在线| 欧美日韩精品免费观看视频| 色成人在线视频| 99re热视频精品| 成人av在线资源网| 国产xxx精品视频大全| 国产综合色精品一区二区三区| 日本欧美肥老太交大片| 天堂久久久久va久久久久| 亚洲制服丝袜一区| 亚洲品质自拍视频网站| 国产精品久久久久永久免费观看 | 精品免费99久久| 欧美一二区视频| 3d动漫精品啪啪| 欧美精品久久天天躁| 欧美日韩三级视频| 91成人免费在线视频| 一本大道久久a久久精二百| 色先锋资源久久综合|