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

📄 pairwiseselector.java

📁 wekaUT是 university texas austin 开发的基于weka的半指导学习(semi supervised learning)的分类器
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	strPair.class1 = pair.instance1.classValue();	strPair.class2 = pair.instance2.classValue();	negPairDistances[negCounter++] = addUniquePair(strPairSet, strPair);      }          }         return negPairDistances;  }      /** Populate m_posPairList with all positive InstancePair's */  protected void createPosPairList() {    // go through lists of instances for each class and create a list of *all* positive pairs    m_posPairList = new ArrayList();    Iterator iterator = m_classInstanceMap.values().iterator();    while (iterator.hasNext()) {      ArrayList instanceList = (ArrayList) iterator.next();      // create all same-class pairs for every true object      for (int i = 0; i < instanceList.size(); i++) {	Instance instance1 = (Instance) instanceList.get(i);	for (int j = i+1; j < instanceList.size(); j++) {	  Instance instance2 = (Instance) instanceList.get(j);	  InstancePair pair = new InstancePair(instance1, instance2, true, 0);	  m_posPairList.add(pair);	}      }    }  }  /** Populate m_negPairList with negative InstancePair's */  protected void createNegPairList() {    m_negPairList = new ArrayList();    // go through lists of instances for each class    for (int i = 0; i < m_classValueList.size(); i++) {      ArrayList instanceList1 = (ArrayList) m_classInstanceMap.get(m_classValueList.get(i));      for (int j = 0; j < instanceList1.size(); j++) {	Instance instance1 = (Instance) instanceList1.get(j);	// create all pairs from other clusters with this str	for (int k = i+1; k < m_classValueList.size(); k++) {	  ArrayList instanceList2 = (ArrayList) m_classInstanceMap.get(m_classValueList.get(k));	  for (int l = 0; l < instanceList2.size(); l++) {	    Instance instance2 = (Instance) instanceList2.get(l);	    InstancePair pair = new InstancePair(instance1, instance2, false, 0);	    m_negPairList.add(pair);	  }	}      }    }  }    /** Given a set, return a TreeSet whose items are accessed in descending order   * @param set any set containing Comparable objects   * @return a new ordered set with those objects in reverse order   */  public TreeSet reverseCopy(Set set) {    TreeSet reverseSet = new TreeSet(new ReverseComparator());    reverseSet.addAll(set);    return reverseSet;  }  /** Set the selection mode for positives   * @param mode selection mode for positive examples   */  public void setPositivesMode(SelectedTag mode) {    if (mode.getTags() == TAGS_POS_MODE) {      m_positivesMode = mode.getSelectedTag().getID();    }  }  /**   * return the selection mode for positives   * @return one of the selection modes   */  public SelectedTag getPositivesMode() {    return new SelectedTag(m_positivesMode, TAGS_POS_MODE);  }  /** Set the selection mode for negatives   * @param mode selection mode for negative examples   */  public void setNegativesMode(SelectedTag mode) {    if (mode.getTags() == TAGS_NEG_MODE) {      m_negativesMode = mode.getSelectedTag().getID();    }  }  /**   * return the selection mode for negatives   * @return one of the selection modes   */  public SelectedTag getNegativesMode() {    return new SelectedTag(m_negativesMode, TAGS_NEG_MODE);  }  /**   * Set the maximum fraction of common tokens that instances can have to   * be included as implicit negatives   * @param maxImplicitCommonTokenFraction   */  public void setMaxImplicitCommonTokenFraction(double maxImplicitCommonTokenFraction) {    m_maxImplicitCommonTokenFraction = maxImplicitCommonTokenFraction;  }   /**   * Get the maximum fraction of common tokens that instances can have to   * be included as implicit negatives   * @return the fraction   */  public double getMaxImplicitCommonTokenFraction() {    return m_maxImplicitCommonTokenFraction;  }    /** Turn using rejected positives as negatives on/off   * @param useRejectedPositives if true, false positives that were picked during the   * static-active selection will be added to the negatives set   */  public void setUseRejectedPositives(boolean useRejectedPositives) {    m_useRejectedPositives = useRejectedPositives;  }  /** Check whether using rejected positives as negatives is on or off   * @return returns true if false positives that were picked during   * the static-active selection are added to the negatives set   */  public boolean getUseRejectedPositives() {    return m_useRejectedPositives;  }  /** Turn using false implicit negatives on/off   * @param useFalseImplicitNegatives if true, false implicit negatives will be added to  positives   */  public void setUseFalseImplicitNegatives(boolean useFalseImplicitNegatives) {    m_useFalseImplicitNegatives = useFalseImplicitNegatives;  }  /** Check whether using false implicit negatives is on/off   * @return true if false implicit negatives are added to  positives   */  public boolean getUseFalseImplicitNegatives() {    return m_useFalseImplicitNegatives;  }    /** Set the selection mode for positive string examples   * @param mode selection mode for positive  string examples   */  public void setPosStringMode(SelectedTag mode) {    if (mode.getTags() == TAGS_STRING_PAIR_MODE) {      m_posStringMode = mode.getSelectedTag().getID();    }  }  /**   * return the selection mode for positive string examples   * @return one of the selection modes for positive  string examples   */  public SelectedTag getPosStringMode() {    return new SelectedTag(m_posStringMode, TAGS_STRING_PAIR_MODE);  }    /** Set the selection mode for negative string examples   * @param mode selection mode for negative  string examples   */  public void setNegStringMode(SelectedTag mode) {    if (mode.getTags() == TAGS_STRING_PAIR_MODE) {      m_negStringMode = mode.getSelectedTag().getID();    }  }  /**   * return the selection mode for negative string examples   * @return one of the selection modes for negative  string examples   */  public SelectedTag getNegStringMode() {    return new SelectedTag(m_negStringMode, TAGS_STRING_PAIR_MODE);  }      /** Turn debugging output on/off   * @param debug if true, debugging info will be printed   */  public void setDebug(boolean debug) {    m_debug = debug;  }  /** See whether debugging output is on/off   * @returns if true, debugging info will be printed   */  public boolean getDebug() {    return m_debug;  }    /**   * get an array random indeces out of n possible values.   * if the number of requested indeces is larger then maxIdx, returns   * maxIdx permuted values   * @param maxIdx - the maximum index of the set   * @param numIdxs number of indexes to return   * @return an array of indexes   */  public static int[] randomSubset(int numIdxs, int maxIdx) {    Random r = new Random(maxIdx + numIdxs);    int[] indeces = new int[maxIdx];    for (int i = 0; i < maxIdx; i++) {      indeces[i] = i;    }    // permute the indeces randomly    for (int i = 0; i < indeces.length; i++) {      int idx = r.nextInt (maxIdx);      int temp = indeces[idx];      indeces[idx] = indeces[i];      indeces[i] = temp;    }    int []returnIdxs = new int[Math.min(numIdxs,maxIdx)];    for (int i = 0; i < returnIdxs.length; i++) {      returnIdxs[i] = indeces[i];    }    return returnIdxs;  }  /** return true if two strings have commmon tokens */  public static boolean haveCommonTokens(String s1, String s2) {    String delimiters = " \t\n\r\f\'\"\\!@#$%^&*()_-+={}<>,.;:|[]{}/*~`";        HashSet tokenSet1 = new HashSet();     StringTokenizer tokenizer = new StringTokenizer(s1, delimiters);    while (tokenizer.hasMoreTokens()) {      String token = tokenizer.nextToken();      tokenSet1.add(token);    }    int count = 0;     tokenizer = new StringTokenizer(s2, delimiters);    while (tokenizer.hasMoreTokens()) {      String token = tokenizer.nextToken();      if (tokenSet1.contains(token)) {	count++;	if (count > 0) {	  return true;	}      }    }    return false;  }   /** return the number of commmon tokens that two strings have   * @param s1 string 1   * @param s2 string 2   * @return the number of common tokens the strings have   */  public static double fractionCommonTokens(String s1, String s2) {    String delimiters = " \t\n\r\f\'\"\\!@#$%^&*()_-+={}<>,.;:|[]{}/*~`";        HashSet tokenSet1 = new HashSet();    int commonTokens = 0;    int totalTokens = 0;        StringTokenizer tokenizer = new StringTokenizer(s1, delimiters);    while (tokenizer.hasMoreTokens()) {      String token = tokenizer.nextToken();      tokenSet1.add(token);      totalTokens++;    }    tokenizer = new StringTokenizer(s2, delimiters);    while (tokenizer.hasMoreTokens()) {      String token = tokenizer.nextToken();      if (tokenSet1.contains(token)) {	commonTokens++;      }      totalTokens++;    }    return ((commonTokens + 0.0)/totalTokens);  }       /**   * Gets the current settings of WeightedDotP.   *   * @return an array of strings suitable for passing to setOptions()   */  public String [] getOptions() {    String [] options = new String [10];    int current = 0;    switch(m_positivesMode) {    case POS_MODE_RANDOM_RECORDS:      options[current++] = "-Pr";      break;    case POS_MODE_RANDOM_POSITIVES:      options[current++] = "-Pp";      break;    case POS_MODE_STATIC_ACTIVE:      if (m_useRejectedPositives) { 	options[current++] = "-PsN";      } else {	options[current++] = "-Ps";      }      break;    }    switch(m_negativesMode) {    case NEG_MODE_RANDOM_RECORDS:      options[current++] = "-Nr";      break;    case NEG_MODE_RANDOM_NEGATIVES:      options[current++] = "-Nn";      break;    case NEG_MODE_IMPLICIT_NEGATIVES:      if (m_useFalseImplicitNegatives) { 	options[current++] = "-NiP" + m_maxImplicitCommonTokenFraction;      } else {	options[current++] = "-Ni" + m_maxImplicitCommonTokenFraction;      }      break;    }        switch(m_posStringMode) {    case STRING_PAIRS_RANDOM:      options[current++] = "-SPr";      break;    case STRING_PAIRS_HARDEST:      options[current++] = "-SPh";      break;    case STRING_PAIRS_EASIEST:      options[current++] = "-SPe";      break;    }    switch(m_negStringMode) {    case STRING_PAIRS_RANDOM:      options[current++] = "-SNr";      break;    case STRING_PAIRS_HARDEST:      options[current++] = "-SNh";      break;    case STRING_PAIRS_EASIEST:      options[current++] = "-SNe";      break;    }        while (current < options.length) {      options[current++] = "";    }    return options;  }    /**   * Parses a given list of options. Valid options are:<p>   *   */  public void setOptions(String[] options) throws Exception {  }  /**   * Returns an enumeration describing the available options.   *   * @return an enumeration of all the available options.   */  public Enumeration listOptions() {    Vector newVector = new Vector(0);    return newVector.elements();  }}

⌨️ 快捷键说明

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