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

📄 algorithmlda.java,v

📁 包含了模式识别中常用的一些分类器设计算法
💻 JAVA,V
📖 第 1 页 / 共 4 页
字号:
	    text =
		new String(
			   "       Results for class 0:\n"
			   + "          Total number of samples: "
			   + samples1
			   + "\n"
			   + "          Misclassified samples: "
			   + incorrect1
			   + "\n"
			   + "          Classification error: "
			   + MathUtil.setDecimal(error, 2)
			   + "%");
	    
	    pro_box_d.appendMessage(text);
	}
	
	// compute the classification error for the second set
	//
	for (int i = 0; i < set2_d.size(); i++)
	{
	    
	    MyPoint point = (MyPoint)set2_d.elementAt(i);
	    samples2++;
	    if ((point.x > scale.xmin && point.x < scale.xmax)
		&& (point.y > scale.ymin && point.y < scale.ymax))
	    {
		if (output_canvas_d[(int)((point.x - scale.xmin) / incrementX)]
		    [(int)((point.y - scale.ymin) / incrementY)] != 1)
		{
		    incorrect2++;
		}
	    }
	}
	
	if (set2_d.size() > 0)
	{
	    
	    error = ((double)incorrect2 / (double)samples2) * 100.0;
	    
	    text =
		new String(
			   "       Results for class 1:\n"
			   + "          Total number of samples: "
			   + samples2
			   + "\n"
			   + "          Misclassified samples: "
			   + incorrect2
			   + "\n"
			   + "          Classification error: "
			   + MathUtil.setDecimal(error, 2)
			   + "%");
	    
	    pro_box_d.appendMessage(text);
	}
	
	// compute the classification error for the third set
	//
	for (int i = 0; i < set3_d.size(); i++)
	{
	    
	    MyPoint point = (MyPoint)set3_d.elementAt(i);
	    samples3++;
	    if ((point.x > scale.xmin && point.x < scale.xmax)
		&& (point.y > scale.ymin && point.y < scale.ymax))
	    {
		if (output_canvas_d[(int)((point.x - scale.xmin) / incrementX)]
		    [(int)((point.y - scale.ymin) / incrementY)] != 2)
		{
		    incorrect3++;
		}
	    }
	}
	
	if (set3_d.size() > 0)
	{
	    error = ((double)incorrect3 / (double)samples3) * 100.0;
	    
	    text =
		new String(
			   "       Results for class 2:\n"
			   + "          Total number of samples: "
			   + samples3
			   + "\n"
			   + "          Misclassified samples: "
			   + incorrect3
			   + "\n"
			   + "          Classification error: "
			   + MathUtil.setDecimal(error, 2)
			   + "%");
	    
	    pro_box_d.appendMessage(text);
	}
	
	// compute the classification error for the forth set
	//
	for (int i = 0; i < set4_d.size(); i++)
	{
	    
	    MyPoint point = (MyPoint)set4_d.elementAt(i);
	    samples4++;
	    if ((point.x > scale.xmin && point.x < scale.xmax)
		&& (point.y > scale.ymin && point.y < scale.ymax))
	    {
		if (output_canvas_d[(int)((point.x - scale.xmin) / incrementX)]
		    [(int)((point.y - scale.ymin) / incrementY)] != 3)
		{
		    incorrect4++;
		}
	    }
	}
	
	if (set4_d.size() > 0)
	{
		
	    error = ((double)incorrect4 / (double)samples4) * 100.0;
	    
	    text =
		new String(
			   "       Results for class 3:\n"
			   + "          Total number of samples: "
			   + samples4
			   + "\n"
			   + "          Misclassified samples: "
			   + incorrect4
			   + "\n"
			   + "          Classification error: "
			   + MathUtil.setDecimal(error, 2)
			   + "%");
	    
	    pro_box_d.appendMessage(text);
	}
	
	// compute the overall classification error
	//
	samples = samples1 + samples2 + samples3 + samples4;
	incorrect = incorrect1 + incorrect2 + incorrect3 + incorrect4;
	error = ((double)incorrect / (double)samples) * 100.0;
	
	text =
	    new String(
		       "       Overall results:\n"
		       + "          Total number of samples: "
		       + samples
		       + "\n"
		       + "          Misclassified samples: "
		       + incorrect
		       + "\n"
		       + "          Classification error: "
		       + MathUtil.setDecimal(error, 2)
		       + "%");
	
	pro_box_d.appendMessage(text);
    }
}
@1.6log@Fixed minor Javadoc errors.@text@d11 1d25 2a26 2    Vector decision_regions_d;
    Vector support_vectors_d;
