Example #1
0
 public double getActiveLearningRatio(double qbcEntropy, DoubleVector combinedVote) {
   int maxIndex = combinedVote.maxIndex();
   int ensembleLength = this.ensemble.length;
   double maxVote = combinedVote.getValue(maxIndex);
   double activeLearningRatio = (qbcEntropy) * (maxVote / ensembleLength);
   return activeLearningRatio;
 }
Example #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();
  }