/**
   * builds the necessary CollectiveInstances from the given Instances
   *
   * @throws Exception if anything goes wrong
   */
  @Override
  protected void generateSets() throws Exception {
    int i;

    super.generateSets();

    m_CollectiveInstances = new CollectiveInstances();
    m_CollectiveInstances.setSeed(getSeed());
    m_CollectiveInstances.setFlipper(m_Flipper);

    m_TrainsetNew = new Instances(m_Trainset);
    for (i = 0; i < m_Testset.numInstances(); i++) m_TrainsetNew.add(m_Testset.instance(i));

    m_FlipHistory = new FlipHistory(m_TrainsetNew);
  }
  /**
   * calculates the RMS for test and train set
   *
   * @throws Exception if something goes wrong
   */
  protected void calculateRMS() throws Exception {
    double[] rms;

    rms =
        CollectiveInstances.calculateRMS(
            this.getClassifier(),
            m_Trainset,
            new Instances(m_TrainsetNew, m_Trainset.numInstances(), m_Testset.numInstances()),
            m_TestsetOriginal);

    m_RMS = rms[0];
    m_RMSTrain = rms[1];
    m_RMSTest = rms[2];
    m_RMSTestOriginal = rms[3];

    if (getVerbose())
      System.out.println(
          "\nRMSTest: "
              + m_RMSTest
              + ", "
              + "RMSTestOrig: "
              + m_RMSTestOriginal
              + ", "
              + "RMSTrain: "
              + m_RMSTrain
              + ", "
              + "RMS: "
              + m_RMS);
  }
  /**
   * calculates the accuracy for original test and train set
   *
   * @throws Exception if something goes wrong
   */
  protected void calculateAccuracy() throws Exception {
    double[] acc;

    acc =
        CollectiveInstances.calculateAccuracy(this.getClassifier(), m_Trainset, m_TestsetOriginal);

    m_AccTrain = acc[0];
    m_AccTestOriginal = acc[1];

    if (getVerbose())
      System.out.println("\nAccTrain: " + m_AccTrain + ", " + "AccTestOrig: " + m_AccTestOriginal);
  }
  /**
   * flips the labels of the CollectiveInstances
   *
   * @throws Exception if flipping fails
   */
  public void flipLabels() throws Exception {
    int from;
    int count;

    if (getUpdateTraining()) {
      from = 0;
      count = m_TrainsetNew.numInstances();
    } else {
      from = m_Trainset.numInstances();
      count = m_Testset.numInstances();
    }

    if (m_EvaluationType == CollectiveInstances.EVAL_HILLCLIMBING)
      m_TrainsetNew =
          m_CollectiveInstances.flipLabels(
              getBestModel().getClassifier(), m_TrainsetNew, from, count, m_FlipHistory);
    else
      m_TrainsetNew =
          m_CollectiveInstances.flipLabels(
              this.getClassifier(), m_TrainsetNew, from, count, m_FlipHistory);
  }
 /**
  * returns the percentage of flipped labels
  *
  * @return the percentage
  * @see CollectiveInstances#getFlippedLabels()
  */
 protected double getFlippedLabels() {
   return m_CollectiveInstances.getFlippedLabels();
 }
 /**
  * initializes the labels of the CollectiveInstances
  *
  * @throws Exception if initialization fails
  */
 public void initializeLabels() throws Exception {
   m_TrainsetNew =
       m_CollectiveInstances.initializeLabels(
           m_Trainset, m_TrainsetNew, m_Trainset.numInstances(), m_Testset.numInstances());
 }