/** * Creates and returns a linear VFA object over this Fourier basis feature database. * @param defaultWeightValue the default feature weight value to use for all features * @return a linear VFA object over this Fourier basis feature database. */ public DenseLinearVFA generateVFA(double defaultWeightValue) { return new DenseLinearVFA(this, defaultWeightValue); }
@Override public double evaluate(State s, Action a) { this.currentStateFeatures = this.stateFeatures.features(s); this.currentActionOffset = this.getActionOffset(a); int indOff = this.currentActionOffset*this.currentStateFeatures.length; double val = 0; for(int i = 0; i < this.currentStateFeatures.length; i++){ val += this.currentStateFeatures[i] * this.stateActionWeights[i+indOff]; } this.currentValue = val; this.currentGradient = null; this.lastState = s; return this.currentValue; }
public int getActionOffset(Action a){ Integer offset = this.actionOffset.get(a); if(offset == null){ offset = this.actionOffset.size(); this.actionOffset.put(a, offset); this.expandStateActionWeights(this.currentStateFeatures.length); } return offset; }
@Override public FunctionGradient gradient(State s, Action a){ double [] features; if(this.lastState == s){ if(this.currentGradient != null){ return this.currentGradient; } features = this.currentStateFeatures; } else{ features = this.stateFeatures.features(s); } FunctionGradient gradient = new FunctionGradient.SparseGradient(features.length); int actionOffset = this.getActionOffset(a); int sIndOffset = actionOffset*features.length; for(int i = 0; i < features.length; i++){ gradient.put(i+sIndOffset, features[i]); } this.currentGradient = gradient; this.currentStateFeatures = features; this.lastState = s; return gradient; }
/** * Creates and returns a linear VFA object over this RBF feature database. * @param defaultWeightValue the default feature weight value to use for all features * @return a linear VFA object over this RBF feature database. */ public DenseLinearVFA generateVFA(double defaultWeightValue) { return new DenseLinearVFA(this, defaultWeightValue); }
@Override public DenseLinearVFA copy() { DenseLinearVFA vfa = new DenseLinearVFA(this.stateFeatures, this.defaultWeight); vfa.actionOffset = new HashMap<Action, Integer>(this.actionOffset); if(this.stateWeights != null) { vfa.stateWeights = new double[this.stateWeights.length]; for(int i = 0; i < this.stateWeights.length; i++) { vfa.stateWeights[i] = this.stateWeights[i]; } } if(this.stateActionWeights != null) { vfa.stateActionWeights = new double[this.stateActionWeights.length]; for(int i = 0; i < this.stateActionWeights.length; i++) { vfa.stateActionWeights[i] = this.stateActionWeights[i]; } } return vfa; } }