public class LinearVFA extends java.lang.Object implements DifferentiableStateValue, DifferentiableStateActionValue
SparseStateFeatures
object that will be used to store
retrieve state features. For every feature returned by the feature functions, this class will automatically create a weight associated with it.
The returned approximated value for any state is the linear combination of state features and weights.
This class can also be used for state-action value function approximation, which it will perform by creating state-action features as a cross product of the state features and action set. You should only ever using this class for state-values or state-action values, not both.
ParametricFunction.ParametricStateActionFunction, ParametricFunction.ParametricStateFunction
Modifier and Type | Field and Description |
---|---|
protected java.util.List<StateFeature> |
currentFeatures |
protected FunctionGradient |
currentGradient |
protected double |
currentValue |
protected double |
defaultWeight
A default weight for the functions
|
protected Action |
lastAction |
protected State |
lastState |
protected SparseStateFeatures |
sparseStateFeatures
The state features
|
protected SparseCrossProductFeatures |
stateActionFeatures
The State-action features based on the cross product of state features and actions
|
protected java.util.Map<java.lang.Integer,java.lang.Double> |
weights
A map from feature identifiers to function weights
|
Constructor and Description |
---|
LinearVFA(SparseStateFeatures sparseStateFeatures)
Initializes with a feature database; the default weight value will be zero
|
LinearVFA(SparseStateFeatures sparseStateFeatures,
double defaultWeight)
Initializes
|
Modifier and Type | Method and Description |
---|---|
LinearVFA |
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)
|
double |
getParameter(int i)
Returns the value of the ith parameter value
|
protected double |
getWeight(int weightId) |
FunctionGradient |
gradient(State s)
Returns the gradient of this function
|
FunctionGradient |
gradient(State s,
Action a)
Returns the gradient of this function.
|
int |
numParameters()
Returns the number of parameters defining this function.
|
void |
resetParameters()
Resets the parameters of this function to default values.
|
void |
setParameter(int i,
double p)
Sets the value of the ith parameter to given value
|
protected SparseStateFeatures sparseStateFeatures
protected SparseCrossProductFeatures stateActionFeatures
protected java.util.Map<java.lang.Integer,java.lang.Double> weights
protected double defaultWeight
protected java.util.List<StateFeature> currentFeatures
protected double currentValue
protected FunctionGradient currentGradient
protected State lastState
protected Action lastAction
public LinearVFA(SparseStateFeatures sparseStateFeatures)
sparseStateFeatures
- the feature database to usepublic LinearVFA(SparseStateFeatures sparseStateFeatures, double defaultWeight)
sparseStateFeatures
- the feature database to usedefaultWeight
- the default feature weight to initialize feature weights topublic 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 setprotected double getWeight(int weightId)
public void resetParameters()
ParametricFunction
resetParameters
in interface ParametricFunction
public LinearVFA copy()
ParametricFunction
ParametricFunction
.copy
in interface ParametricFunction
ParametricFunction
.