⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 algorithmlda2.java,v

📁 包含了模式识别中常用的一些分类器设计算法
💻 JAVA,V
📖 第 1 页 / 共 5 页
字号:
	    // append message to process box
	    pro_box_d.appendMessage((String)description_d.get(step_index_d));
d107 3a109 3	    // exit gracefully
	    return true;
	}
d111 4a114 4	boolean step1()
	{
	    // Debug
	    //System.out.println(algo_id + ": step1()");
d116 18a133 18	    pro_box_d.setProgressMin(0);
	    pro_box_d.setProgressMax(20);
	    pro_box_d.setProgressCurr(0);
	    
	    // append message to process box
	    output_panel_d.addOutput(set1_d, Classify.PTYPE_INPUT, 
				     data_points_d.color_dset1);
	    output_panel_d.addOutput(set2_d, Classify.PTYPE_INPUT,
				     data_points_d.color_dset2);
	    output_panel_d.addOutput(set3_d, Classify.PTYPE_INPUT,
				     data_points_d.color_dset3);
	    output_panel_d.addOutput(set4_d, Classify.PTYPE_INPUT, 
				     data_points_d.color_dset4);		
	    // step 1 completed
	    pro_box_d.setProgressCurr(20);
	    output_panel_d.repaint();
	    return true;
	}
d135 4a138 4	boolean step2()
	{
		// Debug
	    //System.out.println(algo_id + ": step2()");
d140 3a142 3		pro_box_d.setProgressMin(0);
		pro_box_d.setProgressMax(20);
		pro_box_d.setProgressCurr(0);
d144 1a144 1		computeMeans();
d146 3a148 3		// determine the within class scatter matrix
		//
		withinClass(W);
d150 3a152 3		// determine the between class scatter matrix
		//
		betweenClass1(B1, B2, B3, B4);
d157 1a157 1		W.invertMatrix(invW);
d159 16a174 16		if (set1_d.size() > 0)
		{
		    invW.multMatrix(B1, S1);
		}
		if (set2_d.size() > 0)
		{
		    invW.multMatrix(B2, S2);
		}
		if (set3_d.size() > 0)
		{
		    invW.multMatrix(B3, S3);
		}
		if (set4_d.size() > 0)
		{
		    invW.multMatrix(B4, S4);
		}
d176 3a178 3		// transform the samples from all data sets
		//
		transformLDA1(S1, S2, S3, S4);
d180 1a180 1		printMatrices();
d182 3a184 3		// display means
		//----
		output_panel_d.addOutput(point_means_d, Classify.PTYPE_OUTPUT_LARGE, Color.black);
d186 3a188 3		// display support vectors
		//----
		output_panel_d.addOutput(support_vectors_d, Classify.PTYPE_INPUT, Color.cyan);
d190 6a195 6		// display support vectors
		//
		pro_box_d.setProgressCurr(20);
		output_panel_d.repaint();
		return true;
	}
