/** * Calls the appropriate <code>Learner.setParameters(Parameters)</code> method for this * <code>Parameters</code> object. * * @param l The learner whose parameters will be set. **/ public void setParameters(Learner l) { ((AdaBoost) l).setParameters(this); }
/** * This method uses the trained parameters to make a binary decision about an example object. * * @param exampleFeatures The example's array of feature indices. * @param exampleValues The example's array of feature values. * @return The decision value. **/ public String discreteValue(int[] exampleFeatures, double[] exampleValues) { double[] scores = sumAlphas(exampleFeatures, exampleValues); return allowableValues[scores[0] > scores[1] ? 0 : 1]; }
/** * This method adds the example object to the array storing the training examples. * * <p> * Note that learning does not actually take place until {@link #doneLearning()} is called. * * @param example The example object. **/ public void learn(Object example) { allExamples.add(getExampleArray(example)); }
/** * This method uses the trained parameters to make a binary decision about an example object. * * @param exampleFeatures The example features. * @param exampleValues The example values. * @return A binary <code>DiscreteFeature</code>. **/ public FeatureVector classify(int[] exampleFeatures, double[] exampleValues) { return new FeatureVector(featureValue(exampleFeatures, exampleValues)); }
/** * Sets the labeler. * * @param l A labeling classifier. **/ public void setLabeler(Classifier l) { if (l == null || l.allowableValues().length != 2) { System.err.println("Error: " + name + ": An LTU must be given a single binary label classifier."); new Exception().printStackTrace(); System.exit(1); } super.setLabeler(l); allowableValues = l.allowableValues(); labelLexicon.clear(); labelLexicon.lookup(new DiscretePrimitiveStringFeature(l.containingPackage, l.name, "", allowableValues[0], (short) 0, (short) 2), true); labelLexicon.lookup(new DiscretePrimitiveStringFeature(l.containingPackage, l.name, "", allowableValues[1], (short) 1, (short) 2), true); createPrediction(0); createPrediction(1); }
/** * Returns the classification of the given example as a single feature instead of a * {@link FeatureVector}. * * @param exampleFeatures The example's array of feature indices. * @param exampleValues The example's array of feature values. * @return The classification of the example as a feature. **/ public Feature featureValue(int[] exampleFeatures, double[] exampleValues) { double[] scores = sumAlphas(exampleFeatures, exampleValues); return predictions.get(scores[0] > scores[1] ? 0 : 1); }
/** * Initializing constructor. Sets all member variables to their associated settings in the * {@link AdaBoost.Parameters} object. * * @param n The name of the classifier. * @param p The settings of all parameters. **/ public AdaBoost(String n, Parameters p) { super(n); setParameters(p); allExamples = new OVector(); allowableValues = new String[] {"*", "*"}; }
/** * Produces a set of scores indicating the degree to which each possible discrete classification * value is associated with the given example object. * * @param exampleFeatures The example's array of feature indices. * @param exampleValues The example's array of feature values. * @return The accumulated alpha values of weak learners that predicted the associated * classification value. **/ public ScoreSet scores(int[] exampleFeatures, double[] exampleValues) { double[] scores = sumAlphas(exampleFeatures, exampleValues); String[] values = new String[] {labelLexicon.lookupKey(0).getStringValue(), labelLexicon.lookupKey(1).getStringValue()}; return new ScoreSet(values, scores); }