mlpy.mdp.stateaction.Action.key_to_index¶
-
Action.
key_to_index
(key)¶ Maps internal name to group index.
Maps the internal name of a feature to the index of the corresponding feature grouping. For example for a feature vector consisting of the x-y-z position of the left and the right arm, the features for the left and the right arm can be extracted separately as a group, effectively splitting the feature vector into two vectors with x, y, and z at the positions specified by the the mapping of this function.
Parameters: key : str
The key into the mapping
Returns: int :
The index in the feature array.
Raises: NotImplementedError
If the child class does not implement this function.
Notes
Optionally this method can be overwritten at runtime.
Examples
>>> def my_key_to_index(key) ... return { ... "x": 0, ... "y": 1, ... "z": 2 ... }[key] ... >>> State.description = {'LArm': {'x': 0, 'y': 1, 'z': 2} ... 'RArm': {'x': 3, 'y': 4, 'z': 5}} >>> State.key_to_index = staticmethod(my_key_to_index)
This specifies the mapping in both direction.
>>> state = [0.1, 0.4, 0.3. 4.6. 2.5. 0.9] >>> >>> mapping = State.description['LArm'] >>> >>> larm = np.zeros[len(mapping.keys())] >>> for key, axis in mapping.iteritems(): ... larm[State.key_to_index(key)] = state[axis] ... >>> print larm [0.1, 0.4, 0.3]
This extracts the features for the left arm from the state vector.