public class FVCMACFeatureDatabase extends java.lang.Object implements FeatureDatabase
CMACFeatureDatabase
class instead, otherwise, this implementation is slightly more efficient.
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 CMACFeatureDatabase.TilingArrangement
enumerator.
To specify the tiling used, use the addTilingsForAllDimensionsWithWidths(double[], int, CMACFeatureDatabase.TilingArrangement)
or
addTilingsForDimensionsAndWidths(boolean[], double[], int, CMACFeatureDatabase.TilingArrangement)
method.
1. Albus, James S. "A theory of cerebellar function." Mathematical Biosciences 10.1 (1971): 25-61Modifier and Type | Class and Description |
---|---|
protected class |
FVCMACFeatureDatabase.ActionFeatureID
A class for associating a
GroundedAction with a feature id. |
Modifier and Type | Field and Description |
---|---|
protected StateToFeatureVectorGenerator |
featureVectorGenerator
The generator that turns OO-MDP state objects into state feature vectors.
|
protected int |
nextActionFeatureId
The identifier to use for the next state-action pair feature
|
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 |
---|
FVCMACFeatureDatabase(StateToFeatureVectorGenerator 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 |
---|---|
protected int |
addOrGetMatchingActionFeatureID(java.util.List<FVCMACFeatureDatabase.ActionFeatureID> storedActionFeatures,
GroundedAction ga)
Returns or creates, stores and returns the action feature id for the given
GroundedAction in the list of action features. |
void |
addTilingsForAllDimensionsWithWidths(double[] widths,
int nTilings,
CMACFeatureDatabase.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,
CMACFeatureDatabase.TilingArrangement tileArrangement)
Adss a number of tilings where each tile is dependent on the dimensions that are labeled as "true" in the dimensionMask parameter.
|
FVCMACFeatureDatabase |
copy()
Returns a deep copy of this feature database.
|
void |
freezeDatabaseState(boolean toggle)
Enable or disable the database from generating new features.
|
LinearVFA |
generateVFA(double defaultWeightValue)
After all the tiling specifications have been set, this method can be called to produce a linear
VFA object.
|
java.util.List<ActionFeaturesQuery> |
getActionFeaturesSets(State s,
java.util.List<GroundedAction> actions)
Returns non-zero action features for all of provided actions in state s.
|
protected java.util.List<FVCMACFeatureDatabase.ActionFeatureID> |
getOrGenerateActionFeatureList(java.util.Map<FVTiling.FVTile,java.util.List<FVCMACFeatureDatabase.ActionFeatureID>> tileFeatureMap,
FVTiling.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<FVTiling.FVTile,java.lang.Integer> tileFeatureMap,
FVTiling.FVTile tile)
Returns the stored feature id or creates, stores and returns one.
|
java.util.List<StateFeature> |
getStateFeatures(State s)
Returns non-zero state features for a given state.
|
protected FVCMACFeatureDatabase.ActionFeatureID |
matchingActionFeature(java.util.List<FVCMACFeatureDatabase.ActionFeatureID> actionFeatures,
GroundedAction forAction)
Returns the
FVCMACFeatureDatabase.ActionFeatureID with an equivalent GroundedAction in the given list or null if there is none. |
int |
numberOfFeatures()
Returns the number of features this database tracks.
|
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 StateToFeatureVectorGenerator featureVectorGenerator
protected java.util.Random rand
protected int nextActionFeatureId
protected int nextStateFeatureId
public FVCMACFeatureDatabase(StateToFeatureVectorGenerator featureVectorGenerator)
featureVectorGenerator
- the OO-MDP state to feature vector generator to usepublic FVCMACFeatureDatabase copy()
FeatureDatabase
copy
in interface FeatureDatabase
public void addTilingsForDimensionsAndWidths(boolean[] dimensionMask, double[] widths, int nTilings, CMACFeatureDatabase.TilingArrangement tileArrangement)
CMACFeatureDatabase.TilingArrangement.UNIFORM
then each of the nTilings
created with will be uniformly spaced across the width of each dimension. If it is set to CMACFeatureDatabase.TilingArrangement.RANDOMJITTER
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, CMACFeatureDatabase.TilingArrangement tileArrangement)
CMACFeatureDatabase.TilingArrangement.UNIFORM
then each of the nTilings
created with will be uniformly spaced across the width of each dimension. If it is set to CMACFeatureDatabase.TilingArrangement.RANDOMJITTER
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> getStateFeatures(State s)
FeatureDatabase
getStateFeatures
in interface FeatureDatabase
s
- the state for which features should be returnedpublic int numberOfFeatures()
FeatureDatabase
numberOfFeatures
in interface FeatureDatabase
protected int getOrGenerateFeature(java.util.Map<FVTiling.FVTile,java.lang.Integer> tileFeatureMap, FVTiling.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.public java.util.List<ActionFeaturesQuery> getActionFeaturesSets(State s, java.util.List<GroundedAction> actions)
FeatureDatabase
getActionFeaturesSets
in interface FeatureDatabase
s
- the state for which features should be returnedactions
- the action set for which the action features should be returnedprotected java.util.List<FVCMACFeatureDatabase.ActionFeatureID> getOrGenerateActionFeatureList(java.util.Map<FVTiling.FVTile,java.util.List<FVCMACFeatureDatabase.ActionFeatureID>> tileFeatureMap, FVTiling.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.protected int addOrGetMatchingActionFeatureID(java.util.List<FVCMACFeatureDatabase.ActionFeatureID> storedActionFeatures, GroundedAction ga)
GroundedAction
in the list of action features. If a
a new action feature id is created, then the nextActionFeatureId
datamember of this object is incremented.storedActionFeatures
- the stores list of action features.ga
- the grounded action whose associated feature should be returned (or created, stored, and returned)public LinearVFA generateVFA(double defaultWeightValue)
defaultWeightValue
- the default value weights for the CMAC features will use.public void freezeDatabaseState(boolean toggle)
FeatureDatabase
freezeDatabaseState
in interface FeatureDatabase
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 FVCMACFeatureDatabase.ActionFeatureID matchingActionFeature(java.util.List<FVCMACFeatureDatabase.ActionFeatureID> actionFeatures, GroundedAction forAction)
FVCMACFeatureDatabase.ActionFeatureID
with an equivalent GroundedAction
in the given list or null if there is none.actionFeatures
- the list of FVCMACFeatureDatabase.ActionFeatureID
objects to search.forAction
- the GroundedAction
for which a match is to be found.FVCMACFeatureDatabase.ActionFeatureID
with an equivalent GroundedAction
in the given list or null if there is none.