d197 4a200 4	boolean step3()
	{
		// Debug
	    //System.out.println(algo_id + ": step3()");
d202 7a208 7		pro_box_d.setProgressMin(0);
		pro_box_d.setProgressMax(20);
		pro_box_d.setProgressCurr(0);
		
		// compute the decision regisions
		//----
		computeDecisionRegions();
d212 1a212 1		computeErrors();
d214 2a215 2		// display support vectors
		output_panel_d.addOutput( decision_regions_d, Classify.PTYPE_INPUT, new Color(255, 200, 0));
d217 2a218 2		//Color.black);
		output_panel_d.repaint();
d220 13a232 1		return true;
d234 2a235 2
	public void run()
d237 4a240 2	    // Debug
	    //System.out.println(algo_id + " run()");
d242 6a247 22	    if (step_index_d == 1)
		{
		    disableControl();
		    step1();
		    enableControl();
		}
	    
	    else if (step_index_d == 2)
		{
		    disableControl();
		    step2(); 
		    enableControl();
		}
	    
	    else if (step_index_d == 3)
		{
		    disableControl();
		    step3();
		    pro_box_d.appendMessage("   Algorithm Complete");
		    enableControl(); 
		}
	    return;
d249 46d296 2a297 47	// method transformLDA1
	//
	// arguments:
	//    Data d: input data point
	//    Matrix M1: covariance matrix of the first class
	//    Matrix M2: covariance matrix of the second class
	//    Matrix M3: covariance matrix of the third class
	//    Matrix M4: covariance matrix of the forth class
	//
	// return   : none
	//
	// this method transforms a given set of points to a new space
	// using the class dependent linear discrimination analysis algorithm
	//
	public void transformLDA1(Matrix S1, Matrix S2, Matrix S3, Matrix S4)
	{
		// declare local variables
		int size = 0;
		int xsize1 = 0;
		int ysize1 = 0;
		int xsize2 = 0;
		int ysize2 = 0;
		int xsize3 = 0;
		int ysize3 = 0;
		int xsize4 = 0;
		int ysize4 = 0;

		double xval1 = 0.0;
		double yval1 = 0.0;
		double xval2 = 0.0;
		double yval2 = 0.0;
		double xval3 = 0.0;
		double yval3 = 0.0;
		double xval4 = 0.0;
		double yval4 = 0.0;

		double xmean1 = 0.0;
		double ymean1 = 0.0;
		double xmean2 = 0.0;
		double ymean2 = 0.0;
		double xmean3 = 0.0;
		double ymean3 = 0.0;
		double xmean4 = 0.0;
		double ymean4 = 0.0;

		double xval = 0.0;
		double yval = 0.0;
d300 4a303 4		double eigVal1[] = null;
		double eigVal2[] = null;
		double eigVal3[] = null;
		double eigVal4[] = null;
d307 1a307 1		double eigVec[] = new double[2];
d309 3a311 3		// compute the propabilities of each data set
		//
		double maxsamples = set1_d.size() + set2_d.size() + set3_d.size() + set4_d.size();
d313 4a316 4		double p1 = set1_d.size() / maxsamples;
		double p2 = set2_d.size() / maxsamples;
		double p3 = set3_d.size() / maxsamples;
		double p4 = set4_d.size() / maxsamples;
d319 4a322 1		size = set1_d.size();
d324 7a330 2		xsize1 += size;
		ysize1 += size;
d332 44a375 1		for (int i = 0; i < size; i++)
d377 1a377 4
		    MyPoint p = (MyPoint)set1_d.elementAt(i);
		    xval1 += p.x;
		    yval1 += p.y;
d379 20d400 23a422 1		// compute the transformation matrix for the first data set
d424 1a424 8		if (size > 0)
		{

		    // declare matrix objects
		    //
		    Matrix T = new Matrix();
		    Matrix M = new Matrix();
		    Matrix W = new Matrix();
d426 3a428 5		    // allocate memory for the matrix elements
		    //
		    T.Elem = new double[2][2];
		    M.Elem = new double[2][2];
		    W.Elem = new double[2][2];
d430 3a432 12		    // initialize the transformation matrix dimensions
		    //
		    W.row = 2;
		    W.col = 2;
		    
		    // reset the matrices
		    //
		    W.resetMatrix();
		    
		    // initialize the matrix needed to compute the eigenvalues
		    //
		    T.initMatrix(S1.Elem, 2, 2);
d434 1a434 39		    // make a copy of the original matrix
		    //
		    M.copyMatrix(T);
		    
		    // compute the eigen values
		    //
		    eigVal1 = Eigen.compEigenVal(T);
		    
		    // compute the eigen vectors
		    //
		    for (int i = 0; i < 2; i++)
			{
			    Eigen.calcEigVec(M, eigVal1[i], eigVec);
			    for (int j = 0; j < 2; j++)
				{
				    W.Elem[j][i] = eigVec[j];
				}
			}
		    
		    // save the transformation matrix 
		    //
			LDA1 = W;
			
		}

		size = set2_d.size();

		xsize2 += size;
		ysize2 += size;

		for (int i = 0; i < size; i++)
		{

		    MyPoint p = (MyPoint)set2_d.elementAt(i);
		    xval2 += p.x;
		    yval2 += p.y;
		}

		// compute the transformation matrix for the second data set
d436 1a436 31		if (size > 0)
		{

		    // declare matrix objects
		    //
		    Matrix T = new Matrix();
		    Matrix M = new Matrix();
		    Matrix W = new Matrix();
		    
		    // allocate memory for the matrix elements
		    //
		    T.Elem = new double[2][2];
		    M.Elem = new double[2][2];
		    W.Elem = new double[2][2];
		    
		    // initialize the transformation matrix dimensions
		    //
		    W.row = 2;
		    W.col = 2;
		    
		    // reset the matrices
		    //
		    W.resetMatrix();
		    
		    // initialize the matrix needed to compute the eigenvalues
		    //
		    T.initMatrix(S2.Elem, 2, 2);
		    
		    // make a copy of the original matrix
		    //
		    M.copyMatrix(T);
d438 1a438 34		    // compute the eigen values
		    //
		    eigVal2 = Eigen.compEigenVal(T);
		    
		    // compute the eigen vectors
		    //
		    for (int i = 0; i < 2; i++)
			{
			    Eigen.calcEigVec(M, eigVal2[i], eigVec);
			    for (int j = 0; j < 2; j++)
				{
				    W.Elem[j][i] = eigVec[j];
				}
			}
		    
		    // save the transformation matrix 
		    //
		    LDA2 = W;
		}
		
		size = set3_d.size();

		xsize3 += size;
		ysize3 += size;

		for (int i = 0; i < size; i++)
		{

		    MyPoint p = (MyPoint)set3_d.elementAt(i);
		    xval3 += p.x;
		    yval3 += p.y;
		}

		// compute the transformation matrix for the third data set
d440 1a440 1		if (size > 0)
d442 2a443 37		    
		    // declare matrix objects
		    //
		    Matrix T = new Matrix();
		    Matrix M = new Matrix();
		    Matrix W = new Matrix();
		    
		    // allocate memory for the matrix elements
		    //
		    T.Elem = new double[2][2];
		    M.Elem = new double[2][2];
		    W.Elem = new double[2][2];
		    
		    // initialize the transformation matrix dimensions
		    //
		    W.row = 2;
		    W.col = 2;
		    
		    // reset the matrices
		    //
		    W.resetMatrix();
		    
		    // initialize the matrix needed to compute the eigenvalues
		    //
		    T.initMatrix(S3.Elem, 2, 2);
		    
		    // make a copy of the original matrix
		    //
		    M.copyMatrix(T);
		    
		    // compute the eigen values
		    //
		    eigVal3 = Eigen.compEigenVal(T);
		    
		    // compute the eigen vectors
		    //
		    for (int i = 0; i < 2; i++)
d445 1a445 5			Eigen.calcEigVec(M, eigVal3[i], eigVec);
			for (int j = 0; j < 2; j++)
			{
			    W.Elem[j][i] = eigVec[j];
			}
a446 4		    
		    // save the transformation matrix 
		    //
		    LDA3 = W;
d449 6a454 1		size = set4_d.size();
d456 2a457 2		xsize4 += size;
		ysize4 += size;
d459 7a465 2		for (int i = 0; i < size; i++)
		{
d467 6a472 6		    MyPoint p = (MyPoint)set4_d.elementAt(i);
		    xval4 += p.x;
		    yval4 += p.y;
		}

		// compute the transformation matrix for the forth data set
d474 3a476 2		if (size > 0)
		{
d478 5a482 5		    // declare matrix objects
		    //
		    Matrix T = new Matrix();
		    Matrix M = new Matrix();
		    Matrix W = new Matrix();
d484 4a487 5		    // allocate memory for the matrix elements
		    //
		    T.Elem = new double[2][2];
		    M.Elem = new double[2][2];
		    W.Elem = new double[2][2];
d489 3a491 4		    // initialize the transformation matrix dimensions
		    //
		    W.row = 2;
		    W.col = 2;
d493 3a495 3		    // reset the matrices
		    //
		    W.resetMatrix();
d497 3a499 3		    // initialize the matrix needed to compute the eigenvalues
		    //
		    T.initMatrix(S4.Elem, 2, 2);
d501 3a503 3		    // make a copy of the original matrix
		    //
		    M.copyMatrix(T);
d505 6a510 7		    // compute the eigen values
		    //
		    eigVal4 = Eigen.compEigenVal(T);
		    
		    // compute the eigen vectors
		    //
		    for (int i = 0; i < 2; i++)
d512 2a513 10			Eigen.calcEigVec(M, eigVal4[i], eigVec);
			for (int j = 0; j < 2; j++)
			{
			    W.Elem[j][i] = eigVec[j];
			}
		    }
		    
		    // save the transformation matrix 
		    //
		    LDA4 = W;
d515 17a531 1
d533 2a534 8    
	// method: withinClass
	//
	// arguments:
	//    Data d: input data points
	//    Matrix M: within class scatter matrix
	//
	// return   : none
d536 1a536 3	// this method determines the within class scatter matrix
	//
	public void withinClass(Matrix M)
a537 5	    // declare local variables
	    //
	    int size = 0;
	    double x[] = null;
	    double y[] = null;
d539 1a539 3	    DisplayScale scale = output_panel_d.disp_area_d.getDisplayScale();

	    // declare the covariance object
d541 3a543 1	    Covariance cov = new Covariance();
d545 1a545 1	    // compute the propabilities of each data set
d547 3a549 10	    double maxsamples = set1_d.size() + set2_d.size() + set3_d.size() + set4_d.size();
	    
	    double p1 = set1_d.size() / maxsamples;
	    double p2 = set2_d.size() / maxsamples;
	    double p3 = set3_d.size() / maxsamples;
	    double p4 = set4_d.size() / maxsamples;
	    
	    // get the first data set size
	    //
	    size = set1_d.size();
d551 1a551 1	    // initialize arrays to store the samples
d553 2a554 2	    x = new double[size];
	    y = new double[size];
d556 1a556 2	    // set up

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -