@Override public Prediction getPredictionForInstance(MultiLabelInstance x){ if (this.majorityLabelset == null) { int L = x.numberOutputTargets(); return new MultiLabelPrediction(L); } return this.majorityLabelset; }
@Override public double[] getVotes() { return getVotes(0); }
@Override public void trainOnInstanceImpl(MultiLabelInstance x) { int L = x.numberOutputTargets(); MultiLabelPrediction y = new MultiLabelPrediction(L); for(int j=0; j<L;j++) y.setVotes(j,new double[]{1- x.classValue(j), x.classValue(j)}); double freq = x.weight(); if (this.vectorCounts.containsKey(y.toString())) { freq += this.vectorCounts.get(y.toString()); } this.vectorCounts.put(y.toString(), (Double)freq); if (freq > this.maxValue) { this.maxValue = freq; this.majorityLabelset = y; } //System.out.println("---"+this.majorityLabelset); }
@Override public Prediction getPredictionForInstance(MultiLabelInstance samoaInstance) { MultiLabelPrediction prediction = new MultiLabelPrediction(L); if (isClassificationEnabled == true) { double votes[] = getVotesForInstance(samoaInstance); for (int j = 0; j < L; j++) { prediction.setVotes(j, new double[]{1.-votes[j],votes[j]}); } } // else there's no model yet... (just return empty prediction). return prediction; }
public Prediction getPredictionForInstance(MultiLabelInstance inst) { checkRoot(); double[] predictionVector = treeRoot.getPrediction(inst); MultiLabelPrediction prediction = new MultiLabelPrediction(getModelContext().numOutputAttributes()); for (int i = 0; i < getModelContext().numOutputAttributes(); i++) { prediction.setVote(i, 1, predictionVector[i]); } return prediction; }
@Override public void setVotes(double[] votes) { setVotes(0, votes); }
@Override public void getModelDescription(StringBuilder out, int indent) { StringUtils.appendIndented(out, indent, ""); out.append(this.majorityLabelset.toString()); StringUtils.appendNewline(out); }
@Override public void addResult(Example<Instance> example, double[] classVotes) { Prediction p=new MultiLabelPrediction(1); p.setVotes(classVotes); addResult(example, p); }
@Override public Prediction getPredictionForInstance(Instance inst){ Prediction prediction= new MultiLabelPrediction(1); prediction.setVotes(getVotesForInstance(inst)); return prediction; }
@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; }
@Override public Prediction getPredictionForInstance(MultiLabelInstance inst) { int numOutputs=inst.numOutputAttributes(); Prediction p=new MultiLabelPrediction(numOutputs); if(countVector!=null){ for (int i=0; i<numOutputs; i++){ double frac=countVector[i]/numInstances; p.setVote(i, 1, frac); p.setVote(i, 0, 1-frac); } } return p; }
@Override public void trainOnInstanceImpl(MultiLabelInstance inst) { int numOutputs = inst.numberOutputTargets(); Prediction prediction = new MultiLabelPrediction(numOutputs); for(int i=0; i<numOutputs;i++) prediction.setVotes(i,new double[]{inst.classValue(i)}); this.lastSeenClasses = prediction; }
@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 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++) { //For each vote for (int i=0; i<n; i++) { int numClasses=votes.get(i).numClasses(o); if(votes.get(i).hasVotesForAttribute(o)) weights[i][o]=1.0/outputAttributesCount[o]; //else takes value 0 //For each class for(int j=0; j<numClasses; j++){ weightedVote.setVote(o, j, weightedVote.getVote(o, j)+votes.get(i).getVote(o, j)*weights[i][o]); } } } } return weightedVote; }
weightedVote=new MultiLabelPrediction(numOutputs);
@Override public Prediction getPredictionForInstance(MultiLabelInstance instance) { Prediction prediction=null; if (this.hasStarted){ prediction=new MultiLabelPrediction(ensemble.length); DoubleVector combinedVote = new DoubleVector(); for (int i = 0; i < this.ensemble.length; i++) { double vote=this.ensemble[i].getVotesForInstance(transformInstance(instance,i))[0]; prediction.setVote(i, 0, vote); } } return prediction; } }
public void addPrediction(Prediction prediction, MultiLabelInstance inst){ int numOutputs=inst.numberOutputTargets(); Prediction trueClass= new MultiLabelPrediction(numOutputs); for (int i=0; i<numOutputs; i++){ trueClass.setVotes(i, new double[]{inst.valueOutputAttribute(i)}); } addPrediction(prediction, trueClass, inst.weight()); }
@Override public Prediction getPredictionForInstance(MultiLabelInstance instance) { Prediction prediction=null; double [] votes= new double[instance.numClasses()]; double vote; if (this.hasStarted){ prediction=new MultiLabelPrediction(ensemble.length); DoubleVector combinedVote = new DoubleVector(); for (int i = 0; i < this.ensemble.length; i++) { vote= this.ensemble[i].getVotesForInstance(transformInstance(instance,i))[0]; prediction.setVote(i, 0, vote); } } return prediction; }
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; }
@Override public Prediction getPredictionForInstance(MultiLabelInstance inst) { Prediction pred=null; if(hasStarted) { int numOutputs=outAttrSum.length; pred=new MultiLabelPrediction(numOutputs); double [] normInputs=getNormalizedInput(inst); double [] firstLayerOutput=predict1stLayer(normInputs); double [] denormalizedOutput=null; if(!skipStackingOption.isSet()){ double [] secondLayerOutput=predict2ndLayer(firstLayerOutput); denormalizedOutput=getDenormalizedOutput(secondLayerOutput); } else denormalizedOutput=getDenormalizedOutput(firstLayerOutput); for(int i=0; i<numOutputs; i++) pred.setVotes(i, new double[]{denormalizedOutput[i]}); } return pred; }