@Override public double[] getVotesForInstance(Instance inst) { Prediction pred = getPredictionForInstance(inst); if (pred != null) { return pred.getVotes(); } else { return new double[]{0}; //for compatibility with single target code } }
@Override public void addResult(Example<Instance> example, Prediction prediction) { if(prediction!=null) addResult(example,prediction.getVotes(0)); } }
@Override public void addResult(Example<Instance> testInst, Prediction prediction) { double votes[]; if(prediction==null) votes = new double[0]; else votes=prediction.getVotes(); addResult(testInst, votes); } }
@Override public Prediction computeWeightedVote() { int n=votes.size(); if (n>0){ int numOutputs=outputAttributesCount.length; weights=new double[n][numOutputs]; weightedVote=new MultiLabelPrediction(numOutputs); //For each output attribute for (int o=0;o<numOutputs;o++) { //int numClasses=votes.get(0).numClasses(o); //For each vote for (int i=0; i<n; i++) { if(votes.get(i).hasVotesForAttribute(o)){ //set as weighted vote and set weight to 1 weights[i][o]=1; /*for(int j=0; j<numClasses; j++){ weightedVote.setVote(o, j, votes.get(i).getVote(o, j)); }*/ weightedVote.setVotes(o, votes.get(i).getVotes(o)); break; } } } } return weightedVote; } }
@Override public Prediction targetPredictionToSource(Prediction targetPrediction) { Prediction sourcePrediction=new MultiLabelPrediction(this.numSourceInstancesOutputs); for (int i=0; i<targetPrediction.numOutputAttributes();i++){ sourcePrediction.setVotes(this.targetOutputIndices[i], targetPrediction.getVotes(i)); } return sourcePrediction; }
public static Prediction combinePredictions(Prediction[] predictions, Instance inst) { Prediction result = new MultiLabelPrediction(inst.numOutputAttributes()); for (int i = 0; i < predictions.length; i++) { try { Prediction more_votes = predictions[i]; if (more_votes != null) { for (int numOutputAttribute = 0; numOutputAttribute < inst.numOutputAttributes(); numOutputAttribute++) { int length = 0; if (more_votes.getVotes(numOutputAttribute) != null) length = more_votes.getVotes(numOutputAttribute).length; for (int numValueAttribute = 0; numValueAttribute < length; numValueAttribute++) { result.setVote(numOutputAttribute, numValueAttribute, (result.getVote(numOutputAttribute, numValueAttribute) + more_votes.getVote(numOutputAttribute, numValueAttribute) / (double) predictions.length)); } } } } catch (NullPointerException e) { System.err.println("NullPointer"); } catch (ArrayIndexOutOfBoundsException e) { System.err.println("OutofBounds"); } } return result; }
System.out.print("Rule " + rule.getRuleNumberID()+ ": "); for (int i=0; i< instance.numOutputAttributes() ; i++){ System.out.print(" " + vote.getVotes(i)[0]); for (int i=0; i<vote.numOutputAttributes(); i++){ if(!vote.hasVotesForAttribute(i)){ fixVote.setVotes(i, defaultVote.getVotes(i)); fixErrors[i]=defaultErrors[i];
for (int i=0; i<vote.numOutputAttributes(); i++){ if(!vote.hasVotesForAttribute(i)){ fixVote.setVotes(i, defaultVote.getVotes(i)); fixErrors[i]=defaultErrors[i];