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

📄 #semisuppairactivecurvecvresultproducer.java#

📁 wekaUT是 university texas austin 开发的基于weka的半指导学习(semi supervised learning)的分类器
💻 JAVA#
📖 第 1 页 / 共 3 页
字号:
			unlabeledTrain.deleteClassAttribute();			Instances unlabeledTest = new Instances (test);			unlabeledTest.deleteClassAttribute();			if (m_IsTransductive) {			  for (int i=0; i<test.numInstances(); i++) {				unlabeledTrain.add(unlabeledTest.instance(i));			  }			} 	    					Object [] seResults;			if (m_SplitEvaluator instanceof SemiSupClustererSplitEvaluator) {			  seResults = ((SemiSupClustererSplitEvaluator) m_SplitEvaluator).getResult(labeledTrainPairs, train, unlabeledTrain, test, unlabeledTest); 			}			else {			  throw new Exception("SplitEvaluator should be SemiSupClustererSplitEvaluator - SemiSupClassifierSplitEvaluator not yet implemented");			}			Object [] results = new Object [seResults.length + 1];			results[0] = getTimestamp();			System.arraycopy(seResults, 0, results, 1,							 seResults.length);			if (m_debugOutput) {			  String resultName = (""+run+"."+(fold+1)+"."+ m_CurrentSize + "." 								   + Utils.backQuoteChars(runInstances.relationName())								   +"."								   +m_SplitEvaluator.toString()).replace(' ','_');			  resultName = Utils.removeSubstring(resultName, 												 "weka.clusterers.");			  resultName = Utils.removeSubstring(resultName, 												 "weka.filters.");			  resultName = Utils.removeSubstring(resultName, 												 "weka.attributeSelection.");			  m_ZipDest.zipit(m_SplitEvaluator.getRawResultOutput(), resultName);			}			m_ResultListener.acceptResult(this, key, results);		  } catch (Exception ex) {			// Save the train and test datasets for debugging purposes?			throw ex;		  }		}		//  	PCKMeans pckmeans = (PCKMeans) ((SemiSupClustererSplitEvaluator)m_SplitEvaluator).getClusterer(); // KLUGE, will have to remove later!!		//  	HashSet[] indexClusters = pckmeans.getIndexClusters();		//  	for (int i = 0; i < indexClusters.length; i++) {		//  	  HashSet cluster = indexClusters[i];		//  	  if (cluster == null) {		//  	    System.out.println("Cluster " + i + " is null");		//  	  }		//  	  else {		//  	    System.out.println ("Cluster " + i + " consists of " + cluster.size() + " elements");		//  	    Iterator iter = cluster.iterator();		//  	    while (iter.hasNext()) {		//  	      int idx = ((Integer) iter.next()).intValue();		//  	      if (idx < train.numInstances()) {		//  		System.out.println("\t\t" + train.instance(idx).classValue());		//  	      }		//  	      else {		//  		System.out.println("\t\t" + test.instance(idx-train.numInstances()).classValue());		//  	      }		//  	    }		//  	  }		//  	}      		if (m_PlotPoints != null) {		  pointNum++;		  int oldCurrentSize = m_CurrentSize;		  m_CurrentSize = plotPoint(pointNum);		  if (m_DoActive && m_CurrentSize<maxTrainSize()) {			// Active learning done totally in clustering code now,			// only size of labeledTrainPairs is important			labeledTrainPairs = InstancePair.getPairs(train,													  m_CurrentSize,													  m_fractionMustLinks); 		  }		  else if (m_CurrentSize < maxTrainSize()) {			labeledTrainPairs = InstancePair.getPairs(train,													  m_CurrentSize,													  m_fractionMustLinks);		  }		}		else {		  int oldCurrentSize = m_CurrentSize;		  m_CurrentSize += m_StepSize;		  if (m_DoActive && m_CurrentSize<maxTrainSize()) {			// Active learning done totally in clustering code now,			// only size of labeledTrainPairs is important			labeledTrainPairs = InstancePair.getPairs(train,													  m_CurrentSize,													  m_fractionMustLinks); 		  }		  else if (m_CurrentSize < maxTrainSize()) {			labeledTrainPairs = InstancePair.getPairs(train,													  m_CurrentSize,													  m_fractionMustLinks);		  }		}      }    }  }  public ArrayList reorganizeTrainForActiveLearning(ArrayList trainPairs, int currentSize, InstancePair[] pairsForActiveLearning, Instances trainWithLabels) throws Exception{    for (int i=0; i<pairsForActiveLearning.length; i++) {      // Check that pairs for active learning have been correctly picked, not from test      if (pairsForActiveLearning[i].first >= trainWithLabels.numInstances() ||		  pairsForActiveLearning[i].second >= trainWithLabels.numInstances()) {		throw new Exception ("Something wrong ... asking for active learning on test!!");      }      else if (pairsForActiveLearning[i].first >= pairsForActiveLearning[i].second) {// first should be < second at this point		throw new Exception("Something wrong ... first >= second!!");      }      System.out.println("Now adding active learned: " + pairsForActiveLearning[i]);      trainPairs.add(pairsForActiveLearning[i]);    }    if (trainPairs.size() != currentSize) {      throw new Exception("Pair numbers do not match, something wrong!!");    }    return trainPairs;  }  /** Determines if the points specified are fractions of the total number of examples */  protected boolean setIsFraction(){    if (m_PlotPoints != null){      if(!isInteger(m_PlotPoints[0]))//if the first point is not an integer		m_IsFraction = true;      else		m_IsFraction = false;    }    return m_IsFraction;  }    /** Return the number of training examples for the ith point on the   * curve for plotPoints as specified.   */  protected int plotPoint(int i) {    // If i beyond number of given plot points return a value greater than maximum training size    if (i >= m_PlotPoints.length)      return maxTrainSize() + 1;    double point = m_PlotPoints[i];    // If plot point is an integer (other than a non-initial 1)    // treat it as a specific number of examples    if (isInteger(point) && !(Utils.eq(point, 1.0) && i!=0))      return (int)point;    else      // Otherwise, treat it as a percentage of the full set      return (int)Math.round(point * maxTrainSize());  }    /** Return true if the given double represents an integer value */  protected static boolean isInteger(double val) {    return Utils.eq(Math.floor(val), Math.ceil(val));  }    /**   * Gets the names of each of the columns produced for a single run.   * This method should really be static.   *   * @return an array containing the name of each column   */  public String [] getKeyNames() {    String [] keyNames = m_SplitEvaluator.getKeyNames();    // Add in the names of our extra key fields    int numExtraKeys;    if(m_IsFraction)      numExtraKeys = 5;    else       numExtraKeys = 4;    String [] newKeyNames = new String [keyNames.length + numExtraKeys];    newKeyNames[0] = DATASET_FIELD_NAME;    newKeyNames[1] = RUN_FIELD_NAME;    newKeyNames[2] = FOLD_FIELD_NAME;    newKeyNames[3] = STEP_FIELD_NAME;    if(m_IsFraction) newKeyNames[4] = FRACTION_FIELD_NAME;    System.arraycopy(keyNames, 0, newKeyNames, numExtraKeys, keyNames.length);    return newKeyNames;  }  /**   * Gets the data types of each of the columns produced for a single run.   * This method should really be static.   *   * @return an array containing objects of the type of each column. The    * objects should be Strings, or Doubles.   */  public Object [] getKeyTypes() {    Object [] keyTypes = m_SplitEvaluator.getKeyTypes();    int numExtraKeys;    if(m_IsFraction)      numExtraKeys = 5;    else       numExtraKeys = 4;    // Add in the types of our extra fields    Object [] newKeyTypes = new String [keyTypes.length + numExtraKeys];    newKeyTypes[0] = new String();    newKeyTypes[1] = new String();    newKeyTypes[2] = new String();    newKeyTypes[3] = new String();    if(m_IsFraction) newKeyTypes[4] = new String();    System.arraycopy(keyTypes, 0, newKeyTypes, numExtraKeys, keyTypes.length);    return newKeyTypes;  }  /**   * Gets the names of each of the columns produced for a single run.   * This method should really be static.   *   * @return an array containing the name of each column   */  public String [] getResultNames() {    String [] resultNames = m_SplitEvaluator.getResultNames();    // Add in the names of our extra Result fields    String [] newResultNames = new String [resultNames.length + 1];    newResultNames[0] = TIMESTAMP_FIELD_NAME;    System.arraycopy(resultNames, 0, newResultNames, 1, resultNames.length);    return newResultNames;  }  /**   * Gets the data types of each of the columns produced for a single run.   * This method should really be static.   *   * @return an array containing objects of the type of each column. The    * objects should be Strings, or Doubles.   */  public Object [] getResultTypes() {    Object [] resultTypes = m_SplitEvaluator.getResultTypes();    // Add in the types of our extra Result fields    Object [] newResultTypes = new Object [resultTypes.length + 1];    newResultTypes[0] = new Double(0);    System.arraycopy(resultTypes, 0, newResultTypes, 1, resultTypes.length);    return newResultTypes;  }  /**   * Gets a description of the internal settings of the result   * producer, sufficient for distinguishing a ResultProducer   * instance from another with different settings (ignoring   * those settings set through this interface). For example,   * a cross-validation ResultProducer may have a setting for the   * number of folds. For a given state, the results produced should   * be compatible. Typically if a ResultProducer is an OptionHandler,   * this string will represent the command line arguments required   * to set the ResultProducer to that state.   *   * @return the description of the ResultProducer state, or null   * if no state is defined   */  public String getCompatibilityState() {    String result = "-X " + m_NumFolds + " -S " + getStepSize() + 	  " -L " + getLowerSize() + " -U " + getUpperSize() + " ";    if (m_SplitEvaluator == null) {      result += "<null SplitEvaluator>";    } else {      result += "-W " + m_SplitEvaluator.getClass().getName();    }    return result + " --";  }  /**   * Returns the tip text for this property   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String outputFileTipText() {    return "Set the destination for saving raw output. If the rawOutput "      +"option is selected, then output from the splitEvaluator for "      +"individual folds is saved. If the destination is a directory, "      +"then each output is saved to an individual gzip file; if the "      +"destination is a file, then each output is saved as an entry "      +"in a zip file.";  }  /**   * Get the value of OutputFile.   *   * @return Value of OutputFile.   */  public File getOutputFile() {        return m_OutputFile;  }    /**   * Set the value of OutputFile.   *   * @param newOutputFile Value to assign to OutputFile.   */  public void setOutputFile(File newOutputFile) {        m_OutputFile = newOutputFile;  }    /**   * Returns the tip text for this property   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String numFoldsTipText() {    return "Number of folds to use in cross validation.";  }  /**   * Get the value of NumFolds.   *   * @return Value of NumFolds.   */  public int getNumFolds() {        return m_NumFolds;  }    /**   * Set the value of NumFolds.   *   * @param newNumFolds Value to assign to NumFolds.   */  public void setNumFolds(int newNumFolds) {        m_NumFolds = newNumFolds;  }  //    /**  //     * Get the active learning algorithm type.   //     *  //     * @returns the active learning method   //     */  //    public SelectedTag getActiveType ()  //    {  //        return new SelectedTag(m_ActiveType, TAGS_ACTIVE);  //    }  //    /**  //     * Set the active learning algorithm type.  //     *  //     * @param activeMethod the active learning method to use  //     */  //    public void setActiveType (SelectedTag activeMethod)  //    {  //      if (activeMethod.getTags() == TAGS_ACTIVE) {  //        System.out.println("Active learning method: " + activeMethod.getSelectedTag().getReadable());  //        m_ActiveType = activeMethod.getSelectedTag().getID();  //      }  //    }  /**   * Returns the tip text for this property   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String isTransductiveTipText() {    return "Whether evaluation is transductive or not.";  }  /**   * Get the value of IsTransductive.   *   * @return Value of IsTransductive.   */  public boolean getIsTransductive() {        return m_IsTransductive;  }    /**   * Set the value of IsTransductive.   *   * @param flag Value to assign to IsTransductive.   */  public void setIsTransductive(boolean flag) {        m_IsTransductive = flag;  }  /** Proportion of training pairs that are must-links   */  public double getFractionMustLinks() {    return m_fractionMustLinks;  }    public void setFractionMustLinks(double fractionMustLinks) {	if ((fractionMustLinks < 0 && fractionMustLinks != -1) || fractionMustLinks > 1) {	  System.err.println("Illegal value for fractionMustLinks: " + fractionMustLinks + " setting to -1");	  fractionMustLinks = -1;	}    this.m_fractionMustLinks = fractionMustLinks;  }    /**   * Returns the tip text for this property   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String DoActiveTipText() {    return "Whether active learning is performed or not.";  }  /**   * Get the value of m_DoActive.   *   * @return Value of m_DoActive.   */  public boolean getDoActive() {        return m_DoActive;  }    /**   * Set the value of m_DoActive.   *   * @param flag Value to assign to m_DoActive.   */  public void setDoActive(boolean flag) {        m_DoActive = flag;  }  /**   * Returns the tip text for this property   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */

⌨️ 快捷键说明

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