d55 4a58 4	point_means_d      = new Vector();
	decision_regions_d = new Vector();
	support_vectors_d  = new Vector();
	description_d      = new Vector();
d92 12a103 5	set1_d = (Vector)data_points_d.dset1.clone();
	set2_d = (Vector)data_points_d.dset2.clone();
	set3_d = (Vector)data_points_d.dset3.clone();
	set4_d = (Vector)data_points_d.dset4.clone();
	
@1.5log@*** empty log message ***@text@d4 2a5 1//                              Last Edited : Sanjay Patil
d43 1a43 1    * @@return   boolean
d112 1a112 1    * @@return boolean
d147 2d203 2@1.4log@minor changes to suit Java Documentation Style.@text@d1 12a12 6/*
 * AlgorithmLDA.java V6.0 03/15/2005
 * author Phil Trasatti Created on Jul 15, 2003
 */


d16 3d28 1d32 1a32 1    Matrix CLDA; // covariance matrix for CLDA1
d37 7a43 3    /* (non-Javadoc)
     * @@see IFAlgorithm#initialize()
     */
d46 1a46 1	algo_id = "AlgorithmLDA";
a49 1	// System.out.println("THE FUNCTION IS CALLED");
d51 1d53 1a53 1	point_means_d = new Vector();
d55 2a56 2	support_vectors_d = new Vector();
	description_d = new Vector();
d60 2a61 2	W = new Matrix();
	LDA = new Matrix();
d63 2a64 2	B = new Matrix();
	S = new Matrix();
d107 6a112 1    
d142 5d197 4d212 1a212 1	// compute the decision regisions
d232 1d234 2a235 4     * this method determines the within class scatter matrix
     *
     * @@param   Matrix M: within class scatter matrix
     *
d402 1a402 2     * 
     * this method determines the between class scatter matrix for
d405 2a406 2     * @@param   Matrix M: between class scatter matrix
     *
d613 4d648 2a649 3     *
     * display two matrices
     *
a705 1	
a708 1     * 
d712 4a715 3     * @@param Data d: input data point
     * @@param Matrix S: between class to within class ratio
     *
d781 1a781 3     * 
     * method computes the line of discrimination for class independent LDA
     *
d954 4d977 2a978 1	DisplayScale scale = output_panel_d.disp_area_d.getDisplayScale();	
d980 1@1.3log@comments and drastic alignment of the documents as per Java DocumentationStandards.@text@d1 6a8 3/*
 * Created on Jul 15, 2003
 */
a9 4/**
 * @@author Phil Trasatti
 *
 */
d13 1d19 1d34 4a37 3	//System.out.println("THE FUNCTION IS CALLED");
	//Debug
	//System.out.println(algo_id + " initialize()");
d45 1d54 1d71 1d75 1d82 1d86 1d90 1d97 2a98 1	//System.out.println(algo_id + " step1()");
d105 1d116 1d126 2a127 1	//System.out.println(algo_id + " step2()");
d140 1a140 1			//
d156 3a158 2	//----
	output_panel_d.addOutput(point_means_d, Classify.PTYPE_OUTPUT_LARGE, Color.black);
d161 3a163 2	//----
	output_panel_d.addOutput(support_vectors_d, Classify.PTYPE_INPUT, Color.black );
d176 2a177 1	//System.out.println(algo_id + " step3()");
d185 1a185 1	//----
d194 3a196 3	// display support vectors
	//----
	output_panel_d.addOutput( decision_regions_d, Classify.PTYPE_INPUT, new Color(255, 200, 0));
a197 1	//Color.black);
a203 1     * method: withinClass
d205 1a205 5     * arguments:
     *    Data d: input data points
     *    Matrix M: within class scatter matrix
     *
     * @@return     none
d207 1a207 1     * this method determines the within class scatter matrix
d234 2a235 1	double maxsamples = set1_d.size() + set2_d.size() + set3_d.size() + set4_d.size();
d375 3a377 1     * method: betweenClass
a378 1     * @@param   Data d: input data points
a380 5     * @@return  none
     *
     * this method determines the between class scatter matrix for
     * the class independent linear discrimination algorithm
     *
