pairedttester.java

来自「wekaUT是 university texas austin 开发的基于wek」· Java 代码 · 共 1,963 行 · 第 1/5 页

JAVA
1,963
字号
  /**   * Returns true if standard deviations have been requested.   * @return true if standard deviations are to be displayed.   */  public boolean getShowStdDevs() {    return m_ShowStdDevs;  }          //=============== BEGIN EDIT melville ===============    /**     * Returns true if learning curves have to be analyzed      * @return true if learning curves have to be analyzed      */    public boolean getLearningCurve() {	return m_LearningCurve;    }        /**     * Set to true if learning curves are to be analyzed     * @param v  Value to assign to m_LearningCurve.     */    public void setLearningCurve(boolean  v) {	this.m_LearningCurve = v;    }        /**     * Set to true if fractions are specified for learning curves     * @param f  Value to assign to m_Fraction.     */    public void setFraction(boolean f){	this.m_Fraction = f;    }        /**     * Returns true if fractions are specified for learning curves     * @return true if fractions are specified for learning curves     */    public boolean getFraction(){	return m_Fraction;    }        /**     * Get the points on the learning curve     * @return value of points on the learning curve     */    public double [] getPoints() {	return m_Points;    }        /**     * Set the points on the learning curve     * @param v  Value to points on the learning curve     */    public void setPoints(double []  v) {	this.m_Points = v;    }    //=============== END EDIT melville ===============      /**   * Separates the instances into resultsets and by dataset/run.   *   * @exception Exception if the TTest parameters have not been set.   */  protected void prepareData() throws Exception {    if (m_Instances == null) {      throw new Exception("No instances have been set");    }    if (m_RunColumnSet == -1) {      m_RunColumn = m_Instances.numAttributes() - 1;    } else {      m_RunColumn = m_RunColumnSet;    }    if (m_ResultsetKeyColumnsRange == null) {      throw new Exception("No result specifier columns have been set");    }    m_ResultsetKeyColumnsRange.setUpper(m_Instances.numAttributes() - 1);    m_ResultsetKeyColumns = m_ResultsetKeyColumnsRange.getSelection();    if (m_DatasetKeyColumnsRange == null) {      throw new Exception("No dataset specifier columns have been set");    }    m_DatasetKeyColumnsRange.setUpper(m_Instances.numAttributes() - 1);    m_DatasetKeyColumns = m_DatasetKeyColumnsRange.getSelection();        //  Split the data up into result sets    m_Resultsets.removeAllElements();      m_DatasetSpecifiers.removeAllSpecifiers();    for (int i = 0; i < m_Instances.numInstances(); i++) {      Instance current = m_Instances.instance(i);      if (current.isMissing(m_RunColumn)) {	throw new Exception("Instance has missing value in run "			    + "column!\n" + current);      }       for (int j = 0; j < m_ResultsetKeyColumns.length; j++) {	if (current.isMissing(m_ResultsetKeyColumns[j])) {	  throw new Exception("Instance has missing value in resultset key "			      + "column " + (m_ResultsetKeyColumns[j] + 1)			      + "!\n" + current);	}      }      for (int j = 0; j < m_DatasetKeyColumns.length; j++) {	if (current.isMissing(m_DatasetKeyColumns[j])) {	  throw new Exception("Instance has missing value in dataset key "			      + "column " + (m_DatasetKeyColumns[j] + 1)			      + "!\n" + current);	}      }      boolean found = false;      for (int j = 0; j < m_Resultsets.size(); j++) {	Resultset resultset = (Resultset) m_Resultsets.elementAt(j);	if (resultset.matchesTemplate(current)) {	  resultset.add(current);	  found = true;	  break;	}      }      if (!found) {	Resultset resultset = new Resultset(current);	m_Resultsets.addElement(resultset);      }      m_DatasetSpecifiers.add(current);    }    // Tell each resultset to sort on the run column    for (int j = 0; j < m_Resultsets.size(); j++) {      Resultset resultset = (Resultset) m_Resultsets.elementAt(j);      resultset.sort(m_RunColumn);    }    m_ResultsetsValid = true;  }  /**   * Gets the number of datasets in the resultsets   *   * @return the number of datasets in the resultsets   */  public int getNumDatasets() {    if (!m_ResultsetsValid) {      try {	prepareData();      } catch (Exception ex) {	ex.printStackTrace();	return 0;      }    }    return m_DatasetSpecifiers.numSpecifiers();  }  /**   * Gets the number of resultsets in the data.   *   * @return the number of resultsets in the data   */  public int getNumResultsets() {    if (!m_ResultsetsValid) {      try {	prepareData();      } catch (Exception ex) {	ex.printStackTrace();	return 0;      }    }    return m_Resultsets.size();  }  /**   * Gets a string descriptive of the specified resultset.   *   * @param index the index of the resultset   * @return a descriptive string for the resultset   */  public String getResultsetName(int index) {    if (!m_ResultsetsValid) {      try {	prepareData();      } catch (Exception ex) {	ex.printStackTrace();	return null;      }    }    return ((Resultset) m_Resultsets.elementAt(index)).templateString();  }    /**   * Computes a paired t-test comparison for a specified dataset between   * two resultsets.   *   * @param datasetSpecifier the dataset specifier   * @param resultset1Index the index of the first resultset   * @param resultset2Index the index of the second resultset   * @param comparisonColumn the column containing values to compare   * @return the results of the paired comparison   * @exception Exception if an error occurs   */  public PairedStats calculateStatistics(Instance datasetSpecifier,				     int resultset1Index,				     int resultset2Index,				     int comparisonColumn) throws Exception {    if (m_Instances.attribute(comparisonColumn).type()	!= Attribute.NUMERIC) {      throw new Exception("Comparison column " + (comparisonColumn + 1)			  + " ("			  + m_Instances.attribute(comparisonColumn).name()			  + ") is not numeric");    }    if (!m_ResultsetsValid) {      prepareData();    }    Resultset resultset1 = (Resultset) m_Resultsets.elementAt(resultset1Index);    Resultset resultset2 = (Resultset) m_Resultsets.elementAt(resultset2Index);    FastVector dataset1 = resultset1.dataset(datasetSpecifier);    FastVector dataset2 = resultset2.dataset(datasetSpecifier);    String datasetName = templateString(datasetSpecifier);    if (dataset1 == null) {      throw new Exception("No results for dataset=" + datasetName			 + " for resultset=" + resultset1.templateString());    } else if (dataset2 == null) {      throw new Exception("No results for dataset=" + datasetName			 + " for resultset=" + resultset2.templateString());    } else if (dataset1.size() != dataset2.size()) {      throw new Exception("Results for dataset=" + datasetName			  + " differ in size for resultset="			  + resultset1.templateString()			  + " and resultset="			  + resultset2.templateString()			  );    }        PairedStats pairedStats = new PairedStats(m_SignificanceLevel);    for (int k = 0; k < dataset1.size(); k ++) {      Instance current1 = (Instance) dataset1.elementAt(k);      Instance current2 = (Instance) dataset2.elementAt(k);      if (current1.isMissing(comparisonColumn)) {	throw new Exception("Instance has missing value in comparison "			    + "column!\n" + current1);      }      if (current2.isMissing(comparisonColumn)) {	throw new Exception("Instance has missing value in comparison "			    + "column!\n" + current2);      }      if (current1.value(m_RunColumn) != current2.value(m_RunColumn)) {	System.err.println("Run numbers do not match!\n"			    + current1 + current2);      }      double value1 = current1.value(comparisonColumn);      double value2 = current2.value(comparisonColumn);      pairedStats.add(value1, value2);    }    pairedStats.calculateDerived();    return pairedStats;  }      //=============== END EDIT melville ===============  /**   * Computes a paired t-test comparison for a specified dataset between   * two resultsets.   *   * @param datasetSpecifier the dataset specifier   * @param resultset1Index the index of the first resultset   * @param resultset2Index the index of the second resultset   * @param comparisonColumn the column containing values to compare   * @param pairedStats stats that are being accumulated   * @return the results of the paired comparison   * @exception Exception if an error occurs   */  public PairedStats accumulateStatistics(Instance datasetSpecifier,					 int resultset1Index,					 int resultset2Index,					 int comparisonColumn, PairedStats pairedStats) throws Exception {    if (m_Instances.attribute(comparisonColumn).type()	!= Attribute.NUMERIC) {      throw new Exception("Comparison column " + (comparisonColumn + 1)			  + " ("			  + m_Instances.attribute(comparisonColumn).name()			  + ") is not numeric");    }    if (!m_ResultsetsValid) {      prepareData();    }    Resultset resultset1 = (Resultset) m_Resultsets.elementAt(resultset1Index);    Resultset resultset2 = (Resultset) m_Resultsets.elementAt(resultset2Index);    FastVector dataset1 = resultset1.dataset(datasetSpecifier);    FastVector dataset2 = resultset2.dataset(datasetSpecifier);    String datasetName = templateString(datasetSpecifier);    if (dataset1 == null) {      throw new Exception("No results for dataset=" + datasetName			 + " for resultset=" + resultset1.templateString());    } else if (dataset2 == null) {      throw new Exception("No results for dataset=" + datasetName			 + " for resultset=" + resultset2.templateString());    } else if (dataset1.size() != dataset2.size()) {      throw new Exception("Results for dataset=" + datasetName			  + " differ in size for resultset="			  + resultset1.templateString()			  + " and resultset="			  + resultset2.templateString()			  );    }        //PairedStats pairedStats = new PairedStats(m_SignificanceLevel);    for (int k = 0; k < dataset1.size(); k ++) {      Instance current1 = (Instance) dataset1.elementAt(k);      Instance current2 = (Instance) dataset2.elementAt(k);      if (current1.isMissing(comparisonColumn)) {	throw new Exception("Instance has missing value in comparison "			    + "column!\n" + current1);      }      if (current2.isMissing(comparisonColumn)) {	throw new Exception("Instance has missing value in comparison "			    + "column!\n" + current2);      }      if (current1.value(m_RunColumn) != current2.value(m_RunColumn)) {	System.err.println("Run numbers do not match!\n"			    + current1 + current2);      }      double value1 = current1.value(comparisonColumn);      double value2 = current2.value(comparisonColumn);      pairedStats.add(value1, value2);    }        return pairedStats;  }    //=============== END EDIT melville ===============  /**   * Creates a key that maps resultset numbers to their descriptions.   *   * @return a value of type 'String'   */  public String resultsetKey() {    if (!m_ResultsetsValid) {      try {	prepareData();      } catch (Exception ex) {	ex.printStackTrace();	return ex.getMessage();      }    }    String result = "";    for (int j = 0; j < getNumResultsets(); j++) {      result += "(" + (j + 1) + ") " + getResultsetName(j) + '\n';    }    return result + '\n';  }    /**   * Creates a "header" string describing the current resultsets.   *   * @param comparisonColumn a value of type 'int'   * @return a value of type 'String'   */  public String header(int comparisonColumn) {    if (!m_ResultsetsValid) {      try {	prepareData();      } catch (Exception ex) {	ex.printStackTrace();	return ex.getMessage();      }    }    return "Analysing:  "      + m_Instances.attribute(comparisonColumn).name() + '\n'      + "Datasets:   " + getNumDatasets() + '\n'      + "Resultsets: " + getNumResultsets() + '\n'      + "Confidence: " + getSignificanceLevel() + " (two tailed)\n"      + "Date:       " + (new SimpleDateFormat()).format(new Date()) + "\n\n";  }    /**   * Creates a "header" string describing the current resultsets.   *   * @param comparisonField comparison field 

⌨️ 快捷键说明

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