classify.java,v

来自「包含了模式识别中常用的一些分类器设计算法」· JAVA,V 代码 · 共 1,436 行 · 第 1/3 页

JAVA,V
1,436
字号
		// init the algorithm	//	return true;	    }    /**     * determine the dimensions of the selection area     * actually this draws a line of width 3 pixels in either directions     * in way, this draws a + sign..     * 3 pixels because, -3 /2 and + 3 / 2 on either side.     *     * @@param   device_a  graphics object used     * @@param   point_a   point which will be displayed     * @@param   type_a    integer describing type     * @@param   color_a   color of the point     *     * @@return  true     *     */  static public boolean drawPoint(				  Graphics device_a,				  Point point_a,				  int type_a,				  Color color_a)    {	int X, Y;		Color curr_color = device_a.getColor();	device_a.setColor(color_a);		X = (int)point_a.x;	Y = (int)point_a.y;		// draw different point	//	switch (type_a)	{	case PTYPE_INPUT :	    device_a.drawLine(X - 3 / 2, Y, X + 3 / 2, Y);	    device_a.drawLine(X, Y - 3 / 2, X, Y + 3 / 2);	    device_a.setColor(curr_color);	    break;	    	case PTYPE_OUTPUT :	    break;	    	case PTYPE_SUPPORT_VECTOR :	    device_a.setColor(color_a);	    device_a.drawOval(X - 5 / 2, Y - 5 / 2, 5, 5);	    device_a.setColor(curr_color);	    break;	    	case PTYPE_OUTPUT_LARGE :	    device_a.setColor(color_a);	    device_a.fillOval(X - 5 / 2, Y - 5 / 2, 5, 5);	    device_a.setColor(curr_color);	    break;	    	default :	    break;	}		// reset the color	//	device_a.setColor(curr_color);		// init the algorithm	//	return true;    }    /**     * determine the dimensions of the selection area     *     * @@param   device_a  graphics object used     * @@param   points_a  points which will be displayed     * @@param   type_a    integer describing type     * @@param   color_a   color of the point     *     * @@return  true     *     */    static public boolean drawPoints(				     Graphics device_a,				     Vector points_a,				     int type_a,				     Color color_a)    {	// put the code here for drawing lines..	if (type_a == PTYPE_LINE)	{	    putLines(device_a, points_a, type_a, color_a);	}		if (type_a != PTYPE_LINE)	{	    for (int i = 0; i < points_a.size(); i++)	    {   		drawPoint(device_a, (Point)points_a.get(i), type_a, color_a);	    }	}	// init the algorithm	//	return true;    }        /**     * Method : putlines     * Method to draw a line between a series of points. The lines sequentially     * connect the first point to the second then the second to the third,     * til the last point.     *     * @@param   device_a  graphics object used     * @@param   points_a  points which will be displayed     * @@param   type_a    integer describing type     * @@param   color_a   color of the point     *     * @@return  true     */    static public boolean putLines (				    Graphics device_a,				    Vector points_a, 				    int type_a,				    Color color_a)    {		for (int i = 0; i < points_a.size() - 1; i++)	{	    putLine(device_a, (Point)points_a.get(i), (Point)points_a.get(i + 1), color_a);	}	return true;    }        /**     * Method to draw a line between two points. The method is called     * for putting a single line at a time by method putlines which is used      * to draw lines between a series of points     *     * @@param   device_a  graphics object used     * @@param   first_pt_a Line begining point     * @@param   second_pt_a Line ending point     * @@param   color_a The color of the line     *     * @@return  boolean     */    static public boolean putLine (				   Graphics device_a,				   Point first_pt_a, 				   Point second_pt_a,				   Color color_a)    {	Color curr_color = device_a.getColor();	device_a.setColor(color_a);		int X1 = 0;	int X2 = 0;	int Y1 = 0;	int Y2 = 0;		X1 = (int) first_pt_a.x;	X2 = (int) second_pt_a.x;	Y1 = (int) first_pt_a.y;	Y2 = (int) second_pt_a.y;		// draw line between two consecutive points	//	device_a.drawLine(X1, Y1, X2, Y2);	device_a.drawLine(X1 - 1 / 2, Y1, X2 - 1 / 2, Y2);	device_a.drawLine(X1 + 1 / 2, Y1, X2 + 1 / 2, Y2);	device_a.setColor(curr_color);		return true;    } }@1.6log@Fixed Javadoc comments.@text@d8 1d37 1a37 1    Vector url_vec_d = new Vector(5, 1);d57 1a57 1    static Vector algo_vec_d = new Vector();d66 1a66 1    static int algo_index_particle_d = -1;d106 1a106 1	algo_vec_d = new Vector();d115 1a115 1	algo_index_particle_d = -1;d367 4@1.5log@line # 144 replaced * by a // for comments@text@d4 2a16 1* class: Classifyd96 1a96 7     * method: Classify     *     * @@param    none     * @@return   none     *     * class default constructor     *a148 1       * @@return  voida182 5     * method: init     *     * @@param   none     * @@return  none     *d373 1a373 6     * method: DetermineDimensions      *     * @@param   none     * @@return  none     *     * determine the dimensions of the selection aread390 1a390 4     * method: getCurrAlgo     *     * @@param   none     * @@return  Object d392 1a392 1     * determine the current algorithm and returns an object for itd406 1a406 1     * method: initializeAlgod408 2a409 4     * @@param    Algorithm - The algorithm to he initialized     * @@return   boolean     *     * determine the dimensions of the selection areaa428 6     * method: drawpoint     *     * @@param   Point - point location which will be put     * @@param   Color - color of the point     * @@return  boolean     *d434 7d495 1a495 1     * method: drawPointsd497 4a500 3     * @@param   Vector - A group of points which are put on the display     * @@param   Color  - The color of the point marked     * @@return  booleand502 1a502 1     * determine the dimensions of the selection aread536 6a541 3     * @@param   Vector - Group of points in cartesian coordinate system.     * @@param   Color - The color of the line     * @@return  booleana557 1     * method : putlined562 5a566 3     * @@param   Point - Line begining point     * @@param   Point - Line ending point     * @@param   Color - The color of the line@1.4log@Changed the comments to suit the Java Documentation Style.@text@d97 2a98 2     * @@param none     * @@returns  : noned144 5a148 5  * *********************************************************************  *  * declare class methods  *  * *********************************************************************d153 2a154 2       * @@param args command line arguments       * @@return void@1.3log@No major changes. The comments put earlier by me [sanjay] were removed. TeThe comments were related to the plus sign and line thickness.methods drawPoints and drawPoint.@text@d1 4a4 2// file: Classify.java//d14 10a23 12//These imports are not needed - Phil T. 6-23-03//import java.awt.event.*;//import java.io.*; // class: Classify//// Classify is the main driver program that extend JApplet and is the // class called when the applet is loaded, which inturn initialize all// other objects and components need to run the applet//// hierarchy: JApplet->Classify//d47 58d106 15a120 27  // declare components  //  static MainMenu main_menu_d;  static ProcessBox pro_box_d = new ProcessBox();  static DataPoints input_points_d = new DataPoints();  static InputPanel input_panel_d = new InputPanel(input_points_d);  static OutputPanel output_panel_d = new OutputPanel();  static Vector algo_vec_d = new Vector();  static int algo_index_d = -1;  static int algo_index_svm_d = -1;  static int algo_index_pcaci_d = -1;  static int algo_index_pca2_d = -1;  static int algo_index_rvm_d = -1;  static int algo_index_ldapca1_d = -1;//   static int algo_index_ldapca2_d = -1;  static int algo_index_particle_d = -1;  static int algo_index_lp_d = -1;  // Phil T. - Added   static int algo_index_ldaci_d = -1;  static int algo_index_lda2_d = -1;  static int algo_index_ed_d = -1;  static int algo_index_nn_d = -1;  static int algo_index_kmeans_d = -1;  static int algo_index_lbg_d = -1;  // d122 21d144 54a197 28  // *********************************************************************  //  // declare non-static variables and components  //  // *********************************************************************  JPanel content_pane_d = new JPanel();  int width_d = 0; // width of the canvas  int height_d = 0; // height of the canvas  int zero_x_d = 0; // zero position on x axis  int zero_y_d = 0; // zero position on y axis  // *********************************************************************  //  // declare class constructors  //  // *********************************************************************  // method: Classify  //  // arguments: none  // returns  : none  //  // class default constructor  //  public void preInit()d200 1a200 15    pro_box_d = new ProcessBox();    input_points_d = new DataPoints();    input_panel_d = new InputPanel(input_points_d);    output_panel_d = new OutputPanel();    algo_vec_d = new Vector();    algo_index_d = -1;    algo_index_svm_d = -1;    algo_index_pcaci_d = -1;    algo_index_pca2_d = -1;    algo_index_rvm_d = -1;    algo_index_ldapca1_d = -1;//     algo_index_ldapca2_d = -1;    algo_index_particle_d = -1;    algo_index_lp_d = -1;d202 1a202 36    // set the sizes of the input and output panels and process box    //    input_panel_d.setSize(new Dimension(30, 40));    input_panel_d.setPreferredSize(new Dimension(30, 40));    input_panel_d.setMinimumSize(new Dimension(30, 40));    input_panel_d.setMaximumSize(new Dimension(30, 40));    output_panel_d.setSize(new Dimension(30, 40));    output_panel_d.setPreferredSize(new Dimension(30, 40));    output_panel_d.setMinimumSize(new Dimension(30, 40));    output_panel_d.setMaximumSize(new Dimension(30, 40));    pro_box_d.setSize(new Dimension(50, 80));    pro_box_d.setPreferredSize(new Dimension(50, 80));    pro_box_d.setMinimumSize(new Dimension(50, 80));    pro_box_d.setMaximumSize(new Dimension(50, 80));    getRootPane().putClientProperty(      "defeatSystemEventQueueCheck",      Boolean.TRUE);  }  // *********************************************************************  //  // declare class methods  //  // *********************************************************************  /**   * main method, the entrance of the program   *    * @@param args command line arguments   * @@return void   */  public static void main(String[] args)  {d204 1a204 3    try    {      // set the look and feeld206 14a219 8      //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());    } catch (Exception e)    {}    Classify frame = new Classify();    frame.setSize(new Dimension(480, 520));    frame.init();    //frame.pack();d221 2a222 12    //Center the window    //    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();    Dimension frameSize = frame.getSize();    if (frameSize.height > screenSize.height)      frameSize.height = screenSize.height;    if (frameSize.width > screenSize.width)      frameSize.width = screenSize.width;

⌨️ 快捷键说明

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