@Override public Vector apply(String groupKey, int actual, Vector instance, AbstractVectorClassifier classifier) { if (random.nextDouble() < alpha) { // one option is to apply a ranking update relative to our recent history if (!hasZero || !hasOne) { throw new IllegalStateException(); } return rank.apply(groupKey, actual, instance, classifier); } else { hasZero |= actual == 0; hasOne |= actual == 1; // the other option is a normal update, but we have to update our history on the way rank.addToHistory(actual, instance); return basic.apply(groupKey, actual, instance, classifier); } } }
@Override public Vector apply(String groupKey, int actual, Vector instance, AbstractVectorClassifier classifier) { if (random.nextDouble() < alpha) { // one option is to apply a ranking update relative to our recent history if (!hasZero || !hasOne) { throw new IllegalStateException(); } return rank.apply(groupKey, actual, instance, classifier); } else { hasZero |= actual == 0; hasOne |= actual == 1; // the other option is a normal update, but we have to update our history on the way rank.addToHistory(actual, instance); return basic.apply(groupKey, actual, instance, classifier); } } }
@Override public Vector apply(String groupKey, int actual, Vector instance, AbstractVectorClassifier classifier) { if (random.nextDouble() < alpha) { // one option is to apply a ranking update relative to our recent history if (!hasZero || !hasOne) { throw new IllegalStateException(); } return rank.apply(groupKey, actual, instance, classifier); } else { hasZero |= actual == 0; hasOne |= actual == 1; // the other option is a normal update, but we have to update our history on the way rank.addToHistory(actual, instance); return basic.apply(groupKey, actual, instance, classifier); } } }
@Override public final Vector apply(String groupKey, int actual, Vector instance, AbstractVectorClassifier classifier) { addToHistory(actual, instance); // now compute average gradient versus saved vectors from the other side Deque<Vector> otherSide = history.get(1 - actual); int n = otherSide.size(); Vector r = null; for (Vector other : otherSide) { Vector g = BASIC.apply(groupKey, actual, instance.minus(other), classifier); if (r == null) { r = g; } else { r.assign(g, Functions.plusMult(1.0 / n)); } } return r; }
@Override public final Vector apply(String groupKey, int actual, Vector instance, AbstractVectorClassifier classifier) { addToHistory(actual, instance); // now compute average gradient versus saved vectors from the other side Deque<Vector> otherSide = history.get(1 - actual); int n = otherSide.size(); Vector r = null; for (Vector other : otherSide) { Vector g = BASIC.apply(groupKey, actual, instance.minus(other), classifier); if (r == null) { r = g; } else { r.assign(g, Functions.plusMult(1.0 / n)); } } return r; }
@Override public final Vector apply(String groupKey, int actual, Vector instance, AbstractVectorClassifier classifier) { addToHistory(actual, instance); // now compute average gradient versus saved vectors from the other side Deque<Vector> otherSide = history.get(1 - actual); int n = otherSide.size(); Vector r = null; for (Vector other : otherSide) { Vector g = BASIC.apply(groupKey, actual, instance.minus(other), classifier); if (r == null) { r = g; } else { r.assign(g, Functions.plusMult(1.0 / n)); } } return r; }
@Override public void train(long trackingKey, String groupKey, int actual, Vector instance) { unseal(); double learningRate = currentLearningRate(); // push coefficients back to zero based on the prior regularize(instance); // update each row of coefficients according to result Vector gradient = this.gradient.apply(groupKey, actual, instance, this); for (int i = 0; i < numCategories - 1; i++) { double gradientBase = gradient.get(i); // then we apply the gradientBase to the resulting element. for (Element updateLocation : instance.nonZeroes()) { int j = updateLocation.index(); double newValue = beta.getQuick(i, j) + gradientBase * learningRate * perTermLearningRate(j) * instance.get(j); beta.setQuick(i, j, newValue); } } // remember that these elements got updated for (Element element : instance.nonZeroes()) { int j = element.index(); updateSteps.setQuick(j, getStep()); updateCounts.incrementQuick(j, 1); } nextStep(); }
@Override public void train(long trackingKey, String groupKey, int actual, Vector instance) { unseal(); double learningRate = currentLearningRate(); // push coefficients back to zero based on the prior regularize(instance); // update each row of coefficients according to result Vector gradient = this.gradient.apply(groupKey, actual, instance, this); for (int i = 0; i < numCategories - 1; i++) { double gradientBase = gradient.get(i); // then we apply the gradientBase to the resulting element. for (Element updateLocation : instance.nonZeroes()) { int j = updateLocation.index(); double newValue = beta.getQuick(i, j) + gradientBase * learningRate * perTermLearningRate(j) * instance.get(j); beta.setQuick(i, j, newValue); } } // remember that these elements got updated for (Element element : instance.nonZeroes()) { int j = element.index(); updateSteps.setQuick(j, getStep()); updateCounts.incrementQuick(j, 1); } nextStep(); }
@Override public void train(long trackingKey, String groupKey, int actual, Vector instance) { unseal(); double learningRate = currentLearningRate(); // push coefficients back to zero based on the prior regularize(instance); // update each row of coefficients according to result Vector gradient = this.gradient.apply(groupKey, actual, instance, this); for (int i = 0; i < numCategories - 1; i++) { double gradientBase = gradient.get(i); // then we apply the gradientBase to the resulting element. for (Element updateLocation : instance.nonZeroes()) { int j = updateLocation.index(); double newValue = beta.getQuick(i, j) + gradientBase * learningRate * perTermLearningRate(j) * instance.get(j); beta.setQuick(i, j, newValue); } } // remember that these elements got updated for (Element element : instance.nonZeroes()) { int j = element.index(); updateSteps.setQuick(j, getStep()); updateCounts.incrementQuick(j, 1); } nextStep(); }