/** * Return an AdaBoostM2 classifier that uses only the first * <tt>numWeakClassifiersToUse</tt> weak learners. * * <p>The returned classifier's Pipe and weak classifiers * are backed by the respective objects of this classifier, * so changes to the returned classifier's Pipe and weak * classifiers are reflected in this classifier, and vice versa. */ public AdaBoostM2 getTrimmedClassifier(int numWeakClassifiersToUse) { if (numWeakClassifiersToUse <= 0 || numWeakClassifiersToUse > weakClassifiers.length) throw new IllegalArgumentException("number of weak learners to use out of range:" + numWeakClassifiersToUse); Classifier[] newWeakClassifiers = new Classifier[numWeakClassifiersToUse]; System.arraycopy(weakClassifiers, 0, newWeakClassifiers, 0, numWeakClassifiersToUse); double[] newAlphas = new double[numWeakClassifiersToUse]; System.arraycopy(alphas, 0, newAlphas, 0, numWeakClassifiersToUse); return new AdaBoostM2(instancePipe, newWeakClassifiers, newAlphas); }
public Classification classify (Instance inst) { return classify(inst, weakClassifiers.length); }
/** * Classify the given instance using only the first * <tt>numWeakClassifiersToUse</tt> classifiers * trained during boosting */ public Classification classify (Instance inst, int numWeakClassifiersToUse) { if (numWeakClassifiersToUse <= 0 || numWeakClassifiersToUse > weakClassifiers.length) throw new IllegalArgumentException("number of weak learners to use out of range:" + numWeakClassifiersToUse); FeatureVector fv = (FeatureVector) inst.getData(); assert (instancePipe == null || fv.getAlphabet () == this.instancePipe.getDataAlphabet ()); int numClasses = getLabelAlphabet().size(); double[] scores = new double[numClasses]; int bestIndex; double sum = 0; // Gather scores of all weakClassifiers for (int round = 0; round < numWeakClassifiersToUse; round++) { bestIndex = weakClassifiers[round].classify(inst).getLabeling().getBestIndex(); scores[bestIndex] += alphas[round]; sum += scores[bestIndex]; } // Normalize the scores for (int i = 0; i < scores.length; i++) scores[i] /= sum; return new Classification (inst, this, new LabelVector (getLabelAlphabet(), scores)); }
/** * Classify the given instance using only the first * <tt>numWeakClassifiersToUse</tt> classifiers * trained during boosting */ public Classification classify (Instance inst, int numWeakClassifiersToUse) { if (numWeakClassifiersToUse <= 0 || numWeakClassifiersToUse > weakClassifiers.length) throw new IllegalArgumentException("number of weak learners to use out of range:" + numWeakClassifiersToUse); FeatureVector fv = (FeatureVector) inst.getData(); assert (instancePipe == null || fv.getAlphabet () == this.instancePipe.getDataAlphabet ()); int numClasses = getLabelAlphabet().size(); double[] scores = new double[numClasses]; int bestIndex; double sum = 0; // Gather scores of all weakClassifiers for (int round = 0; round < numWeakClassifiersToUse; round++) { bestIndex = weakClassifiers[round].classify(inst).getLabeling().getBestIndex(); scores[bestIndex] += alphas[round]; sum += scores[bestIndex]; } // Normalize the scores for (int i = 0; i < scores.length; i++) scores[i] /= sum; return new Classification (inst, this, new LabelVector (getLabelAlphabet(), scores)); }
/** * Return an AdaBoostM2 classifier that uses only the first * <tt>numWeakClassifiersToUse</tt> weak learners. * * <p>The returned classifier's Pipe and weak classifiers * are backed by the respective objects of this classifier, * so changes to the returned classifier's Pipe and weak * classifiers are reflected in this classifier, and vice versa. */ public AdaBoostM2 getTrimmedClassifier(int numWeakClassifiersToUse) { if (numWeakClassifiersToUse <= 0 || numWeakClassifiersToUse > weakClassifiers.length) throw new IllegalArgumentException("number of weak learners to use out of range:" + numWeakClassifiersToUse); Classifier[] newWeakClassifiers = new Classifier[numWeakClassifiersToUse]; System.arraycopy(weakClassifiers, 0, newWeakClassifiers, 0, numWeakClassifiersToUse); double[] newAlphas = new double[numWeakClassifiersToUse]; System.arraycopy(alphas, 0, newAlphas, 0, numWeakClassifiersToUse); return new AdaBoostM2(instancePipe, newWeakClassifiers, newAlphas); }
public Classification classify (Instance inst) { return classify(inst, weakClassifiers.length); }
/** * Classify the given instance using only the first * <tt>numWeakClassifiersToUse</tt> classifiers * trained during boosting */ public Classification classify (Instance inst, int numWeakClassifiersToUse) { if (numWeakClassifiersToUse <= 0 || numWeakClassifiersToUse > weakClassifiers.length) throw new IllegalArgumentException("number of weak learners to use out of range:" + numWeakClassifiersToUse); FeatureVector fv = (FeatureVector) inst.getData(); assert (instancePipe == null || fv.getAlphabet () == this.instancePipe.getDataAlphabet ()); int numClasses = getLabelAlphabet().size(); double[] scores = new double[numClasses]; int bestIndex; double sum = 0; // Gather scores of all weakClassifiers for (int round = 0; round < numWeakClassifiersToUse; round++) { bestIndex = weakClassifiers[round].classify(inst).getLabeling().getBestIndex(); scores[bestIndex] += alphas[round]; sum += scores[bestIndex]; } // Normalize the scores for (int i = 0; i < scores.length; i++) scores[i] /= sum; return new Classification (inst, this, new LabelVector (getLabelAlphabet(), scores)); }
/** * Return an AdaBoostM2 classifier that uses only the first * <tt>numWeakClassifiersToUse</tt> weak learners. * * <p>The returned classifier's Pipe and weak classifiers * are backed by the respective objects of this classifier, * so changes to the returned classifier's Pipe and weak * classifiers are reflected in this classifier, and vice versa. */ public AdaBoostM2 getTrimmedClassifier(int numWeakClassifiersToUse) { if (numWeakClassifiersToUse <= 0 || numWeakClassifiersToUse > weakClassifiers.length) throw new IllegalArgumentException("number of weak learners to use out of range:" + numWeakClassifiersToUse); Classifier[] newWeakClassifiers = new Classifier[numWeakClassifiersToUse]; System.arraycopy(weakClassifiers, 0, newWeakClassifiers, 0, numWeakClassifiersToUse); double[] newAlphas = new double[numWeakClassifiersToUse]; System.arraycopy(alphas, 0, newAlphas, 0, numWeakClassifiersToUse); return new AdaBoostM2(instancePipe, newWeakClassifiers, newAlphas); }
public Classification classify (Instance inst) { return classify(inst, weakClassifiers.length); }
+ classifierWeights2[i]); return new AdaBoostM2 (trainingInsts.getPipe(), weakLearners2, classifierWeights2); this.classifier = new AdaBoostM2 (trainingInsts.getPipe(), weakLearners, classifierWeights); return classifier;
+ classifierWeights2[i]); return new AdaBoostM2 (trainingInsts.getPipe(), weakLearners2, classifierWeights2); this.classifier = new AdaBoostM2 (trainingInsts.getPipe(), weakLearners, classifierWeights); return classifier;
+ classifierWeights2[i]); return new AdaBoostM2 (trainingInsts.getPipe(), weakLearners2, classifierWeights2); this.classifier = new AdaBoostM2 (trainingInsts.getPipe(), weakLearners, classifierWeights); return classifier;