/** * The default training algorithm for a linear threshold unit consists of evaluating the example * object with the {@link #score(Object)} method and {@link #threshold}, checking the result of * evaluation against the label, and, if they are different, promoting when the label is * positive or demoting when the label is negative. * * <p> * This method does not call {@link #classify(Object)}; it calls {@link #score(Object)} * directly. * * @param exampleFeatures The example's array of feature indices * @param exampleValues The example's array of feature values * @param exampleLabels The example's label(s) * @param labelValues The labels' values **/ public void learn(int[] exampleFeatures, double[] exampleValues, int[] exampleLabels, double[] labelValues) { assert exampleLabels.length == 1 : "Example must have a single label."; assert exampleLabels[0] == 0 || exampleLabels[0] == 1 : "Example has unallowed label value."; boolean label = (exampleLabels[0] == 1); double s = score(exampleFeatures, exampleValues); if (shouldPromote(label, s, threshold, positiveThickness)) promote(exampleFeatures, exampleValues, computeLearningRate(exampleFeatures, exampleValues, s, label)); if (shouldDemote(label, s, threshold, negativeThickness)) demote(exampleFeatures, exampleValues, computeLearningRate(exampleFeatures, exampleValues, s, label)); }