Projected quantity
Air Force Research Laboratory (AFRL) Autonomous Capabilities Team (ACT3) Reinforcement Learning (RL) Core.
This is a US Government Work not subject to copyright protection in the US.
The use, dissemination or disclosure of data in this file is subject to limitation or restriction. See accompanying README and LICENSE for details.
Sensors for OpenAIGymSimulator
ProjectedQuantity (BaseDictWrapperGlue)
¤
Glue that takes a quantity and a number of angles and projects the quantity in the direction of the angles given.
Source code in corl/glues/common/projected_quantity.py
class ProjectedQuantity(BaseDictWrapperGlue):
"""
Glue that takes a quantity and a number of angles and projects the quantity in the direction of the angles given.
"""
class Fields:
"""
Fields in this glue
"""
PROJECTED_QUANTITY = "projected_quantity"
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
if 'quantity' not in self.glues().keys():
raise KeyError('Missing key: quantity')
@lru_cache(maxsize=1)
def get_unique_name(self) -> str:
wrapped_name = self.glues()["quantity"].get_unique_name()
if wrapped_name is None:
return "ProjectedQuantity"
return "Projected_" + wrapped_name
@lru_cache(maxsize=1)
def observation_space(self) -> gym.spaces.Space:
wrapped_space = list(self.glues()["quantity"].observation_space().spaces.values())[0]
max_wrapped_obs = np.amax(np.array([np.abs(wrapped_space.low), np.abs(wrapped_space.high)]))
d = gym.spaces.dict.Dict()
d.spaces[self.Fields.PROJECTED_QUANTITY] = gym.spaces.Box(-max_wrapped_obs, max_wrapped_obs, shape=(1, ), dtype=np.float32)
return d
@lru_cache(maxsize=1)
def observation_units(self):
"""
Returns Dict space with the units of the 'quantity' glue
"""
d = gym.spaces.dict.Dict()
quantity_glue = self.glues()['quantity']
try:
d.spaces[self.Fields.PROJECTED_QUANTITY] = quantity_glue.config.output_units
except AttributeError:
d.spaces[self.Fields.PROJECTED_QUANTITY] = quantity_glue.observation_units()
return d
def get_observation(self) -> typing.OrderedDict[str, np.ndarray]:
d = OrderedDict()
observations = {k: list(v.get_observation().values())[0] for k, v in self.glues().items()} # type: ignore[union-attr]
projected_value = observations.pop('quantity')
projected_value *= np.prod(np.cos(list(observations.values())))
d[self.Fields.PROJECTED_QUANTITY] = projected_value
return d
def action_space(self):
...
def apply_action(self, action, observation):
...
Fields
¤
Fields in this glue
Source code in corl/glues/common/projected_quantity.py
class Fields:
"""
Fields in this glue
"""
PROJECTED_QUANTITY = "projected_quantity"
action_space(self)
¤
Build the action space for the controller, etc. that defines the action given to apply_action
Returns¤
gym.spaces.Space The gym Space that defines the action given to the apply_action function
Source code in corl/glues/common/projected_quantity.py
def action_space(self):
...
apply_action(self, action, observation)
¤
Apply the action for the controller, etc.
Parameters¤
action The action for the class to apply to the platform observation The current observations before appling the action
Source code in corl/glues/common/projected_quantity.py
def apply_action(self, action, observation):
...
get_observation(self)
¤
Get the actual observation for the platform using the state of the platform, controller, sensors, etc.
Returns¤
EnvSpaceUtil.sample_type The actual observation for this platform from this glue class
Source code in corl/glues/common/projected_quantity.py
def get_observation(self) -> typing.OrderedDict[str, np.ndarray]:
d = OrderedDict()
observations = {k: list(v.get_observation().values())[0] for k, v in self.glues().items()} # type: ignore[union-attr]
projected_value = observations.pop('quantity')
projected_value *= np.prod(np.cos(list(observations.values())))
d[self.Fields.PROJECTED_QUANTITY] = projected_value
return d
observation_units(self)
¤
Returns Dict space with the units of the 'quantity' glue
Source code in corl/glues/common/projected_quantity.py
@lru_cache(maxsize=1)
def observation_units(self):
"""
Returns Dict space with the units of the 'quantity' glue
"""
d = gym.spaces.dict.Dict()
quantity_glue = self.glues()['quantity']
try:
d.spaces[self.Fields.PROJECTED_QUANTITY] = quantity_glue.config.output_units
except AttributeError:
d.spaces[self.Fields.PROJECTED_QUANTITY] = quantity_glue.observation_units()
return d