public MixedGradient(double alpha, int window) { this.alpha = alpha; this.rank = new RankingGradient(window); this.basic = this.rank.getBaseGradient(); }
@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 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; }
public MixedGradient(double alpha, int window) { this.alpha = alpha; this.rank = new RankingGradient(window); this.basic = this.rank.getBaseGradient(); }
@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; }
public MixedGradient(double alpha, int window) { this.alpha = alpha; this.rank = new RankingGradient(window); this.basic = this.rank.getBaseGradient(); }