src.agents.petsplanners package
Submodules
src.agents.petsplanners.CEMPlanner module
CEM Planner for PETS. Note that we’ve had some errors with this in the past, due to not tuning the parameters properly.
- class src.agents.petsplanners.CEMPlanner.CEMPlanner(action_dim: int = 2, action_min: float = -1, action_max: float = 1, n_planner: int = 500, horizon: int = 12, iter_update_steps: int = 3, k_best: int = 5, epsilon: float = 0.001, update_alpha: float = 0.1, lb: float = -0.5, ub: float = 0.5)
Bases:
BasePlannerCEM ( Gaussian Evolutionary Method ) Based Planner. Untuned.
Initialize CEM Planner
- Parameters
action_dim (int, optional) – Number of dimensions in action space. Defaults to 2.
action_min (float, optional) – Minimum action value. Defaults to -1.
action_max (float, optional) – Maximum action value. Defaults to 1.
n_planner (int, optional) – Number of trajectories to plan. Defaults to 500.
horizon (int, optional) – How many steps in the future to plan. Defaults to 12.
iter_update_steps (int, optional) – How many times to iterate on the planning side. Defaults to 3.
k_best (int, optional) – Number of best trajectories to keep. Defaults to 5.
epsilon (float, optional) – Minimum variance of planner. Defaults to 1e-3.
update_alpha (float, optional) – How much to update planner based on results. Defaults to 0.1.
lb (float, optional) – Lower bound. Defaults to -0.5.
ub (float, optional) – Upper bound. Defaults to 0.5.
- get_action(state, dynamics_model: Module) array
Generate action given state and dynamics model
- Parameters
state (torch.Tensor) – State to plan from
dynamics_model (torch.nn.Module) – Dynamics model ( state, action -> nextstate, rewards )
noise (bool, optional) – Whether to add noise to action. Defaults to False.
- Returns
Planned action
- Return type
np.array
- classmethod instantiate_from_config(config_file_location)
Initialize class from config file
- Parameters
config_file_location (path) – Path to config file
- Raises
ValueError – Error loading file
- Returns
object from class.
- Return type
cls
- classmethod instantiate_from_config_dict(config)
Initialize class from config dictionary
- Parameters
config (dictionary) – Create instance of class from dictionary.
- Returns
Object from class and config.
- Return type
cls
- schema = Map({Optional("action_dim"): Int(), Optional("action_min"): Float(), Optional("action_max"): Float(), Optional("n_planner"): Int(), Optional("horizon"): Int(), Optional("iter_update_steps"): Int(), Optional("k_best"): Int(), Optional("epsilon"): Float(), Optional("update_alpha"): Float(), Optional("lb"): Float(), Optional("ub"): Float()})
src.agents.petsplanners.PDDMPlanner module
PDDM Planner. Largely untested.
- class src.agents.petsplanners.PDDMPlanner.PDDMPlanner(action_dim: int = 2, action_min: float = -1, action_max: float = 1, n_planner: int = 500, horizon: int = 12, gamma: float = 1.0, beta: float = 0.5)
Bases:
BasePlannerLikely an iteration of https://github.com/google-research/pddm.
Initialize PDDM Planner
- Parameters
action_dim (int, optional) – Size of action space. Defaults to 2.
action_min (float, optional) – Minimum action value. Defaults to -1.
action_max (float, optional) – Maximum action value. Defaults to 1.
n_planner (int, optional) – Number of trajectories to plan. Defaults to 500.
horizon (int, optional) – Length to plan into the future. Defaults to 12.
gamma (float, optional) – Gamma. Defaults to 1.0.
beta (float, optional) – Beta. Defaults to 0.5.
- get_action(state, dynamics_model: Module, noise: bool = True) array
Generate action given state and dynamics model
- Parameters
state (torch.Tensor) – State to plan from
dynamics_model (torch.nn.Module) – Dynamics model ( state, action -> nextstate, rewards )
noise (bool, optional) – Whether to add noise to action. Defaults to False.
- Returns
Planned action
- Return type
np.array
- classmethod instantiate_from_config(config_file_location)
Initialize class from config file
- Parameters
config_file_location (path) – Path to config file
- Raises
ValueError – Error loading file
- Returns
object from class.
- Return type
cls
- classmethod instantiate_from_config_dict(config)
Initialize class from config dictionary
- Parameters
config (dictionary) – Create instance of class from dictionary.
- Returns
Object from class and config.
- Return type
cls
- schema = Map({Optional("action_dim"): Int(), Optional("action_min"): Float(), Optional("action_max"): Float(), Optional("n_planner"): Int(), Optional("horizon"): Int(), Optional("gamma"): Float(), Optional("beta"): Float()})
src.agents.petsplanners.RandomPlanner module
PDDM Planner. Largely untested.
- class src.agents.petsplanners.RandomPlanner.RandomPlanner(action_dim: int = 2, action_min: float = -1, action_max: float = 1, n_planner: int = 500, horizon: int = 12)
Bases:
BasePlannerRandom Shooting-Based Planner.
Initialize Random Shooting Planner
- Parameters
action_dim (int, optional) – Dimension of action space. Defaults to 2.
action_min (float, optional) – Minimum action. Defaults to -1.
action_max (float, optional) – Maximum action. Defaults to 1.
n_planner (int, optional) – Number of trajectories to test. Defaults to 500.
horizon (int, optional) – Planning horizon. Defaults to 12.
- get_action(state, dynamics_model: Module, noise: bool = False) array
Generate action given state and dynamics model
- Parameters
state (torch.Tensor) – State to plan from
dynamics_model (torch.nn.Module) – Dynamics model ( state, action -> nextstate, rewards )
noise (bool, optional) – Whether to add noise to action. Defaults to False.
- Returns
Planned action
- Return type
np.array
- classmethod instantiate_from_config(config_file_location)
Initialize class from config file
- Parameters
config_file_location (path) – Path to config file
- Raises
ValueError – Error loading file
- Returns
object from class.
- Return type
cls
- classmethod instantiate_from_config_dict(config)
Initialize class from config dictionary
- Parameters
config (dictionary) – Create instance of class from dictionary.
- Returns
Object from class and config.
- Return type
cls
- schema = Map({Optional("action_dim"): Int(), Optional("action_min"): Float(), Optional("action_max"): Float(), Optional("n_planner"): Int(), Optional("horizon"): Int()})
src.agents.petsplanners.base module
- class src.agents.petsplanners.base.BasePlanner(n_planner: int = 500, horizon: int = 12)
Bases:
ABC- get_action(state) array
Generate action given state and dynamics model
- Parameters
state (torch.Tensor) – State to plan from
dynamics_model (torch.nn.Module) – Dynamics model ( state, action -> nextstate, rewards )
noise (bool, optional) – Whether to add noise to action. Defaults to False.
- Returns
Planned action
- Return type
np.array