public class DenseLinearVFA extends java.lang.Object implements DifferentiableStateValue, DifferentiableStateActionValue
DenseStateFeatures
which defines
the state features on which linear function approximation is performed. In the case of Q-value
function approximation, the state features are replicated for each action with all other action's associated
state features set to zero, thereby allowing for unique predictions for each action.
This class can be used for either state-value functions or state-action-value functions, but only one of them.
Which one is used is determined implicitly by whether the first function input is set with the
evaluate(State)
method or the evaluate(State, Action)
method.
ParametricFunction.ParametricStateActionFunction, ParametricFunction.ParametricStateFunction
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<Action,java.lang.Integer> |
actionOffset
A feature index offset for each action when using Q-value function approximation.
|
protected int |
currentActionOffset |
protected FunctionGradient |
currentGradient |
protected double[] |
currentStateFeatures |
protected double |
currentValue |
protected double |
defaultWeight
A default weight value for the functions weights.
|
protected State |
lastState |
protected double[] |
stateActionWeights
The function weights when performing Q-value function approximation.
|
protected DenseStateFeatures |
stateFeatures
The state feature vector generator used for linear value function approximation.
|
protected double[] |
stateWeights
The function weights when performing state value function approximation.
|
Constructor and Description |
---|
DenseLinearVFA(DenseStateFeatures stateFeatures,
double defaultWeightValue)
Initializes.
|
Modifier and Type | Method and Description |
---|---|
DenseLinearVFA |
copy()
Returns a copy of this
ParametricFunction . |
double |
evaluate(State s)
Sets the input of this function to the given
State and returns
the value of it. |
double |
evaluate(State s,
Action a)
|
protected void |
expandStateActionWeights(int num)
Expands the state-action function weight vector by a fixed sized and initializes their value
to the default weight value set for this object.
|
java.util.Map<Action,java.lang.Integer> |
getActionOffset()
Returns the
Map of feature index offsets into the full feature vector for each action |
int |
getActionOffset(Action a) |
double |
getDefaultWeight() |
double |
getParameter(int i)
Returns the value of the ith parameter value
|
DenseStateFeatures |
getStateFeatures() |
FunctionGradient |
gradient(State s)
Returns the gradient of this function
|
FunctionGradient |
gradient(State s,
Action a)
Returns the gradient of this function.
|
void |
initializeStateActionWeightVector(int size,
double v)
Resets the state-action function weight array to a new array of the given sized and default value.
|
void |
initializeStateWeightVector(int size,
double v)
Resets the state function weight array to a new array of the given sized and default value.
|
int |
numParameters()
Returns the number of parameters defining this function.
|
void |
resetParameters()
Resets the parameters of this function to default values.
|
void |
setActionOffset(Action a,
int offset)
Sets the
Map of feature index offset into the full feature vector for the given action |
void |
setActionOffset(java.util.Map<Action,java.lang.Integer> actionOffset)
Sets the
Map of feature index offsets into the full feature vector for each action |
void |
setParameter(int i,
double p)
Sets the value of the ith parameter to given value
|
protected DenseStateFeatures stateFeatures
protected java.util.Map<Action,java.lang.Integer> actionOffset
protected double[] stateWeights
protected double[] stateActionWeights
protected double defaultWeight
protected double[] currentStateFeatures
protected int currentActionOffset
protected double currentValue
protected FunctionGradient currentGradient
protected State lastState
public DenseLinearVFA(DenseStateFeatures stateFeatures, double defaultWeightValue)
evaluate(State)
or evaluate(State, Action)
is made.
If the former method is called
first, then this object will be tasked with state value function approximation. If the latter
method is called first, then this object will be tasked with state-action value function approximation.stateFeatures
- The state feature vector generator that produces the features used for either linear state value function approximation or state-action-value function approximation.defaultWeightValue
- The default weight value of all function weights.public double evaluate(State s, Action a)
ParametricFunction.ParametricStateActionFunction
evaluate
in interface ParametricFunction.ParametricStateActionFunction
s
- the input State
a
- the input actionState
and Action
public double evaluate(State s)
ParametricFunction.ParametricStateFunction
State
and returns
the value of it.evaluate
in interface ParametricFunction.ParametricStateFunction
s
- the State
to input to the functionState
public FunctionGradient gradient(State s)
DifferentiableStateValue
gradient
in interface DifferentiableStateValue
s
- the input statepublic FunctionGradient gradient(State s, Action a)
DifferentiableStateActionValue
gradient
in interface DifferentiableStateActionValue
s
- the input State
a
- the input Action
FunctionGradient
of this function at the inputpublic int numParameters()
ParametricFunction
numParameters
in interface ParametricFunction
public double getParameter(int i)
ParametricFunction
getParameter
in interface ParametricFunction
i
- the parameter indexpublic void setParameter(int i, double p)
ParametricFunction
setParameter
in interface ParametricFunction
i
- the index of the parameter to setp
- the parameter value to which it should be setpublic void resetParameters()
ParametricFunction
resetParameters
in interface ParametricFunction
public int getActionOffset(Action a)
protected void expandStateActionWeights(int num)
num
- the number of function weights to add to the state-action function weight vectorpublic DenseStateFeatures getStateFeatures()
public double getDefaultWeight()
public void initializeStateWeightVector(int size, double v)
size
- the dimensionality of the weightsv
- the default value to which the weights will be setpublic void initializeStateActionWeightVector(int size, double v)
size
- the dimensionality of the weightsv
- the default value to which the weights will be setpublic java.util.Map<Action,java.lang.Integer> getActionOffset()
Map
of feature index offsets into the full feature vector for each actionMap
of feature index offsets into the full feature vector for each actionpublic void setActionOffset(java.util.Map<Action,java.lang.Integer> actionOffset)
Map
of feature index offsets into the full feature vector for each actionactionOffset
- the Map
of feature index offsets into the full feature vector for each actionpublic void setActionOffset(Action a, int offset)
Map
of feature index offset into the full feature vector for the given actiona
- the action whose feature vector index is to be setoffset
- the feature index offset for the actionpublic DenseLinearVFA copy()
ParametricFunction
ParametricFunction
.copy
in interface ParametricFunction
ParametricFunction
.