pairedttester.java

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

JAVA
1,963
字号
								      comparisonColumn);			result.append(Utils.padLeft("",4));			result.append(Utils.doubleToString(pairedStats.xStats.mean,							   meanWidth, m_Precision));			if (m_ShowStdDevs) {			    if (Double.isInfinite(pairedStats.xStats.stdDev)) {				result.append('(' + Utils.padRight("Inf", stdWidth)					      +')');			    } else {				result.append('('+Utils.doubleToString(pairedStats.xStats.stdDev,								       stdWidth,m_Precision)					      +')');			    }			}		    }catch (Exception ex) {			ex.printStackTrace();		    }		}else{//if the point was not tested print spaces		    result.append(Utils.padLeft("",resultsetLength));		}	    }	    result.append("\n");	}	result.append("\n\n");	return result.toString();    }    //=============== END EDIT melville ===============    //=============== BEGIN EDIT melville ===============  /**   * Creates a comparison table where a base resultset is compared to the   * other resultsets. Results are presented for every dataset.   *   * @param baseResultset the index of the base resultset   * @param comparisonColumn the index of the column to compare over   * @return the comparison table string   * @exception Exception if an error occurs   */    public String multiResultsetPercentErrorReduction(int baseResultset,							  int comparisonColumn) throws Exception {	StringBuffer result = new StringBuffer(1000);        if(getNumResultsets()==1){//no comparison to be made - just display one learning curve	    int maxWidthMean = 2;	    int maxWidthStdDev = 2;	    // determine max field width	    for (int i = 0; i < getNumDatasets(); i++) {		for (int j = 0; j < getNumResultsets(); j++) {		    try {			PairedStats pairedStats = 			    calculateStatistics(m_DatasetSpecifiers.specifier(i), 						baseResultset, j, comparisonColumn);			if (!Double.isInfinite(pairedStats.yStats.mean) &&			    !Double.isNaN(pairedStats.yStats.mean)) {			    double width = ((Math.log(Math.abs(pairedStats.yStats.mean)) / 					     Math.log(10))+1);			    if (width > maxWidthMean) {				maxWidthMean = (int)width;			    }			}			if (m_ShowStdDevs &&			    !Double.isInfinite(pairedStats.yStats.stdDev) &&			    !Double.isNaN(pairedStats.yStats.stdDev)) {			    double width = ((Math.log(Math.abs(pairedStats.yStats.stdDev)) / 					     Math.log(10))+1);			    if (width > maxWidthStdDev) {				maxWidthStdDev = (int)width;			    }			}		    }  catch (Exception ex) {			ex.printStackTrace();		    }		}	    }	    result = new StringBuffer(oneResultsetFullLearningPlainText(baseResultset, 									comparisonColumn, 									maxWidthMean,									maxWidthStdDev));	}	else	    result = new StringBuffer(multiResultsetPercentErrorReductionPlainText(baseResultset, 										   comparisonColumn));    	// append a key so that we can tell the difference between long	// scheme+option names	result.append("\nKey:\n\n");	for (int j = 0; j < getNumResultsets(); j++) {	    result.append("("+(j+1)+") ");	    result.append(getResultsetName(j)+"\n");	}	return result.toString();    }//=============== END EDIT melville ===============    //=============== BEGIN EDIT melville ===============    /**     * Generates percentage error reduction tables across learning curves     *     * @param baseResultset the index of the base resultset     * @param comparisonColumn the index of the column to compare over     * @return the comparison table string     */    private String multiResultsetPercentErrorReductionPlainText(int baseResultset,								int comparisonColumn) {		StringBuffer result = new StringBuffer(1000);	//Compute column widths for pretty printing	int datasetLength = 20;	int meanWidth = 3; 	if(m_Precision>0) meanWidth += (1 + m_Precision); //account for the decimal point and decimal digits	int resultsetLength = 2*meanWidth;	int maxPointWidth = 6;	int numPts = m_Points.length;		//Find maximum point width - assuming the points are in order	maxPointWidth = (int) (Math.log(m_Points[m_Points.length-1])/Math.log(10)) + 1;	if(maxPointWidth<6) maxPointWidth=6;		Vector datasetNames = new Vector();//store names of dataset	HashMap specMap = new HashMap();//maps dataset:point pair to a unique specifier		for (int i = 0; i < getNumDatasets(); i++) {	    Instance spec = m_DatasetSpecifiers.specifier(i);	    String dataName = spec.toString(m_DatasetKeyColumns[0]);	    String point = spec.toString(m_DatasetKeyColumns[1]);	    if(!datasetNames.contains(dataName)){		datasetNames.add(dataName);	    }	    specMap.put(dataName+":"+point, spec);	}			StringBuffer titles;	for (int j = 0; j < getNumResultsets(); j++) {//For each system comparison	    //Generate a different table comparing pts across the learning curve with the base system	    	    if (j == baseResultset) continue;	    	    //Display title	    titles = new StringBuffer();	    titles.append("Comparing "+Utils.padLeft("(" + (j + 1)+ ") "+ getResultsetName(j),						     15)+" to "+			  Utils.padRight("(" + (baseResultset + 1)+ ") "+ getResultsetName(baseResultset),					 15));	    result.append(titles.toString()).append("\n\n");	    	    //Display table headings	    result.append("Dataset\n");	    if(m_Fraction)		result.append(Utils.padLeft("% Points",datasetLength));	    else		result.append(Utils.padLeft("Points",datasetLength));	    /****************************************	     * Uncomment out the block below, if you want the error	     * reductions displayed for each point on the curve.	     ****************************************/	    //  	    for(int pts=0; pts<numPts; pts++){	    //  		if(m_Fraction)	    //  		    result.append(Utils.padLeft(Utils.doubleToString(m_Points[pts]*100,meanWidth,2),resultsetLength));	    //  		else	    //  		    result.append(Utils.padLeft(Utils.doubleToString(m_Points[pts],meanWidth,2),resultsetLength));	    //  	    }	    //  	    result.append("\n");	    //  	    result.append(Utils.padLeft("",datasetLength));	    //  	    for(int pts=0; pts<numPts; pts++)	    //  		for(int k=0; k<resultsetLength; k++)	    //  		    result.append("-");  	    result.append("\n");	    	    int datasetCtr = 0;	    double errorReduction;	    double datasetSum = 0.0;//sum of avg error reduction across datasets	    for(int dataIndex=0; dataIndex<datasetNames.size(); dataIndex++){//for each dataset		double r_sum = 0.0;//sum across the row		int r_ctr = 0;//num of pts in the row (this can be less than numPts)		result.append(Utils.padRight((String)datasetNames.get(dataIndex), datasetLength));				for(int ptIndex=0; ptIndex<m_Points.length; ptIndex++){//for each point on the curve		    String key = datasetNames.get(dataIndex)+":"+(new Double(m_Points[ptIndex]));		    Object obj = specMap.get(key);		    if(!m_Fraction && obj==null){ 			key = datasetNames.get(dataIndex)+":"+(new Integer((int) m_Points[ptIndex]));			obj = specMap.get(key);		    }		    if(obj!=null){//if the point was recorded			Instance specifier = (Instance) obj;			try {			    PairedStats pairedStats =  calculateStatistics(specifier, baseResultset, j, comparisonColumn);			    double yVal = pairedStats.yStats.mean;			    pairedStats = calculateStatistics(specifier, baseResultset, baseResultset, comparisonColumn);			    double xVal = pairedStats.xStats.mean;			    if(yVal == 0 && xVal == 0)				errorReduction = 0;			    else				errorReduction = (1.0 - yVal/xVal)*100.0;			    //Check if errorReduction is NaN or Inf - else			    //result.append(Utils.padLeft(Utils.doubleToString(errorReduction,meanWidth,m_Precision),resultsetLength));			    r_sum += errorReduction;			    r_ctr++;			}catch (Exception ex) {			    ex.printStackTrace();			}		    }else{//if the point was not tested print spaces			//result.append(Utils.padLeft("",resultsetLength));		    }		}		if(r_ctr>0){		    datasetCtr++;		    double r_avg = r_sum/r_ctr;		    datasetSum += r_avg;		    result.append(" | "+Utils.padLeft(Utils.doubleToString(r_avg,meanWidth,m_Precision),resultsetLength-3));		}		    result.append("\n");	    }	    String s="";	    for(int k=0; k<meanWidth; k++)		s = s + "-";	    /****************************************	     * Uncomment out the block below, if you want the error	     * reductions displayed for each point on the curve.	     ****************************************/	    //  	    result.append(Utils.padLeft(s,datasetLength+resultsetLength*(numPts+1)));	    //  	    result.append("\n");	    //  	    result.append(Utils.padLeft(Utils.doubleToString(datasetSum/datasetCtr,meanWidth,m_Precision),datasetLength+resultsetLength*(numPts+1))+"\n\n\n");	    result.append(Utils.padLeft(s,datasetLength+resultsetLength));	    result.append("\n");	    result.append(Utils.padLeft(Utils.doubleToString(datasetSum/datasetCtr,meanWidth,m_Precision),datasetLength+resultsetLength)+"\n\n\n");	}    	return result.toString();    }    //=============== END EDIT melville ===============	    //=============== BEGIN EDIT melville ===============  /**   * Creates a comparison table where a base resultset is compared to the   * other resultsets. Results are presented for every dataset.   *   * @param baseResultset the index of the base resultset   * @param comparisonColumn the index of the column to compare over   * @param nFraction top n fraction of error reductions are averaged   * @return the comparison table string   * @exception Exception if an error occurs */    public String multiResultsetTopNPercentErrorReduction(int baseResultset,							  int comparisonColumn, double nFraction) throws Exception {		StringBuffer result = new StringBuffer(1000);        if(getNumResultsets()==1){//no comparison to be made - just display one learning curve	    int maxWidthMean = 2;	    int maxWidthStdDev = 2;	    // determine max field width	    for (int i = 0; i < getNumDatasets(); i++) {		for (int j = 0; j < getNumResultsets(); j++) {		    try {			PairedStats pairedStats = 			    calculateStatistics(m_DatasetSpecifiers.specifier(i), 						baseResultset, j, comparisonColumn);			if (!Double.isInfinite(pairedStats.yStats.mean) &&			    !Double.isNaN(pairedStats.yStats.mean)) {			    double width = ((Math.log(Math.abs(pairedStats.yStats.mean)) / 					     Math.log(10))+1);			    if (width > maxWidthMean) {				maxWidthMean = (int)width;			    }			}			if (m_ShowStdDevs &&			    !Double.isInfinite(pairedStats.yStats.stdDev) &&			    !Double.isNaN(pairedStats.yStats.stdDev)) {			    double width = ((Math.log(Math.abs(pairedStats.yStats.stdDev)) / 					     Math.log(10))+1);			    if (width > maxWidthStdDev) {				maxWidthStdDev = (int)width;			    }			}		    }  catch (Exception ex) {			ex.printStackTrace();		    }		}	    }	    result = new StringBuffer(oneResultsetFullLearningPlainText(baseResultset, 									comparisonColumn, 									maxWidthMean,									maxWidthStdDev));	}	else{	    result = new StringBuffer(multiResultsetTopNPercentErrorReductionPlainText(baseResultset, 										       comparisonColumn, nFraction));	}		// append a key so that we can tell the difference between long	// scheme+option names	result.append("\nKey:\n\n");	for (int j = 0; j < getNumResultsets(); j++) {	    result.append("("+(j+1)+") ");	    result.append(getResultsetName(j)+"\n");	}	return result.toString();    }//=============== END EDIT melville ===============    //=============== BEGIN EDIT melville ===============    /**     * Generates percentage error reduction tables across learning curves     *     * @param baseResultset the index of the base resultset     * @param comparisonColumn the index of the column to compare over     * @param nFraction top n fraction of error reductions are averaged     * @return the comparison table string     */    private String multiResultsetTopNPercentErrorReductionPlainText(int baseResultset,								    int comparisonColumn, double nFraction) {		StringBuffer result = new StringBuffer(1000);	//Compute column widths for pretty printing	int datasetLength = 20;	int meanWidth = 3; 	if(m_Precision>0) meanWidth += (1 + m_Precision); //account for the decimal point and decimal digits	int resultsetLength = 2*meanWidth;	int maxPointWidth = 6;	int numPts = m_Points.length;		//Find maximum point width - assuming the points are in order	maxPointWidth = (int) (Math.log(m_Points[m_Points.length-1])/Math.log(10)) + 1;	if(maxPointWidth<6) maxPointWidth=6;		Vector datasetNames = new Vector();//store names of dataset	HashMap specMap = new HashMap();//maps dataset:point pair to a unique specifier		for (int i = 0; i < getNumDatasets(); i++) {	    Instance spec = m_DatasetSpecifiers.specifier(i);	    String dataName = spec.toString(m_DatasetKeyColumns[0]);	    String point = spec.toString(m_DatasetKeyColumns[1]);	    if(!datasetNames.contains(dataName)){		datasetNames.add(dataName);	    }	    specMap.put(dataName+":"+point, spec);	}		StringBuffer titles;	for (int j = 0; j < getNumResultsets(); j++) {//For each system comparison	    //Generate a different table comparing pts across the learning curve with the base system	    	    if (j == baseResultset) continue;	    	    //Display title	    titles = new StringBuffer();	    titles.append("Comparing "+Utils.padLeft("(" + (j + 1)+ ") "+ getResultsetName(j),						     15)+" to "+			  Utils.padRight("(" + (baseResultset + 1)+ ") "+ getResultsetName(baseResultset),					 15));	    result.append(titles.toString()).append("\n\n");	    	    //Display table headings	    result.append("Dataset\n");	    if(m_Fraction)		result.append(Utils.padLeft("% Points",datasetLength));	    else		result.append(Utils.padLeft("Points",datasetLength));	    /****************************************	     * Uncomment out the block below, if you want the error	     * reductions displayed for each point on the curve.	     ****************************************/	    	    //  	    for(int pts=0; pts<numPts; pts++){	    //  		if(m_Fraction)	    //  		    result.append(Utils.padLeft(Utils.doubleToString(m_Points[pts]*100,meanWidth,2),resultsetLength));	    //  		else	    //  		    result.append(Utils.padLeft(Utils.doubleToString(m_Points[pts],meanWidth,2),resultsetLength));	    //  	    }	    //  	    result.append("\n");	    //  	    result.append(Utils.padLeft("",datasetLength));	    //  	    for(int pts=0; pts<numPts; pts++)	    //  		for(int k=0; k<resultsetLength; k++)	    //  		    result.append("-");	    result.append("\n");	    	    int datasetCtr = 0;	    double errorReduction;	    	    Triple []ptsErrorReduction = new Triple[numPts];//stores error reductions at each point and t-test results	    double datasetSum = 0.0;//sum of avg error reduction across datasets	    for(int dataIndex=0; dataIndex<datasetNames.size(); dataIndex++){//for each dataset		int r_ctr = 0;

⌨️ 快捷键说明

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