d424 2a425 1	double maxsamples = set1_d.size() + set2_d.size() + set3_d.size() + set4_d.size();
d590 2a591 1	//System.out.println(algo_id + " run()");
a617 5     * method dispalyMatrices
     *
     * @@param  Data d: input data point
     *
     * @@return none
d681 3a683 1     * method transformLDA
a687 5     * @@return     none
     *
     * this method transforms a given set of points to a new space
     * using the class independent linear discrimination analysis algorithm
     *
d691 3a693 2	//	Debug
	//System.out.println(algo_id + " transformLDA(Data d, Matrix S)");
d753 1a753 5     * method: computeDecisionRegions
     *
     * @@param   none
     * @@return  none
     *
d760 2a761 1	//System.out.println(algo_id + " computeDecisionRegions()");
d764 1d786 2a787 2	double incrementY = (scale.ymax-scale.ymin)/outputHeight;
	double incrementX = (scale.xmax-scale.xmin)/outputWidth;
a833 1		    
a840 1		    
a847 1
a854 1		    
d894 2a895 1		    dist = MathUtil.distance(C.Elem[0][0], C.Elem[0][1], D.Elem[0][0], D.Elem[0][1]);
d918 2a919 1		    if (associated != output_canvas_d[i][j - 1] || associated != output_canvas_d[i - 1][j])
d952 2a953 2	double incrementY = (scale.ymax-scale.ymin)/outputHeight;
	double incrementX = (scale.xmax-scale.xmin)/outputWidth;
a958 1	    
d964 2a965 1		if (output_canvas_d[(int)((point.x-scale.xmin)/incrementX)][(int)((point.y-scale.ymin)/incrementY)] != 0)
d1003 2a1004 1		if (output_canvas_d[(int)((point.x-scale.xmin)/incrementX)][(int)((point.y-scale.ymin)/incrementY)] != 1)
d1042 2a1043 1		if (output_canvas_d[(int)((point.x-scale.xmin)/incrementX)][(int)((point.y-scale.ymin)/incrementY)] != 2)
a1051 1	    
d1080 2a1081 1		if (output_canvas_d[(int)((point.x-scale.xmin)/incrementX)][(int)((point.y-scale.ymin)/incrementY)] != 3)
d1129 1a1129 3	
    }    
    
@1.2log@Algorithm Complete and debug statements commented@text@d13 42a54 36	// Public Data Members
	Vector decision_regions_d;
	Vector support_vectors_d;
	int output_canvas_d[][];

	// declare local Matrix objects
	Matrix W;
	Matrix LDA;
	Matrix CLDA; // covariance matrix for CLDA1
	Matrix B;
	Matrix S;
	Matrix invW;

	/* (non-Javadoc)
	 * @@see IFAlgorithm#initialize()
	 */
	public boolean initialize()
	{
	    algo_id = "AlgorithmLDA";

	    //System.out.println("THE FUNCTION IS CALLED");
	    //Debug
	    //System.out.println(algo_id + " initialize()");
	    step_count = 3;
	    point_means_d = new Vector();
	    decision_regions_d = new Vector();
	    support_vectors_d = new Vector();
	    description_d = new Vector();
	    
	    // Initialize local Matrix objects
	    W = new Matrix();
	    LDA = new Matrix();
	    CLDA = new Matrix();
	    B = new Matrix();
	    S = new Matrix();
	    invW = new Matrix();
d56 2a57 18	    // Add the process description for the LDA algorithm
	    if (description_d.size() == 0)
	    {
		String str = new String("   0. Initialize the original data.");
		description_d.addElement(str);
		
		str = new String("   1. Displaying the original data.");
		description_d.addElement(str);
		
		str = new String("   2. Computing the means and covariance.");
		description_d.addElement(str);
		
		str = new String("   3. Computing the decision regions based on the class independent LDA algorithm.");
		description_d.addElement(str);
	    }

	    // append message to process box
	    pro_box_d.appendMessage("Class Independent LDA Analysis:" + "\n");
d59 2a60 5	    // set the data points for this algorithm
	    set1_d = (Vector)data_points_d.dset1.clone();
	    set2_d = (Vector)data_points_d.dset2.clone();
	    set3_d = (Vector)data_points_d.dset3.clone();
	    set4_d = (Vector)data_points_d.dset4.clone();

⌨️ 快捷键说明

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