Exemple #1
0
 protected double getEnsembleMemberWeight(int i) {
   double em = this.swms[i] / (this.scms[i] + this.swms[i]);
   if ((em == 0.0) || (em > 0.5)) {
     return 0.0;
   }
   double Bm = em / (1.0 - em);
   return Math.log(1.0 / Bm);
 }
Exemple #2
0
  public double[] getVotesForInstance(Instance inst) {
    DoubleVector combinedVote = new DoubleVector();
    DoubleVector confidenceVec = new DoubleVector();

    int success = 0;
    double[] ensembleVotes = new double[inst.numClasses()];
    double[] ensMemberWeights = new double[this.ensemble.length];
    boolean[] ensMemberFlags = new boolean[this.ensemble.length];
    double confidence = 0.0;

    for (int i = 0; i < this.ensemble.length; i++) {
      if (!ensMemberFlags[i]) {
        ensMemberWeights[i] = getEnsembleMemberWeight(i);
      }
      if (ensMemberWeights[i] > 0.0) {
        DoubleVector vote = new DoubleVector(this.ensemble[i].getVotesForInstance(inst));
        if (vote.sumOfValues() > 0.0) {
          vote.normalize();
          vote.scaleValues(ensMemberWeights[i]);
          combinedVote.addValues(vote);
          if (getEnsembleMemberError(i) < errorRatio) {
            //
            // these are the votes of the ensembles for the classes
            //
            success++;
            // successFlag = true;
            confidenceVec.addValues(vote);
            ensembleVotes[confidenceVec.maxIndex()] +=
                confidenceVec.getValue(confidenceVec.maxIndex());
          }
        }
      } else {
        break;
      }
    }

    confidenceVec = (DoubleVector) combinedVote.copy();
    confidenceVec.normalize();
    confidence = confidenceVec.getValue(confidenceVec.maxIndex());
    // Reconfigure the activeLearningRatio
    // For confidence measure add to the pool  and in order to fit the confidence value between 0
    // and 1 divide by success val
    if (confidence > confidenceThreshold) {
      double qbcEntropy =
          QBC.queryByCommitee(ensembleVotes, inst.numClasses(), success, ensemble.length);
      Math.pow(qbcEntropy, 2);
      System.out.println("QBC Entropy: " + qbcEntropy);
      double activeLearningRatio = getActiveLearningRatio(qbcEntropy, combinedVote);
      inst.setClassValue(combinedVote.maxIndex()); // Set the class value of the instance
      instConfPool.addVotedInstance(
          inst, combinedVote.getValue(combinedVote.maxIndex()), activeLearningRatio);
      instConfCount++;
    }

    return combinedVote.getArrayRef();
  }