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

📄 osdlcore.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
   */  public void setClassificationType(SelectedTag value) {    if (value.getTags() == TAGS_CLASSIFICATIONTYPES)      m_ctype = value.getSelectedTag().getID();  }  /**    * Returns the classification type.   *   * @return the classification type   */  public SelectedTag getClassificationType() {    return new SelectedTag(m_ctype, TAGS_CLASSIFICATIONTYPES);  }  /**   * Returns the tip text for this property.   *   * @return tip text for this property suitable for    * displaying in the explorer/experimenter gui   */  public String tuneInterpolationParameterTipText() {    return "Whether to tune the interpolation parameter based on the bounds.";  }    /**   * Sets whether the interpolation parameter is to be tuned based on the   * bounds.   *    * @param value if true the parameter is tuned   */  public void setTuneInterpolationParameter(boolean value) {    m_tuneInterpolationParameter = value;  }    /**   * Returns whether the interpolation parameter is to be tuned based on the   * bounds.   *    * @return true if the parameter is to be tuned   */  public boolean getTuneInterpolationParameter() {    return m_tuneInterpolationParameter;  }  /**   * Returns the tip text for this property.   *   * @return tip text for this property suitable for    * displaying in the explorer/experimenter gui   */  public String interpolationParameterLowerBoundTipText() {    return "Sets the lower bound for the interpolation parameter tuning (0 <= x < 1).";  }    /**   * Sets the lower bound for the interpolation parameter tuning    * (0 &lt;= x &lt; 1).   *    * @param value the tne lower bound   * @throws IllegalArgumentException if bound is invalid   */  public void setInterpolationParameterLowerBound(double value) {    if ( (value < 0) || (value >= 1) || (value > getInterpolationParameterUpperBound()) )      throw new IllegalArgumentException("Illegal lower bound");        m_sLower = value;    m_tuneInterpolationParameter = true;    m_interpolationParameterValid = false;  }    /**   * Returns the lower bound for the interpolation parameter tuning   * (0 &lt;= x &lt; 1).   *    * @return the lower bound   */  public double getInterpolationParameterLowerBound() {    return m_sLower;  }  /**   * Returns the tip text for this property.   *   * @return tip text for this property suitable for    * displaying in the explorer/experimenter gui   */  public String interpolationParameterUpperBoundTipText() {    return "Sets the upper bound for the interpolation parameter tuning (0 < x <= 1).";  }    /**   * Sets the upper bound for the interpolation parameter tuning    * (0 &lt; x &lt;= 1).   *    * @param value the tne upper bound   * @throws IllegalArgumentException if bound is invalid   */  public void setInterpolationParameterUpperBound(double value) {    if ( (value <= 0) || (value > 1) || (value < getInterpolationParameterLowerBound()) )      throw new IllegalArgumentException("Illegal upper bound");        m_sUpper = value;    m_tuneInterpolationParameter = true;    m_interpolationParameterValid = false;  }    /**   * Returns the upper bound for the interpolation parameter tuning   * (0 &lt; x &lt;= 1).   *    * @return the upper bound   */  public double getInterpolationParameterUpperBound() {    return m_sUpper;  }    /**   * Sets the interpolation bounds for the interpolation parameter.   * When tuning the interpolation parameter only values in the interval   * <code> [sLow, sUp] </code> are considered.   * It is important to note that using this method immediately   * implies that the interpolation parameter is to be tuned.   *   * @param sLow lower bound for the interpolation parameter,    * should not be smaller than 0 or greater than <code> sUp </code>   * @param sUp upper bound for the interpolation parameter,   * should not exceed 1 or be smaller than <code> sLow </code>   * @throws IllegalArgumentException if one of the above conditions    * is not satisfied.   */  public void setInterpolationParameterBounds(double sLow, double sUp)     throws IllegalArgumentException {        if (sLow < 0. || sUp > 1. || sLow > sUp)       throw new IllegalArgumentException("Illegal upper and lower bounds");    m_sLower = sLow;    m_sUpper = sUp;    m_tuneInterpolationParameter = true;    m_interpolationParameterValid = false;  }  /**   * Returns the tip text for this property.   *   * @return tip text for this property suitable for    * displaying in the explorer/experimenter gui   */  public String interpolationParameterTipText() {    return "Sets the value of the interpolation parameter s;"    + "Estimated distribution is s * f_min + (1 - s) *  f_max. ";  }  /**   * Sets the interpolation parameter.  This immediately means that   * the interpolation parameter is not to be tuned.   *   * @param s value for the interpolation parameter.   * @throws IllegalArgumentException if <code> s </code> is not in   * the range [0,1].   */  public void setInterpolationParameter(double s)     throws IllegalArgumentException {        if (0 > s || s > 1)      throw new IllegalArgumentException("Interpolationparameter exceeds bounds");    m_tuneInterpolationParameter = false;    m_interpolationParameterValid = false;    m_s = s;  }  /**   * Returns the current value of the interpolation parameter.   *   * @return the value of the interpolation parameter   */  public double getInterpolationParameter() {    return m_s;  }  /**   * Returns the tip text for this property.   *   * @return tip text for this property suitable for    * displaying in the explorer/experimenter gui   */  public String numberOfPartsForInterpolationParameterTipText() {    return "Sets the granularity for tuning the interpolation parameter; "    + "For instance if the value is 32 then 33 values for the "    + "interpolation are checked.";    }  /**   * Sets the granularity for tuning the interpolation parameter.   * The interval between lower and upper bounds for the interpolation   * parameter is divided into <code> sParts </code> parts, i.e.   * <code> sParts + 1 </code> values will be checked when    * <code> tuneInterpolationParameter </code> is invoked.   * This also means that the interpolation parameter is to   * be tuned.   *    * @param sParts the number of parts   * @throws IllegalArgumentException if <code> sParts </code> is    * smaller or equal than 0.   */  public void setNumberOfPartsForInterpolationParameter(int sParts)     throws IllegalArgumentException {        if (sParts <= 0)      throw new IllegalArgumentException("Number of parts is negative");    m_tuneInterpolationParameter = true;    if (m_sNrParts != sParts) {      m_interpolationParameterValid = false;      m_sNrParts = sParts;    }  }  /**   * Gets the granularity for tuning the interpolation parameter.   *    * @return the number of parts in which the interval    * <code> [s_low, s_up] </code> is to be split   */  public int getNumberOfPartsForInterpolationParameter() {    return m_sNrParts;  }  /**   * Returns a string suitable for displaying in the gui/experimenter.   *    * @return tip text for this property suitable for    * displaying in the explorer/experimenter gui   */  public String balancedTipText() {    return "If true, the balanced version of the OSDL-algorithm is used\n"    + "This means that distinction is made between the normal and "    + "reversed preference situation.";  }  /**   * If <code> balanced </code> is <code> true </code> then the balanced   * version of OSDL will be used, otherwise the ordinary version of    * OSDL will be in effect.   *   * @param balanced if <code> true </code> then B-OSDL is used, otherwise   * it is OSDL   */  public void setBalanced(boolean balanced) {    m_balanced = balanced;  }  /**    * Returns if the balanced version of OSDL is in effect.   *   * @return <code> true </code> if the balanced version is in effect,   * <code> false </code> otherwise   */  public boolean getBalanced() {    return m_balanced;  }  /**    * Returns a string suitable for displaying in the gui/experimenter.   *    * @return tip text for this property suitable for    * displaying in the explorer/experimenter gui   */  public String weightedTipText() {    return "If true, the weighted version of the OSDL-algorithm is used";  }  /**   * If <code> weighted </code> is <code> true </code> then the   * weighted version of the OSDL is used.   * Note: using the weighted (non-balanced) version only ensures the    * quasi monotonicity of the results w.r.t. to training set.   *   * @param weighted <code> true </code> if the weighted version to be used,   * <code> false </code> otherwise   */  public void setWeighted(boolean weighted) {    m_weighted = weighted;  }  /**   * Returns if the weighted version is in effect.   *   * @return <code> true </code> if the weighted version is in effect,   * <code> false </code> otherwise.   */  public boolean getWeighted() {    return m_weighted;  }  /**   * Returns the current value of the lower bound for the interpolation    * parameter.   *   * @return the current value of the lower bound for the interpolation   * parameter   */  public double getLowerBound() {    return m_sLower;  }  /**   * Returns the current value of the upper bound for the interpolation    * parameter.   *   * @return the current value of the upper bound for the interpolation   * parameter   */  public double getUpperBound() {    return m_sUpper;  }  /**   * Returns the number of instances in the training set.   *   * @return the number of instances used for training   */  public int getNumInstances() {    return m_train.numInstances();  }  /** Tune the interpolation parameter using the current   *  settings of the classifier.   *  This also sets the interpolation parameter.   *  @return the value of the tuned interpolation parameter.   */  public double tuneInterpolationParameter() {    try {      return tuneInterpolationParameter(m_sLower, m_sUpper, m_sNrParts, m_ctype);    } catch (IllegalArgumentException e) {      throw new AssertionError(e);    }  }  /**   *  Tunes the interpolation parameter using the given settings.   *  The parameters of the classifier are updated accordingly!   *  Marks the interpolation parameter as valid.   *     *  @param sLow lower end point of interval of paramters to be examined   *  @param sUp upper end point of interval of paramters to be examined   *  @param sParts number of parts the interval is divided into.  This thus determines   *  the granularity of the search   *  @param ctype the classification type to use   *  @return the value of the tuned interpolation parameter   *  @throws IllegalArgumentException if the given parameter list is not   *  valid   */  public double tuneInterpolationParameter(double sLow, double sUp, int sParts, int ctype)     throws IllegalArgumentException {        setInterpolationParameterBounds(sLow, sUp);    setNumberOfPartsForInterpolationParameter(sParts);    setClassificationType(new SelectedTag(ctype, TAGS_CLASSIFICATIONTYPES));    m_s = crossValidate(sLow, sUp, sParts, ctype);    m_tuneInterpolationParameter = true;    m_interpolationParameterValid = true;    return m_s;  }  /**    *  Tunes the interpolation parameter using the current settings   *  of the classifier.  This doesn't change the classifier, i.e.   *  none of the internal parameters is changed!   *   *  @return the tuned value of the interpolation parameter   *  @throws IllegalArgumentException if somehow the current settings of the    *  classifier are illegal.   */  public double crossValidate() throws IllegalArgumentException {    return crossValidate(m_sLower, m_sUpper, m_sNrParts, m_ctype);  }  /**   *  Tune the interpolation parameter using leave-one-out   *  cross validation, the loss function used is the 1-0 loss   *  function.   *  <p>   *  The given settings are used, but the classifier is not   *  updated!.  Also, the interpolation parameter s is not    *  set.   *  </p>   *    *  @param sLow lower end point of interval of paramters to be examined   *  @param sUp upper end point of interval of paramters to be examined   *  @param sNrParts number of parts the interval is divided into.  This thus determines   *  the granularity of the search   *  @param ctype the classification type to use   *  @return the best value for the interpolation parameter   *  @throws IllegalArgumentException if the settings for the   *  interpolation parameter are not valid or if the classification    *  type is not valid   */  public double crossValidate (double sLow, double sUp, int sNrParts, int ctype)     throws IllegalArgumentException {    double[] performanceStats = new double[sNrParts + 1];    return crossValidate(sLow, sUp, sNrParts, ctype, 	performanceStats, new ZeroOneLossFunction());  }  /**   * Tune the interpolation parameter using leave-one-out   * cross validation.  The given parameters are used, but    * the classifier is not changed, in particular, the interpolation   * parameter remains unchanged.   *   * @param sLow lower bound for interpolation parameter   * @param sUp upper bound for interpolation parameter   * @param sNrParts determines the granularity of the search   * @param ctype the classification type to use   * @param performanceStats array acting as output, and that will   * contain the total loss of the leave-one-out cross validation for   * each considered value of the interpolation parameter   * @param lossFunction the loss function to use   * @return the value of the interpolation parameter that is considered   * best   * @throws IllegalArgumentException the length of the array    * <code> performanceStats </code> is not sufficient   * @throws IllegalArgumentException if the interpolation parameters    * are not valid   * @throws IllegalArgumentException if the classification type is    * not valid   */  public double crossValidate(double sLow, double sUp, int sNrParts,       int ctype, double[] performanceStats,       NominalLossFunction lossFunction) throws IllegalArgumentException {    if (performanceStats.length < sNrParts + 1) {

⌨️ 快捷键说明

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