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

📄 gridsearch.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @return 		the right border     */    public double getMaxX() {      return m_MaxX;    }        /**     * returns the step size on the X axis     *      * @return 		the step size     */    public double getStepX() {      return m_StepX;    }        /**     * returns the label for the X axis     *      * @return		the label     */    public String getLabelX() {      return m_LabelX;    }        /**     * returns the bottom border     *      * @return 		the bottom border     */    public double getMinY() {      return m_MinY;    }        /**     * returns the top border     *      * @return 		the top border     */    public double getMaxY() {      return m_MaxY;    }        /**     * returns the step size on the Y axis     *      * @return 		the step size     */    public double getStepY() {      return m_StepY;    }        /**     * returns the label for the Y axis     *      * @return		the label     */    public String getLabelY() {      return m_LabelY;    }        /**     * returns the number of points in the grid on the Y axis (incl. borders)     *      * @return 		the number of points in the grid on the Y axis     */    public int height() {      return m_Height;    }        /**     * returns the number of points in the grid on the X axis (incl. borders)     *      * @return 		the number of points in the grid on the X axis     */    public int width() {      return m_Width;    }    /**     * returns the values at the given point in the grid     *      * @param x		the x-th point on the X axis     * @param y		the y-th point on the Y axis     * @return		the value pair at the given position     */    public PointDouble getValues(int x, int y) {      if (x >= width())	throw new IllegalArgumentException("Index out of scope on X axis (" + x + " >= " + width() + ")!");      if (y >= height())	throw new IllegalArgumentException("Index out of scope on Y axis (" + y + " >= " + height() + ")!");            return new PointDouble(m_MinX + m_StepX*x, m_MinY + m_StepY*y);    }    /**     * returns the closest index pair for the given value pair in the grid.     *      * @param values	the values to get the indices for     * @return		the closest indices in the grid     */    public PointInt getLocation(PointDouble values) {      PointInt	result;      int	x;      int	y;      double	distance;      double	currDistance;      int	i;      // determine x      x        = 0;      distance = m_StepX;      for (i = 0; i < width(); i++) {	currDistance = StrictMath.abs(values.getX() - getValues(i, 0).getX());	if (currDistance < distance) {	  distance = currDistance;	  x        = i;	}      }            // determine y      y        = 0;      distance = m_StepY;      for (i = 0; i < height(); i++) {	currDistance = StrictMath.abs(values.getY() - getValues(0, i).getY());	if (currDistance < distance) {	  distance = currDistance;	  y        = i;	}      }            result = new PointInt(x, y);      return result;    }    /**     * checks whether the given values are on the border of the grid     *      * @param values		the values to check     * @return			true if the the values are on the border     */    public boolean isOnBorder(PointDouble values) {      return isOnBorder(getLocation(values));    }    /**     * checks whether the given location is on the border of the grid     *      * @param location 		the location to check     * @return			true if the the location is on the border     */    public boolean isOnBorder(PointInt location) {      if (location.getX() == 0)	return true;      else if (location.getX() == width() - 1)	return true;      if (location.getY() == 0)	return true;      else if (location.getY() == height() - 1)	return true;      else	return false;    }        /**     * returns a subgrid with the same step sizes, but different borders     *      * @param top	the top index     * @param left	the left index     * @param bottom	the bottom index     * @param right	the right index     * @return 		the Sub-Grid     */    public Grid subgrid(int top, int left, int bottom, int right) {      return new Grid(                   getValues(left, top).getX(), getValues(right, top).getX(), getStepX(), getLabelX(),                   getValues(left, bottom).getY(), getValues(left, top).getY(), getStepY(), getLabelY());    }        /**     * returns an extended grid that encompasses the given point (won't be on     * the border of the grid).     *      * @param values	the point that the grid should contain     * @return		the extended grid     */    public Grid extend(PointDouble values) {      double	minX;      double	maxX;      double	minY;      double	maxY;      double	distance;            // left      if (values.getX() <= getMinX()) {	distance = getMinX() - values.getX();	// exactly on grid point?	if (StrictMath.floor(distance / getStepX()) == StrictMath.round(distance / getStepX()))	  minX = getMinX() - getStepX() * (StrictMath.round(distance / getStepX()) + 1);	else	  minX = getMinX() - getStepX() * (StrictMath.round(distance / getStepX()));      }      else {	minX = getMinX();      }            // right      if (values.getX() >= getMaxX()) {	distance = values.getX() - getMaxX();	// exactly on grid point?	if (StrictMath.floor(distance / getStepX()) == StrictMath.round(distance / getStepX()))	  maxX = getMaxX() + getStepX() * (StrictMath.round(distance / getStepX()) + 1);	else	  maxX = getMaxX() + getStepX() * (StrictMath.round(distance / getStepX()));      }      else {	maxX = getMaxX();      }            // bottom      if (values.getY() <= getMinY()) {	distance = getMinY() - values.getY();	// exactly on grid point?	if (StrictMath.floor(distance / getStepY()) == StrictMath.round(distance / getStepY()))	  minY = getMinY() - getStepY() * (StrictMath.round(distance / getStepY()) + 1);	else	  minY = getMinY() - getStepY() * (StrictMath.round(distance / getStepY()));      }      else {	minY = getMinY();      }            // top      if (values.getY() >= getMaxY()) {	distance = values.getY() - getMaxY();	// exactly on grid point?	if (StrictMath.floor(distance / getStepY()) == StrictMath.round(distance / getStepY()))	  maxY = getMaxY() + getStepY() * (StrictMath.round(distance / getStepY()) + 1);	else	  maxY = getMaxY() + getStepY() * (StrictMath.round(distance / getStepY()));      }      else {	maxY = getMaxY();      }            return new Grid(minX, maxX, getStepX(), getLabelX(), minY, maxY, getStepY(), getLabelY());    }        /**     * returns an Enumeration over all pairs in the given row     *      * @param y		the row to retrieve     * @return		an Enumeration over all pairs     * @see #getValues(int, int)     */    public Enumeration<PointDouble> row(int y) {      Vector	result;      int	i;            result = new Vector();            for (i = 0; i < width(); i++)	result.add(getValues(i, y));            return result.elements();    }        /**     * returns an Enumeration over all pairs in the given column     *      * @param x		the column to retrieve     * @return		an Enumeration over all pairs     * @see #getValues(int, int)     */    public Enumeration<PointDouble> column(int x) {      Vector	result;      int	i;            result = new Vector();            for (i = 0; i < height(); i++)	result.add(getValues(x, i));            return result.elements();    }        /**     * returns a string representation of the grid     *      * @return a string representation     */    public String toString() {      String	result;            result  = "X: " + m_MinX + " - " + m_MaxX + ", Step " + m_StepX;      if (m_LabelX.length() != 0)	result += " (" + m_LabelX + ")";      result += "\n";            result += "Y: " + m_MinY + " - " + m_MaxY + ", Step " + m_StepY;      if (m_LabelY.length() != 0)	result += " (" + m_LabelY + ")";      result += "\n";      result += "Dimensions (Rows x Columns): " + height() + " x " + width();            return result;    }  }      /**   * A helper class for storing the performance of a values-pair.   * Can be sorted with the PerformanceComparator class.   *    * @see PerformanceComparator   */  protected class Performance    implements Serializable {    /** for serialization */    private static final long serialVersionUID = -4374706475277588755L;        /** the value pair the classifier was built with */    protected PointDouble m_Values;        /** the Correlation coefficient */    protected double m_CC;        /** the Root mean squared error */    protected double m_RMSE;        /** the Root relative squared error */    protected double m_RRSE;        /** the Mean absolute error */    protected double m_MAE;        /** the Relative absolute error */    protected double m_RAE;        /** the Accuracy */    protected double m_ACC;        /**     * initializes the performance container     *      * @param values		the values-pair     * @param evaluation	the evaluation to extract the performance     * 				measures from     * @throws Exception	if retrieving of measures fails     */    public Performance(PointDouble values, Evaluation evaluation) throws Exception {      super();            m_Values = values;            m_RMSE  = evaluation.rootMeanSquaredError();      m_RRSE  = evaluation.rootRelativeSquaredError();      m_MAE   = evaluation.meanAbsoluteError();      m_RAE   = evaluation.relativeAbsoluteError();      try {	m_CC = evaluation.correlationCoefficient();      }      catch (Exception e) {	m_CC = Double.NaN;      }      try {	m_ACC = evaluation.pctCorrect();      }      catch (Exception e) {	m_ACC = Double.NaN;      }    }        /**     * returns the performance measure     *      * @param evaluation	the type of measure to return     * @return 			the performance measure     */    public double getPerformance(int evaluation) {      double	result;            result = Double.NaN;            switch (evaluation) {	case EVALUATION_CC:	  result = m_CC;	  break;	case EVALUATION_RMSE:	  result = m_RMSE;	  break;	case EVALUATION_RRSE:	  result = m_RRSE;	  break;	case EVALUATION_MAE:	  result = m_MAE;	  break;	case EVALUATION_RAE:	  result = m_RAE;	  break;	case EVALUATION_COMBINED:	  result = (1 - StrictMath.abs(m_CC)) + m_RRSE + m_RAE;	  break;	case EVALUATION_ACC:	  result = m_ACC;	  break;	default:	  throw new IllegalArgumentException("Evaluation type '" + evaluation + "' not supported!");      }            return result;    }        /**     * returns the values-pair for this performance     *      * @return the values-pair     */    public PointDouble getValues() {      return m_Values;    }        /**     * returns a string representation of this performance object     *      * @param evaluation	the type of performance to return     * @return 			a string representation     */    public String toString(int evaluation) {      String	result;            result =   "Performance (" + getValues() + "): "       	       + getPerformance(evaluation)       	       + " (" + new SelectedTag(evaluation, TAGS_EVALUATION) + ")";            return result;    }        /**     * returns a Gnuplot string of this performance object     *      * @param evaluation	the type of performance to return     * @return 			the gnuplot string (x, y, z)     */    public String toGnuplot(int evaluation) {      String	result;            result =   getValues().getX() + "\t"       	       + getValues().getY() + "\t"      	       + getPerformance(evaluation);            return result;    }        /**     * returns a string representation of this performance object     * 

⌨️ 快捷键说明

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