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

📄 datapoints.java

📁 包含了模式识别中常用的一些分类器设计算法
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* file: DataPoints.java * *  last edited: Ryan Irwin * */// import necessary java libraries//import java.awt.*;import java.util.*;import javax.swing.*;//These imports are not needed - Phil T. 6-23-03//import javax.swing.*;//import java.awt.event.*;//import java.applet.Applet;/** * class holds the input DataPoints classes that are to be classified as well * as the classification algorithms needed to compute the decision regions * */public class DataPoints{        // *********************************************************************    //    // declare global variables and components    //    // *********************************************************************        static final int DTYPE_USER_SELECTED = 0;           // declare vectors needed to store the set points    //    int set_index_d = 1;    int type_d = DTYPE_USER_SELECTED;    int selectFlag = 0;    int selStartX = 0;    int selStartY = 0;    int selEndX = 0;    int selEndY = 0;    // the set with double value    //    Vector<MyPoint> dset1;    Vector<MyPoint> dset2;    Vector<MyPoint> dset3;    Vector<MyPoint> dset4;    // colors for each set    //    Color color_dset1 = Color.red;      Color color_dset2 = Color.green;    Color color_dset3 = Color.blue;    Color color_dset4 = Color.orange;    // gaussian setup    //      int points = 25;    double cov11 = 0.05;    double cov12 = 0;    double cov21 = 0;    double cov22 = 0.05;    // Scale values    //    // double xmin = -10.0;    // double xmax = 10.0;    // double ymin = -10.0;    // double ymax = 10.0;       /**     * initializes the samples to be plotted in the signal panel by calling     * initialize()     *     */    DataPoints()    {		// initialize the data set 	//	initialize();	    }        // *********************************************************************    //    // declare class methods    //    // *********************************************************************        /**     * initializes dset1-dset4     *     * @return   true     */    public boolean initialize()    {		// initialize the data set 	//	dset1 = new Vector<MyPoint>(40, 20);	dset2 = new Vector<MyPoint>(40, 20);	dset3 = new Vector<MyPoint>(40, 20);	dset4 = new Vector<MyPoint>(40, 20);		return true;    }        /**     * method returns true if valid data is present else it returns false     *     * @return     true if data is valid     */    public boolean isDataValid()    {	// check if valid data is present in the first data set	//	if (dset1.size() > 0)	{	    return true;	}		// check if valid data is present in the second data set	//	if (dset2.size() > 0)	{	    return true;	}	// check if valid data is present in the third data set	//	if (dset3.size() > 0)	{	    return true;	}		// check if valid data is present in the fourth data set	//	if (dset4.size() > 0)	{	    return true;	}		// indicate that no valid data is present	//	return false;    }        /**     * clear out all point form the data sets     *     */    public void clearAllSets()    {		if (dset1.size() > 0)	{	    dset1.removeAllElements();	}	if (dset2.size() > 0)	{	    dset2.removeAllElements();	}	if (dset3.size() > 0)	{	    dset3.removeAllElements();	}	if (dset4.size() > 0)	{	    dset4.removeAllElements();	}    }        /**     * add a point to the data set that is determined by the index (setNum)     *     * @param  p  point to be added to the input data class     *     */    public void addPoint(MyPoint p)    {			selectFlag = 0;	switch (set_index_d)	{	    	    case 1 :    		dset1.addElement(p);		break;			    case 2 :		dset2.addElement(p);		break;	    case 3 :		dset3.addElement(p);		break;	    	    case 4 :		dset4.addElement(p);		break;	}    }        /**      * Draws Gaussian distribution by calling setGaussian()     *     * @param  meanx double x value of mean point     * @param  meany double y value of mean point     * @param  scale DisplayScale variable used for displaying     */    public void drawGaussian(double meanx, double meany, DisplayScale scale )    {	setGaussian(points, meanx, meany, cov11, cov12, cov21, cov22, scale);    }        /**     * creates a set of point that correspond to a gaussians distribution     *     * @param    points max points in the distribution     * @param    meanx mean (x) of the distribution     * @param    meany mean (y) of the distribution     * @param    c11 covariance matrix element c11     * @param    c12 covariance matrix element c12     * @param    c21 covariance matrix element c21     * @param    c22 covariance matrix element c22     * @param    scale DisplayScale variable     *     *     */    public void setGaussian(			    int points,			    double meanx,			    double meany,			    double c11,			    double c12,			    double c21,			    double c22,			    DisplayScale scale)    {	// declare local variables	//	double xmax, xmin, ymax, ymin;  	double[] xval = null;	double[] yval = null;	BiNormal bn = new BiNormal();	// initialize variables	//	xmax = scale.xmax;	xmin = scale.xmin;	ymax = scale.ymax;	ymin = scale.ymin;	xval = new double[points];	yval = new double[points];	// determine the ratio of pixels per seconds	//	//double xpixsec = input_width_a / (xmax - xmin);	//double ypixsec = input_height_a / (ymax - ymin);	// generate the binormal gaussian random deviates	//	bn.gaussian(points, meanx, meany, xval, yval, c11, c12, c21, c22);	// format the point to be plotted on the screen	//	//Vector dist = new Vector(points);	Vector<MyPoint> samp = new Vector<MyPoint>(points);		for (int i = 0; i < points; i++)	{    	    if (set_index_d == 1)	    {		dset1.addElement(new MyPoint(xval[i], yval[i]));	    } 	    else if (set_index_d == 2)	    {		dset2.addElement(new MyPoint(xval[i], yval[i]));	    } 	    else if (set_index_d == 3)	    {		dset3.addElement(new MyPoint(xval[i], yval[i]));	    } 	    else	    {		dset4.addElement(new MyPoint(xval[i], yval[i]));	    }	    	}		// for (int i = 0; i < points; i++)	//{	// int xpixel = (int) ((input_width_a / 2) + (xpixsec * xval[i]));	// int ypixel = (int) ((input_width_a / 2) - (ypixsec * yval[i]));	// dist.addElement(new Point(xpixel, ypixel));	// samp.addElement(new MyPoint(xval[i], yval[i]));	//}		// clone the distribution to the appropriate data set	    }    /**     * create a set of point that correspond to two gaussians to     * be displayed on the input canvas     *     * @param scale DisplayScale variable used for displaying     */    public void setTwoGaussian(DisplayScale scale)    {	// declare local variables	//	double xmax, xmin, ymax, ymin;  	int maxsize = 0;	double[] xval = null;	double[] yval = null;	BiNormal bn = new BiNormal();	// initialize variables	//	xmax = scale.xmax;	xmin = scale.xmin;	ymax = scale.ymax;	ymin = scale.ymin;	maxsize = 200    ;	xval = new double[maxsize];	yval = new double[maxsize];	// generate the binormal gaussian random deviates	//	bn.gaussian(		    maxsize,		    xmin + (xmax - xmin) / 4.0,		    ymax - (ymax - ymin) / 4.0,		    xval,		    yval,		    ((0.1 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4),		    0.0,		    0.0,		    ((0.1 * (ymax - ymin)) / 4) * (((ymax - ymin)) / 4));	// format the point to be plotted on the screen	//	Vector<MyPoint> first = new Vector<MyPoint>(maxsize);	for (int i = 0; i < maxsize; i++)	{	    first.addElement(new MyPoint(xval[i], yval[i]));	}	// generate the binormal gaussian random deviates	//	bn.gaussian(		    maxsize,		    xmax - (xmax - xmin) / 4,		    ymin + (ymax - ymin) / 4,		    xval,		    yval,		    ((0.1 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4),		    0.0,		    0.0,		    ((0.1 * (ymax - ymin)) / 4) * (((ymax - ymin)) / 4));		// format the point to be plotted on the screen	//	Vector<MyPoint> second = new Vector<MyPoint>(maxsize);	for (int i = 0; i < maxsize; i++)	{	    second.addElement(new MyPoint(xval[i], yval[i]));	}	dset1 = first;	dset2 = second;    }    /**     * create a set of point that correspond to four gaussians to     * be displayed on the input canvas     * method: setFourGaussian     *     * @param scale DisplayScale variable used for displaying     *     */  public void setFourGaussian(DisplayScale scale)  {      // local variables      //      double xmax, xmin, ymax, ymin;        int maxsize = 0;      double[] xval = null;      double[] yval = null;      BiNormal bn = new BiNormal();      // initialize variables      //      xmax = scale.xmax;      xmin = scale.xmin;      ymax = scale.ymax;      ymin = scale.ymin;      maxsize = 200;      xval = new double[maxsize];      yval = new double[maxsize];      // generate the binormal gaussian random deviates      //      bn.gaussian(		  maxsize,		  xmax - (xmax - xmin) / 4.0,		  ymax - (ymax - ymin) / 4.0,		  xval,		  yval,		  ((0.1 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4),		  0.0,		  0.0,		  ((0.1 * (ymax - ymin)) / 4) * (((ymax - ymin)) / 4));      // format the point to be plotted on the screen      //      Vector<MyPoint> first = new Vector<MyPoint>(maxsize);      for (int i = 0; i < maxsize; i++)      {	  first.addElement(new MyPoint(xval[i], yval[i]));      }      // generate the binormal gaussian random deviates      //      bn.gaussian(		  maxsize,		  xmin + (xmax - xmin) / 4.0,		  ymax - (ymax - ymin) / 4.0,		  xval,		  yval,		  ((0.1 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4),		  0.0,		  0.0,		  ((0.1 * (ymax - ymin)) / 4) * (((ymax - ymin)) / 4));            // format the point to be plotted on the screen      //      Vector<MyPoint> second = new Vector<MyPoint>(maxsize);      for (int i = 0; i < maxsize; i++)      {	  second.addElement(new MyPoint(xval[i], yval[i]));      }            // generate the binormal gaussian random deviates      //      bn.gaussian(		  maxsize,		  xmin + (xmax - xmin) / 4.0,		  ymin + (ymax - ymin) / 4.0,		  xval,		  yval,		  ((0.1 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4),		  0.0,		  0.0,		  ((0.1 * (ymax - ymin)) / 4) * (((ymax - ymin)) / 4));      // format the point to be plotted on the screen      //      Vector<MyPoint> third = new Vector<MyPoint>(maxsize);      for (int i = 0; i < maxsize; i++)      {	  third.addElement(new MyPoint(xval[i], yval[i]));      }      // generate the binormal gaussian random deviates      //      bn.gaussian(		  maxsize,		  xmax - (xmax - xmin) / 4.0,		  ymin + (ymax - ymin) / 4.0,		  xval,		  yval,		  ((0.1 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4),		  0.0,		  0.0,		  ((0.1 * (ymax - ymin)) / 4) * (((ymax - ymin)) / 4));      // format the point to be plotted on the screen      //      Vector<MyPoint> forth = new Vector<MyPoint>(maxsize);      for (int i = 0; i < maxsize; i++)      {	  forth.addElement(new MyPoint(xval[i], yval[i]));      }            dset1 = first;      dset2 = second;      dset3 = third;      dset4 = forth;  }        /**     * create a set of point that correspond to two overlapped gaussians to     * be displayed on the input canvas     *     * @param scale DisplayScale variable used for displaying     *     */    public void setOverGaussian(DisplayScale scale)    {	// local variables	//	double xmax, xmin, ymax, ymin;  	int maxsize = 0;	double[] xval = null;	double[] yval = null;	BiNormal bn = new BiNormal();	// initialize variables	//	xmax = scale.xmax;	xmin = scale.xmin;	ymax = scale.ymax;	ymin = scale.ymin;	maxsize = 200;	xval = new double[maxsize];	yval = new double[maxsize];	// generate the binormal gaussian random deviates	//	bn.gaussian(		    maxsize,		    ((xmax - xmin) / 1.75 + xmin),		    ((ymax - ymin) / 2 + ymin),		    xval,		    yval,		    ((0.1 * (ymax - ymin)) / 4) * (((ymax - ymin)) / 4),		    0.0,		    0.0,		    ((0.1 * (ymax - ymin)) / 4) * (((ymax - ymin)) / 4));	// format the point to be plotted on the screen	//	Vector<MyPoint> first = new Vector<MyPoint>(maxsize);	for (int i = 0; i < maxsize; i++)	{	    first.addElement(new MyPoint(xval[i], yval[i]));	}	// generate the binormal gaussian random deviates	//	bn.gaussian(		    maxsize,		    (xmax - (xmax - xmin) / 1.75),		    ((ymax - ymin) / 2 + ymin),		    xval,		    yval,		    ((0.1 * (ymax - ymin)) / 4) * (((ymax - ymin)) / 4),		    0.0,		    0.0,		    ((0.1 * (ymax - ymin)) / 4) * (((ymax - ymin)) / 4));	// format the point to be plotted on the screen	//	Vector<MyPoint> second = new Vector<MyPoint>(maxsize);	for (int i = 0; i < maxsize; i++)	{	    second.addElement(new MyPoint(xval[i], yval[i]));	}		dset1 = first;	dset2 = second;    }        /**     * create a set of point that correspond to two ellipses to     * be displayed on the input canvas     *     * @param   scale DisplayScale variable used for displaying     */    public void setTwoEllipses(DisplayScale scale)    {		// local variables	//	double xmax, xmin, ymax, ymin;  

⌨️ 快捷键说明

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