public class TileCodingFeatures extends java.lang.Object implements SparseStateFeatures
Different tilings can be created over different dimensions of the converted state feature vector and different tiling widths for each dimension can be specified. Each tiling
over the same dimensions can either be randomly jittered from each other or uniformly distributed across the space, which is specified using the TilingArrangement
enumerator.
To specify the tiling used, use the addTilingsForAllDimensionsWithWidths(double[], int, TilingArrangement)
or
addTilingsForDimensionsAndWidths(boolean[], double[], int, TilingArrangement)
method.
1. Albus, James S. "A theory of cerebellar function." Mathematical Biosciences 10.1 (1971): 25-61
Modifier and Type | Class and Description |
---|---|
protected class |
TileCodingFeatures.ActionFeatureID
A class for associating a
Action with a feature id. |
Modifier and Type | Field and Description |
---|---|
protected DenseStateFeatures |
featureVectorGenerator
The generator that turns OO-MDP state objects into state feature vectors.
|
protected int |
nextStateFeatureId
The identifier to use for the next state feature.
|
protected java.util.Random |
rand
A random object for jittering the tile alignments.
|
Constructor and Description |
---|
TileCodingFeatures(DenseStateFeatures featureVectorGenerator)
Initializes specifying the kind of state feature vector generator to use for turning OO-MDP states into feature vectors.
|
Modifier and Type | Method and Description |
---|---|
void |
addTilingsForAllDimensionsWithWidths(double[] widths,
int nTilings,
TilingArrangement tileArrangement)
Adss a number of tilings where each tile is dependent on *all* the dimensions of a state feature vector.
|
void |
addTilingsForDimensionsAndWidths(boolean[] dimensionMask,
double[] widths,
int nTilings,
TilingArrangement tileArrangement)
Adss a number of tilings where each tile is dependent on the dimensions that are labeled as "true" in the dimensionMask parameter.
|
TileCodingFeatures |
copy()
Returns a deep copy of this feature database.
|
java.util.List<StateFeature> |
features(State s)
Returns non-zero state features for a given state.
|
LinearVFA |
generateVFA(double defaultWeightValue)
After all the tiling specifications have been set, this method can be called to produce a linear
VFA object.
|
protected java.util.List<TileCodingFeatures.ActionFeatureID> |
getOrGenerateActionFeatureList(java.util.Map<Tiling.FVTile,java.util.List<TileCodingFeatures.ActionFeatureID>> tileFeatureMap,
Tiling.FVTile tile)
Returns or creates stores and returns the list of action feature ids in the given map for the given tile.
|
protected int |
getOrGenerateFeature(java.util.Map<Tiling.FVTile,java.lang.Integer> tileFeatureMap,
Tiling.FVTile tile)
Returns the stored feature id or creates, stores and returns one.
|
protected TileCodingFeatures.ActionFeatureID |
matchingActionFeature(java.util.List<TileCodingFeatures.ActionFeatureID> actionFeatures,
Action forAction)
Returns the
TileCodingFeatures.ActionFeatureID with an equivalent Action in the given list or null if there is none. |
int |
numFeatures()
Returns the total number of features
|
protected double[] |
produceRandomOffset(boolean[] dimensionMask,
double[] widths)
Creates and returns a random tiling offset for the given widths and required dimensions.
|
protected double[] |
produceUniformTilingsOffset(boolean[] dimensionMask,
double[] widths,
int ithTiling,
int nTilings)
Creates and returns an offset that is uniformly spaced from other tilings.
|
protected DenseStateFeatures featureVectorGenerator
protected java.util.Random rand
protected int nextStateFeatureId
public TileCodingFeatures(DenseStateFeatures featureVectorGenerator)
featureVectorGenerator
- the OO-MDP state to feature vector generator to usepublic TileCodingFeatures copy()
SparseStateFeatures
copy
in interface SparseStateFeatures
public void addTilingsForDimensionsAndWidths(boolean[] dimensionMask, double[] widths, int nTilings, TilingArrangement tileArrangement)
TilingArrangement.UNIFORM
then each of the nTilings
created with will be uniformly spaced across the width of each dimension. If it is set to TilingArrangement.RANDOM_JITTER
then each tiling
will be offset by a random amount.dimensionMask
- each true entry in this boolen array is a dimension over which the tiling will be defined.widths
- the width of tiles along each dimension. This value should be non-zero for each dimension unless the tiling doesn't depend on that dimension.nTilings
- the number of tilings over the specified dimensions to createtileArrangement
- whether the created tiles are uniformally spaced or randomly spaced.public void addTilingsForAllDimensionsWithWidths(double[] widths, int nTilings, TilingArrangement tileArrangement)
TilingArrangement.UNIFORM
then each of the nTilings
created with will be uniformly spaced across the width of each dimension. If it is set to TilingArrangement.RANDOM_JITTER
then each tiling
will be offset by a random amount.widths
- the width of tiles along each dimension. This value should be non-zero for each dimension .nTilings
- the number of tilings over the specified dimensions to create.tileArrangement
- whether the created tiles are uniformally spaced or randomly spaced.public java.util.List<StateFeature> features(State s)
SparseStateFeatures
features
in interface SparseStateFeatures
s
- the state for which features should be returnedpublic int numFeatures()
SparseStateFeatures
numFeatures
in interface SparseStateFeatures
protected int getOrGenerateFeature(java.util.Map<Tiling.FVTile,java.lang.Integer> tileFeatureMap, Tiling.FVTile tile)
nextStateFeatureId
data member of this
object is incremented.tileFeatureMap
- the map from tiles to feature idstile
- the tile for which a feature id is returned.protected java.util.List<TileCodingFeatures.ActionFeatureID> getOrGenerateActionFeatureList(java.util.Map<Tiling.FVTile,java.util.List<TileCodingFeatures.ActionFeatureID>> tileFeatureMap, Tiling.FVTile tile)
tileFeatureMap
- the map from tiles for a state to the list of action features for that statetile
- the tile for which the list of action features is returned.public LinearVFA generateVFA(double defaultWeightValue)
defaultWeightValue
- the default value weights for the CMAC features will use.protected double[] produceRandomOffset(boolean[] dimensionMask, double[] widths)
dimensionMask
- each true entry is a dimension on which the tiling dependswidths
- the width of each dimensionprotected double[] produceUniformTilingsOffset(boolean[] dimensionMask, double[] widths, int ithTiling, int nTilings)
dimensionMask
- each true entry is a dimension on which the tiling dependswidths
- widths the width of each dimensionithTiling
- which tiling of the nTilings for which this offset is to be generatednTilings
- the total number of tilings that will be uniformaly spacedprotected TileCodingFeatures.ActionFeatureID matchingActionFeature(java.util.List<TileCodingFeatures.ActionFeatureID> actionFeatures, Action forAction)
TileCodingFeatures.ActionFeatureID
with an equivalent Action
in the given list or null if there is none.actionFeatures
- the list of TileCodingFeatures.ActionFeatureID
objects to search.forAction
- the Action
for which a match is to be found.TileCodingFeatures.ActionFeatureID
with an equivalent Action
in the given list or null if there is none.