code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def __getstate__(self): """Refuse to be pickled. Raises: ValueError: Always raised, since pickling Workers is not supported. """ raise ValueError('Workers are not pickleable. ' 'Please pickle the WorkerFactory instead.')
Refuse to be pickled. Raises: ValueError: Always raised, since pickling Workers is not supported.
__getstate__
python
rlworkgroup/garage
src/garage/sampler/worker.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/sampler/worker.py
MIT
def prepare_worker_messages(self, objs, preprocess=identity_function): """Take an argument and canonicalize it into a list for all workers. This helper function is used to handle arguments in the sampler API which may (optionally) be lists. Specifically, these are agent, env, agent_upda...
Take an argument and canonicalize it into a list for all workers. This helper function is used to handle arguments in the sampler API which may (optionally) be lists. Specifically, these are agent, env, agent_update, and env_update. Checks that the number of parameters is correct. ...
prepare_worker_messages
python
rlworkgroup/garage
src/garage/sampler/worker_factory.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/sampler/worker_factory.py
MIT
def __call__(self, worker_number): """Construct a worker given its number. Args: worker_number(int): The worker number. Should be at least 0 and less than or equal to `n_workers`. Raises: ValueError: If the worker number is greater than `n_workers`. ...
Construct a worker given its number. Args: worker_number(int): The worker number. Should be at least 0 and less than or equal to `n_workers`. Raises: ValueError: If the worker number is greater than `n_workers`. Returns: garage.sampler.Worke...
__call__
python
rlworkgroup/garage
src/garage/sampler/worker_factory.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/sampler/worker_factory.py
MIT
def step(self, action, agent_info): """Step the episode using an action from an agent. Args: action (np.ndarray): The action taken by the agent. agent_info (dict[str, np.ndarray]): Extra agent information. Returns: np.ndarray: The new observation from the en...
Step the episode using an action from an agent. Args: action (np.ndarray): The action taken by the agent. agent_info (dict[str, np.ndarray]): Extra agent information. Returns: np.ndarray: The new observation from the environment.
step
python
rlworkgroup/garage
src/garage/sampler/_dtypes.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/sampler/_dtypes.py
MIT
def to_batch(self): """Convert this in-progress episode into a EpisodeBatch. Returns: EpisodeBatch: This episode as a batch. Raises: AssertionError: If this episode contains no time steps. """ assert len(self.rewards) > 0 env_infos = dict(self.e...
Convert this in-progress episode into a EpisodeBatch. Returns: EpisodeBatch: This episode as a batch. Raises: AssertionError: If this episode contains no time steps.
to_batch
python
rlworkgroup/garage
src/garage/sampler/_dtypes.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/sampler/_dtypes.py
MIT
def _apply_env_update(old_env, env_update): """Use any non-None env_update as a new environment. A simple env update function. If env_update is not None, it should be the complete new environment. This allows changing environments by passing the new environment as `env_update` into `obtain_samples...
Use any non-None env_update as a new environment. A simple env update function. If env_update is not None, it should be the complete new environment. This allows changing environments by passing the new environment as `env_update` into `obtain_samples`. Args: old_env (Environment): Enviro...
_apply_env_update
python
rlworkgroup/garage
src/garage/sampler/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/sampler/_functions.py
MIT
def compile_function(inputs, outputs): """Compiles a tensorflow function using the current session. Args: inputs (list[tf.Tensor]): Inputs to the function. Can be a list of inputs or just one. outputs (list[tf.Tensor]): Outputs of the function. Can be a list of outputs o...
Compiles a tensorflow function using the current session. Args: inputs (list[tf.Tensor]): Inputs to the function. Can be a list of inputs or just one. outputs (list[tf.Tensor]): Outputs of the function. Can be a list of outputs or just one. Returns: Callable: Co...
compile_function
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def get_target_ops(variables, target_variables, tau=None): """Get target variables update operations. In RL algorithms we often update target network every n steps. This function returns the tf.Operation for updating target variables (denoted by target_var) from variables (denote by var) with fract...
Get target variables update operations. In RL algorithms we often update target network every n steps. This function returns the tf.Operation for updating target variables (denoted by target_var) from variables (denote by var) with fraction tau. In other words, each time we want to keep tau of the ...
get_target_ops
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def flatten_batch_dict(d, name='flatten_batch_dict'): """Flatten a batch of observations represented as a dict. Args: d (dict[tf.Tensor]): A dict of Tensors to flatten. name (string): The name of the operation (None by default). Returns: dict[tf.Tensor]: A dict with flattened tenso...
Flatten a batch of observations represented as a dict. Args: d (dict[tf.Tensor]): A dict of Tensors to flatten. name (string): The name of the operation (None by default). Returns: dict[tf.Tensor]: A dict with flattened tensors.
flatten_batch_dict
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def filter_valids(t, valid, name='filter_valids'): """Filter out tensor using valid array. Args: t (tf.Tensor): The tensor to filter. valid (list[float]): Array of length of the valid values (either 0 or 1). name (string): Name of the operation. Returns: tf.Tens...
Filter out tensor using valid array. Args: t (tf.Tensor): The tensor to filter. valid (list[float]): Array of length of the valid values (either 0 or 1). name (string): Name of the operation. Returns: tf.Tensor: Filtered Tensor.
filter_valids
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def filter_valids_dict(d, valid, name='filter_valids_dict'): """Filter valid values on a dict. Args: d (dict[tf.Tensor]): Dict of tensors to be filtered. valid (list[float]): Array of length of the valid values (elements can be either 0 or 1). name (string): Name of the operatio...
Filter valid values on a dict. Args: d (dict[tf.Tensor]): Dict of tensors to be filtered. valid (list[float]): Array of length of the valid values (elements can be either 0 or 1). name (string): Name of the operation. None by default. Returns: dict[tf.Tensor]: Dict with...
filter_valids_dict
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def flatten_inputs(deep): """Flattens an :class:`collections.abc.Iterable` recursively. Args: deep (Iterable): An :class:`~collections.abc.Iterable` to flatten. Returns: list: The flattened result. """ def flatten(deep): # pylint: disable=missing-yield-doc,missing-yield-ty...
Flattens an :class:`collections.abc.Iterable` recursively. Args: deep (Iterable): An :class:`~collections.abc.Iterable` to flatten. Returns: list: The flattened result.
flatten_inputs
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def new_tensor(name, ndim, dtype): """Creates a placeholder :class:`tf.Tensor` with the specified arguments. Args: name (string): Name of the tf.Tensor. ndim (int): Number of dimensions of the tf.Tensor. dtype (type): Data type of the tf.Tensor's contents. Returns: tf.Tenso...
Creates a placeholder :class:`tf.Tensor` with the specified arguments. Args: name (string): Name of the tf.Tensor. ndim (int): Number of dimensions of the tf.Tensor. dtype (type): Data type of the tf.Tensor's contents. Returns: tf.Tensor: Placeholder tensor.
new_tensor
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def concat_tensor_dict_list(tensor_dict_list): """Concatenates a dict of tensors lists. Each list of tensors gets concatenated into one tensor. Args: tensor_dict_list (dict[list[ndarray]]): Dict with lists of tensors. Returns: dict[ndarray]: A dict with the concatenated tensors. "...
Concatenates a dict of tensors lists. Each list of tensors gets concatenated into one tensor. Args: tensor_dict_list (dict[list[ndarray]]): Dict with lists of tensors. Returns: dict[ndarray]: A dict with the concatenated tensors.
concat_tensor_dict_list
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def stack_tensor_dict_list(tensor_dict_list): """Stack a list of dictionaries of {tensors or dictionary of tensors}. Args: tensor_dict_list (dict): a list of dictionaries of {tensors or dictionary of tensors}. Returns: dict: a dictionary of {stacked tensors or dictionary of sta...
Stack a list of dictionaries of {tensors or dictionary of tensors}. Args: tensor_dict_list (dict): a list of dictionaries of {tensors or dictionary of tensors}. Returns: dict: a dictionary of {stacked tensors or dictionary of stacked tensors}.
stack_tensor_dict_list
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def split_tensor_dict_list(tensor_dict): """Split a list of dictionaries of {tensors or dictionary of tensors}. Args: tensor_dict (dict): a list of dictionaries of {tensors or dictionary of tensors}. Returns: dict: a dictionary of {split tensors or dictionary of split tensors}. ...
Split a list of dictionaries of {tensors or dictionary of tensors}. Args: tensor_dict (dict): a list of dictionaries of {tensors or dictionary of tensors}. Returns: dict: a dictionary of {split tensors or dictionary of split tensors}.
split_tensor_dict_list
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def pad_tensor(x, max_len): """Pad tensors with zeros. Args: x (numpy.ndarray): Tensors to be padded. max_len (int): Maximum length. Returns: numpy.ndarray: Padded tensor. """ return np.concatenate([ x, np.tile(np.zeros_like(x[0]), (max_len -...
Pad tensors with zeros. Args: x (numpy.ndarray): Tensors to be padded. max_len (int): Maximum length. Returns: numpy.ndarray: Padded tensor.
pad_tensor
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def pad_tensor_n(xs, max_len): """Pad array of tensors. Args: xs (numpy.ndarray): Tensors to be padded. max_len (int): Maximum length. Returns: numpy.ndarray: Padded tensor. """ ret = np.zeros((len(xs), max_len) + xs[0].shape[1:], dtype=xs[0].dtype) for idx, x in enumer...
Pad array of tensors. Args: xs (numpy.ndarray): Tensors to be padded. max_len (int): Maximum length. Returns: numpy.ndarray: Padded tensor.
pad_tensor_n
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def pad_tensor_dict(tensor_dict, max_len): """Pad dictionary of tensors with zeros. Args: tensor_dict (dict[numpy.ndarray]): Tensors to be padded. max_len (int): Maximum length. Returns: dict[numpy.ndarray]: Padded tensor. """ keys = list(tensor_dict.keys()) ret = dict(...
Pad dictionary of tensors with zeros. Args: tensor_dict (dict[numpy.ndarray]): Tensors to be padded. max_len (int): Maximum length. Returns: dict[numpy.ndarray]: Padded tensor.
pad_tensor_dict
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def compute_advantages(discount, gae_lambda, max_len, baselines, rewards, name='compute_advantages'): """Calculate advantages. Advantages are a discounted cumulative sum. The discount cumulat...
Calculate advantages. Advantages are a discounted cumulative sum. The discount cumulative sum can be represented as an IIR filter ob the reversed input vectors, i.e. y[t] - discount*y[t+1] = x[t], or rev(y)[t] - discount*rev(y)[t-1] = rev(x)[t] Given the time-domain IIR filter step response,...
compute_advantages
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def center_advs(advs, axes, eps, offset=0, scale=1, name='center_adv'): """Normalize the advs tensor. This calculates the mean and variance using the axes specified and normalizes the tensor using those values. Args: advs (tf.Tensor): Tensor to normalize. axes (array[int]): Axes along ...
Normalize the advs tensor. This calculates the mean and variance using the axes specified and normalizes the tensor using those values. Args: advs (tf.Tensor): Tensor to normalize. axes (array[int]): Axes along which to compute the mean and variance. eps (float): Small number to av...
center_advs
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def positive_advs(advs, eps, name='positive_adv'): """Make all the values in the advs tensor positive. Offsets all values in advs by the minimum value in the tensor, plus an epsilon value to avoid dividing by zero. Args: advs (tf.Tensor): The tensor to offset. eps (tf.float32): A small...
Make all the values in the advs tensor positive. Offsets all values in advs by the minimum value in the tensor, plus an epsilon value to avoid dividing by zero. Args: advs (tf.Tensor): The tensor to offset. eps (tf.float32): A small value to avoid by-zero division. name (string): N...
positive_advs
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def discounted_returns(discount, max_len, rewards, name='discounted_returns'): """Calculate discounted returns. Args: discount (float): Discount factor. max_len (int): Maximum length of a single episode. rewards (tf.Tensor): A 2D vector of per-step rewards with shape :math:`...
Calculate discounted returns. Args: discount (float): Discount factor. max_len (int): Maximum length of a single episode. rewards (tf.Tensor): A 2D vector of per-step rewards with shape :math:`(N, T)`, where :math:`N` is the batch dimension (number of episodes) and :...
discounted_returns
python
rlworkgroup/garage
src/garage/tf/_functions.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/_functions.py
MIT
def _init_opt(self): """Build the loss function and init the optimizer.""" with tf.name_scope(self._name): # Create target policy and qf network with tf.name_scope('inputs'): obs_dim = self._env_spec.observation_space.flat_dim input_y = tf.compat.v...
Build the loss function and init the optimizer.
_init_opt
python
rlworkgroup/garage
src/garage/tf/algos/ddpg.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/ddpg.py
MIT
def __getstate__(self): """Object.__getstate__. Returns: dict: the state to be pickled for the instance. """ data = self.__dict__.copy() del data['_target_policy_f_prob_online'] del data['_target_qf_f_prob_online'] del data['_f_train_policy'] ...
Object.__getstate__. Returns: dict: the state to be pickled for the instance.
__getstate__
python
rlworkgroup/garage
src/garage/tf/algos/ddpg.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/ddpg.py
MIT
def train(self, trainer): """Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Experiment trainer, which provides services such as snapshotting and sampler control. Returns: float: The average return in last epoch cycle. ...
Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Experiment trainer, which provides services such as snapshotting and sampler control. Returns: float: The average return in last epoch cycle.
train
python
rlworkgroup/garage
src/garage/tf/algos/ddpg.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/ddpg.py
MIT
def _train_once(self, itr, episodes): """Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. """ self._replay_buffer.add_episode_batch(episodes) epoch = itr / ...
Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes.
_train_once
python
rlworkgroup/garage
src/garage/tf/algos/ddpg.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/ddpg.py
MIT
def _optimize_policy(self): """Perform algorithm optimizing. Returns: float: Loss of action predicted by the policy network float: Loss of q value predicted by the q network. float: ys. float: Q value predicted by the q network. """ times...
Perform algorithm optimizing. Returns: float: Loss of action predicted by the policy network float: Loss of q value predicted by the q network. float: ys. float: Q value predicted by the q network.
_optimize_policy
python
rlworkgroup/garage
src/garage/tf/algos/ddpg.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/ddpg.py
MIT
def _init_opt(self): """Initialize the networks and Ops. Assume discrete space for dqn, so action dimension will always be action_space.n """ action_dim = self._env_spec.action_space.n # build q networks with tf.name_scope(self._name): action_t_ph = ...
Initialize the networks and Ops. Assume discrete space for dqn, so action dimension will always be action_space.n
_init_opt
python
rlworkgroup/garage
src/garage/tf/algos/dqn.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/dqn.py
MIT
def train(self, trainer): """Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Experiment trainer, which provides services such as snapshotting and sampler control. Returns: float: The average return in last epoch cycle. ...
Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Experiment trainer, which provides services such as snapshotting and sampler control. Returns: float: The average return in last epoch cycle.
train
python
rlworkgroup/garage
src/garage/tf/algos/dqn.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/dqn.py
MIT
def _train_once(self, itr, episodes): """Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. Returns: list[float]: Q function losses """ self._rep...
Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. Returns: list[float]: Q function losses
_train_once
python
rlworkgroup/garage
src/garage/tf/algos/dqn.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/dqn.py
MIT
def _optimize_policy(self): """Optimize network using experiences from replay buffer. Returns: numpy.float64: Loss of policy. """ timesteps = self._replay_buffer.sample_timesteps( self._buffer_batch_size) observations = timesteps.observations re...
Optimize network using experiences from replay buffer. Returns: numpy.float64: Loss of policy.
_optimize_policy
python
rlworkgroup/garage
src/garage/tf/algos/dqn.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/dqn.py
MIT
def __getstate__(self): """Parameters to save in snapshot. Returns: dict: Parameters to save. """ data = self.__dict__.copy() del data['_qf_update_ops'] del data['_train_qf'] return data
Parameters to save in snapshot. Returns: dict: Parameters to save.
__getstate__
python
rlworkgroup/garage
src/garage/tf/algos/dqn.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/dqn.py
MIT
def train(self, trainer): """Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Experiment trainer, which rovides services such as snapshotting and sampler control. Returns: float: The average return in last epoch cycle. ...
Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Experiment trainer, which rovides services such as snapshotting and sampler control. Returns: float: The average return in last epoch cycle.
train
python
rlworkgroup/garage
src/garage/tf/algos/npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/npo.py
MIT
def _train_once(self, itr, episodes): """Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. Returns: numpy.float64: Average return. """ # -- Stag...
Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. Returns: numpy.float64: Average return.
_train_once
python
rlworkgroup/garage
src/garage/tf/algos/npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/npo.py
MIT
def _optimize_policy(self, episodes, baselines): """Optimize policy. Args: episodes (EpisodeBatch): Batch of episodes. baselines (np.ndarray): Baseline predictions. """ policy_opt_input_values = self._policy_opt_input_values( episodes, baselines) ...
Optimize policy. Args: episodes (EpisodeBatch): Batch of episodes. baselines (np.ndarray): Baseline predictions.
_optimize_policy
python
rlworkgroup/garage
src/garage/tf/algos/npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/npo.py
MIT
def _build_inputs(self): """Build input variables. Returns: namedtuple: Collection of variables to compute policy loss. namedtuple: Collection of variables to do policy optimization. """ observation_space = self.policy.observation_space action_space = se...
Build input variables. Returns: namedtuple: Collection of variables to compute policy loss. namedtuple: Collection of variables to do policy optimization.
_build_inputs
python
rlworkgroup/garage
src/garage/tf/algos/npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/npo.py
MIT
def _build_policy_loss(self, i): """Build policy loss and other output tensors. Args: i (namedtuple): Collection of variables to compute policy loss. Returns: tf.Tensor: Policy loss. tf.Tensor: Mean policy KL divergence. """ policy_entropy =...
Build policy loss and other output tensors. Args: i (namedtuple): Collection of variables to compute policy loss. Returns: tf.Tensor: Policy loss. tf.Tensor: Mean policy KL divergence.
_build_policy_loss
python
rlworkgroup/garage
src/garage/tf/algos/npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/npo.py
MIT
def _build_entropy_term(self, i): """Build policy entropy tensor. Args: i (namedtuple): Collection of variables to compute policy loss. Returns: tf.Tensor: Policy entropy. """ pol_dist = self._policy_network.dist with tf.name_scope('policy_entr...
Build policy entropy tensor. Args: i (namedtuple): Collection of variables to compute policy loss. Returns: tf.Tensor: Policy entropy.
_build_entropy_term
python
rlworkgroup/garage
src/garage/tf/algos/npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/npo.py
MIT
def _fit_baseline_with_data(self, episodes, baselines): """Update baselines from samples. Args: episodes (EpisodeBatch): Batch of episodes. baselines (np.ndarray): Baseline predictions. Returns: np.ndarray: Augment returns. """ policy_opt_in...
Update baselines from samples. Args: episodes (EpisodeBatch): Batch of episodes. baselines (np.ndarray): Baseline predictions. Returns: np.ndarray: Augment returns.
_fit_baseline_with_data
python
rlworkgroup/garage
src/garage/tf/algos/npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/npo.py
MIT
def _policy_opt_input_values(self, episodes, baselines): """Map episode samples to the policy optimizer inputs. Args: episodes (EpisodeBatch): Batch of episodes. baselines (np.ndarray): Baseline predictions. Returns: list(np.ndarray): Flatten policy optimiza...
Map episode samples to the policy optimizer inputs. Args: episodes (EpisodeBatch): Batch of episodes. baselines (np.ndarray): Baseline predictions. Returns: list(np.ndarray): Flatten policy optimization input values.
_policy_opt_input_values
python
rlworkgroup/garage
src/garage/tf/algos/npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/npo.py
MIT
def _check_entropy_configuration(self, entropy_method, center_adv, stop_entropy_gradient, use_neg_logli_entropy, policy_ent_coeff): """Check entropy configuration. Args: entropy_method (str): A string from: 'max', 're...
Check entropy configuration. Args: entropy_method (str): A string from: 'max', 'regularized', 'no_entropy'. The type of entropy method to use. 'max' adds the dense entropy to the reward for each time step. 'regularized' adds the mean entropy to the su...
_check_entropy_configuration
python
rlworkgroup/garage
src/garage/tf/algos/npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/npo.py
MIT
def __getstate__(self): """Parameters to save in snapshot. Returns: dict: Parameters to save. """ data = self.__dict__.copy() del data['_name_scope'] del data['_policy_opt_inputs'] del data['_f_policy_entropy'] del data['_f_policy_kl'] ...
Parameters to save in snapshot. Returns: dict: Parameters to save.
__getstate__
python
rlworkgroup/garage
src/garage/tf/algos/npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/npo.py
MIT
def __setstate__(self, state): """Parameters to restore from snapshot. Args: state (dict): Parameters to restore from. """ self.__dict__ = state self._name_scope = tf.name_scope(self._name) self._init_opt()
Parameters to restore from snapshot. Args: state (dict): Parameters to restore from.
__setstate__
python
rlworkgroup/garage
src/garage/tf/algos/npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/npo.py
MIT
def train(self, trainer): """Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Experiment trainer, which provides services such as snapshotting and sampler control. Returns: float: The average return in last epoch cycle. ...
Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Experiment trainer, which provides services such as snapshotting and sampler control. Returns: float: The average return in last epoch cycle.
train
python
rlworkgroup/garage
src/garage/tf/algos/reps.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/reps.py
MIT
def _train_once(self, itr, episodes): """Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. Returns: numpy.float64: Average return. """ # -- Stag...
Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. Returns: numpy.float64: Average return.
_train_once
python
rlworkgroup/garage
src/garage/tf/algos/reps.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/reps.py
MIT
def __getstate__(self): """Parameters to save in snapshot. Returns: dict: Parameters to save. """ data = self.__dict__.copy() del data['_name_scope'] del data['_policy_opt_inputs'] del data['_dual_opt_inputs'] del data['_f_dual'] del ...
Parameters to save in snapshot. Returns: dict: Parameters to save.
__getstate__
python
rlworkgroup/garage
src/garage/tf/algos/reps.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/reps.py
MIT
def __setstate__(self, state): """Parameters to restore from snapshot. Args: state (dict): Parameters to restore from. """ self.__dict__ = state self._name_scope = tf.name_scope(self._name) self._init_opt()
Parameters to restore from snapshot. Args: state (dict): Parameters to restore from.
__setstate__
python
rlworkgroup/garage
src/garage/tf/algos/reps.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/reps.py
MIT
def _optimize_policy(self, episodes): """Optimize the policy using the samples. Args: episodes (EpisodeBatch): Batch of episodes. """ # Initial BFGS parameter values. x0 = np.hstack([self._param_eta, self._param_v]) # Set parameter boundaries: \eta>=1e-12, v...
Optimize the policy using the samples. Args: episodes (EpisodeBatch): Batch of episodes.
_optimize_policy
python
rlworkgroup/garage
src/garage/tf/algos/reps.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/reps.py
MIT
def eval_dual(x): """Evaluate dual function loss. Args: x (numpy.ndarray): Input to dual function. Returns: numpy.float64: Dual function loss. """ self._param_eta = x[0] self._param_v = x[1:] dual_opt_...
Evaluate dual function loss. Args: x (numpy.ndarray): Input to dual function. Returns: numpy.float64: Dual function loss.
eval_dual
python
rlworkgroup/garage
src/garage/tf/algos/reps.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/reps.py
MIT
def eval_dual_grad(x): """Evaluate gradient of dual function loss. Args: x (numpy.ndarray): Input to dual function. Returns: numpy.ndarray: Gradient of dual function loss. """ self._param_eta = x[0] self._param_v ...
Evaluate gradient of dual function loss. Args: x (numpy.ndarray): Input to dual function. Returns: numpy.ndarray: Gradient of dual function loss.
eval_dual_grad
python
rlworkgroup/garage
src/garage/tf/algos/reps.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/reps.py
MIT
def _build_inputs(self): """Build input variables. Returns: namedtuple: Collection of variables to compute policy loss. namedtuple: Collection of variables to do policy optimization. """ observation_space = self.policy.observation_space action_space = se...
Build input variables. Returns: namedtuple: Collection of variables to compute policy loss. namedtuple: Collection of variables to do policy optimization.
_build_inputs
python
rlworkgroup/garage
src/garage/tf/algos/reps.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/reps.py
MIT
def _build_policy_loss(self, i): """Build policy loss and other output tensors. Args: i (namedtuple): Collection of variables to compute policy loss. Returns: tf.Tensor: Policy loss. tf.Tensor: Mean policy KL divergence. Raises: NotImple...
Build policy loss and other output tensors. Args: i (namedtuple): Collection of variables to compute policy loss. Returns: tf.Tensor: Policy loss. tf.Tensor: Mean policy KL divergence. Raises: NotImplementedError: If is_recurrent is True. ...
_build_policy_loss
python
rlworkgroup/garage
src/garage/tf/algos/reps.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/reps.py
MIT
def _dual_opt_input_values(self, episodes): """Update dual func optimize input values based on samples data. Args: episodes (EpisodeBatch): Batch of episodes. Returns: list(np.ndarray): Flatten dual function optimization input values. """ agent_infos = ...
Update dual func optimize input values based on samples data. Args: episodes (EpisodeBatch): Batch of episodes. Returns: list(np.ndarray): Flatten dual function optimization input values.
_dual_opt_input_values
python
rlworkgroup/garage
src/garage/tf/algos/reps.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/reps.py
MIT
def _policy_opt_input_values(self, episodes): """Update policy optimize input values based on samples data. Args: episodes (EpisodeBatch): Batch of episodes. Returns: list(np.ndarray): Flatten policy optimization input values. """ agent_infos = episodes...
Update policy optimize input values based on samples data. Args: episodes (EpisodeBatch): Batch of episodes. Returns: list(np.ndarray): Flatten policy optimization input values.
_policy_opt_input_values
python
rlworkgroup/garage
src/garage/tf/algos/reps.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/reps.py
MIT
def _features(self, episodes): """Get valid view features based on samples data. Args: episodes (EpisodeBatch): Batch of episodes. Returns: numpy.ndarray: Features for training. """ start = 0 feat_diff = [] for length in episodes.lengths...
Get valid view features based on samples data. Args: episodes (EpisodeBatch): Batch of episodes. Returns: numpy.ndarray: Features for training.
_features
python
rlworkgroup/garage
src/garage/tf/algos/reps.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/reps.py
MIT
def step(self, action): """Call step on wrapped env. Args: action (np.ndarray): An action provided by the agent. Returns: EnvStep: The environment step resulting from the action. Raises: RuntimeError: if `step()` is called after the environment has ...
Call step on wrapped env. Args: action (np.ndarray): An action provided by the agent. Returns: EnvStep: The environment step resulting from the action. Raises: RuntimeError: if `step()` is called after the environment has been constructed an...
step
python
rlworkgroup/garage
src/garage/tf/algos/rl2.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/rl2.py
MIT
def _create_rl2_obs_space(self): """Create observation space for RL2. Returns: akro.Box: Augmented observation space. """ obs_flat_dim = np.prod(self._env.observation_space.shape) action_flat_dim = np.prod(self._env.action_space.shape) return akro.Box(low=-n...
Create observation space for RL2. Returns: akro.Box: Augmented observation space.
_create_rl2_obs_space
python
rlworkgroup/garage
src/garage/tf/algos/rl2.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/rl2.py
MIT
def rollout(self): """Sample a single episode of the agent in the environment. Returns: EpisodeBatch: The collected episode. """ self.agent.reset() for _ in range(self._n_episodes_per_trial): self.start_episode() while not self.step_episode()...
Sample a single episode of the agent in the environment. Returns: EpisodeBatch: The collected episode.
rollout
python
rlworkgroup/garage
src/garage/tf/algos/rl2.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/rl2.py
MIT
def set_param_values(self, params): """Set param values. Args: params (Tuple[np.ndarray, np.ndarray]): Two numpy array of parameter values, one of the network parameters, one for the initial hidden state. """ inner_params, hiddens = params ...
Set param values. Args: params (Tuple[np.ndarray, np.ndarray]): Two numpy array of parameter values, one of the network parameters, one for the initial hidden state.
set_param_values
python
rlworkgroup/garage
src/garage/tf/algos/rl2.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/rl2.py
MIT
def train(self, trainer): """Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Experiment trainer, which provides services such as snapshotting and sampler control. Returns: float: The average return in last epoch. ...
Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Experiment trainer, which provides services such as snapshotting and sampler control. Returns: float: The average return in last epoch.
train
python
rlworkgroup/garage
src/garage/tf/algos/rl2.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/rl2.py
MIT
def train_once(self, itr, episodes): """Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. Returns: numpy.float64: Average return. """ episodes, ...
Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. Returns: numpy.float64: Average return.
train_once
python
rlworkgroup/garage
src/garage/tf/algos/rl2.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/rl2.py
MIT
def _process_samples(self, itr, episodes): # pylint: disable=too-many-statements """Return processed sample data based on the collected paths. Args: itr (int): Iteration number. episodes (EpisodeBatch): Original collected episode batch for each task. For ...
Return processed sample data based on the collected paths. Args: itr (int): Iteration number. episodes (EpisodeBatch): Original collected episode batch for each task. For each episode, episode.agent_infos['batch_idx'] indicates which task this episode bel...
_process_samples
python
rlworkgroup/garage
src/garage/tf/algos/rl2.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/rl2.py
MIT
def _concatenate_episodes(self, episode_list): """Concatenate episodes. The input list contains samples from different episodes but same task/environment. In RL^2, paths within each meta batch are all concatenate into a single path and fed to the policy. Args: episo...
Concatenate episodes. The input list contains samples from different episodes but same task/environment. In RL^2, paths within each meta batch are all concatenate into a single path and fed to the policy. Args: episode_list (list[EpisodeBatch]): Input paths. All paths are f...
_concatenate_episodes
python
rlworkgroup/garage
src/garage/tf/algos/rl2.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/rl2.py
MIT
def _init_opt(self): """Build the loss function and init the optimizer.""" with tf.name_scope(self._name): # Create target policy (actor) and qf (critic) networks with tf.name_scope('inputs'): obs_dim = self._env_spec.observation_space.flat_dim y =...
Build the loss function and init the optimizer.
_init_opt
python
rlworkgroup/garage
src/garage/tf/algos/td3.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/td3.py
MIT
def train(self, trainer): """Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Experiment trainer, which provides services such as snapshotting and sampler control. Returns: float: The average return in last epoch cycle. ...
Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Experiment trainer, which provides services such as snapshotting and sampler control. Returns: float: The average return in last epoch cycle.
train
python
rlworkgroup/garage
src/garage/tf/algos/td3.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/td3.py
MIT
def _train_once(self, itr, episodes): """Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. """ self._replay_buffer.add_episode_batch(episodes) epoch = itr /...
Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes.
_train_once
python
rlworkgroup/garage
src/garage/tf/algos/td3.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/td3.py
MIT
def _optimize_policy(self, itr): """Perform algorithm optimizing. Args: itr(int): Iterations. Returns: float: Loss of action predicted by the policy network. float: Loss of q value predicted by the q network. float: y_s. float: Q valu...
Perform algorithm optimizing. Args: itr(int): Iterations. Returns: float: Loss of action predicted by the policy network. float: Loss of q value predicted by the q network. float: y_s. float: Q value predicted by the q network.
_optimize_policy
python
rlworkgroup/garage
src/garage/tf/algos/td3.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/td3.py
MIT
def step_episode(self): """Take a single time-step in the current episode. Returns: bool: True iff the episode is done, either due to the environment indicating termination of due to reaching `max_episode_length`. """ if self._eps_length < self._max_episode_...
Take a single time-step in the current episode. Returns: bool: True iff the episode is done, either due to the environment indicating termination of due to reaching `max_episode_length`.
step_episode
python
rlworkgroup/garage
src/garage/tf/algos/te.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te.py
MIT
def collect_episode(self): """Collect the current episode, clearing the internal buffer. One-hot task id is saved in env_infos['task_onehot']. Latent is saved in agent_infos['latent']. Latent infos are saved in agent_infos['latent_info_name'], where info_name is the original latent ...
Collect the current episode, clearing the internal buffer. One-hot task id is saved in env_infos['task_onehot']. Latent is saved in agent_infos['latent']. Latent infos are saved in agent_infos['latent_info_name'], where info_name is the original latent info name. Returns: ...
collect_episode
python
rlworkgroup/garage
src/garage/tf/algos/te.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te.py
MIT
def _init_opt(self): """Initialize optimizater. Raises: NotImplementedError: Raise if the policy is recurrent. """ # Input variables (pol_loss_inputs, pol_opt_inputs, infer_loss_inputs, infer_opt_inputs) = self._build_inputs() self._policy_opt_inpu...
Initialize optimizater. Raises: NotImplementedError: Raise if the policy is recurrent.
_init_opt
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def train(self, trainer): """Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Trainer is passed to give algorithm the access to trainer.step_epochs(), which provides services such as snapshotting and sampler control. ...
Obtain samplers and start actual training for each epoch. Args: trainer (Trainer): Trainer is passed to give algorithm the access to trainer.step_epochs(), which provides services such as snapshotting and sampler control. Returns: float: The aver...
train
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _train_once(self, itr, episodes): """Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. Returns: numpy.float64: Average return. """ undiscoun...
Perform one step of policy optimization given one batch of samples. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. Returns: numpy.float64: Average return.
_train_once
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _optimize_policy(self, itr, episodes, baselines, embed_eps, embed_ep_infos): """Optimize policy. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. baselines (np.ndarray): Baseline predictions. embe...
Optimize policy. Args: itr (int): Iteration number. episodes (EpisodeBatch): Batch of episodes. baselines (np.ndarray): Baseline predictions. embed_eps (np.ndarray): Embedding episodes. embed_ep_infos (dict): Embedding distribution information. ...
_optimize_policy
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _process_episodes(self, episodes): # pylint: disable=too-many-statements """Return processed sample data based on the collected paths. Args: episodes (EpisodeBatch): Batch of episodes. Returns: np.ndarray: Embedding episodes. dict: Embedding dist...
Return processed sample data based on the collected paths. Args: episodes (EpisodeBatch): Batch of episodes. Returns: np.ndarray: Embedding episodes. dict: Embedding distribution information. * mean (list[numpy.ndarray]): Means of the distribution. ...
_process_episodes
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _build_inputs(self): """Build input variables. Returns: namedtuple: Collection of variables to compute policy loss. namedtuple: Collection of variables to do policy optimization. namedtuple: Collection of variables to compute inference loss. namedtupl...
Build input variables. Returns: namedtuple: Collection of variables to compute policy loss. namedtuple: Collection of variables to do policy optimization. namedtuple: Collection of variables to compute inference loss. namedtuple: Collection of variables to do inf...
_build_inputs
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _build_policy_loss(self, i): """Build policy loss and other output tensors. Args: i (namedtuple): Collection of variables to compute policy loss. Returns: tf.Tensor: Policy loss. tf.Tensor: Mean policy KL divergence. """ # pylint: disabl...
Build policy loss and other output tensors. Args: i (namedtuple): Collection of variables to compute policy loss. Returns: tf.Tensor: Policy loss. tf.Tensor: Mean policy KL divergence.
_build_policy_loss
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _build_entropy_terms(self, i): """Build policy entropy tensor. Args: i (namedtuple): Collection of variables to compute policy loss. Returns: tf.Tensor: Policy entropy. """ pol_dist = self._policy_network.dist infer_dist = self._infer_networ...
Build policy entropy tensor. Args: i (namedtuple): Collection of variables to compute policy loss. Returns: tf.Tensor: Policy entropy.
_build_entropy_terms
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _build_encoder_kl(self): """Build graph for encoder KL divergence. Returns: tf.Tensor: Encoder KL divergence. """ dist = self._encoder_network.dist old_dist = self._old_encoder_network.dist with tf.name_scope('encoder_kl'): kl = old_dist.kl_...
Build graph for encoder KL divergence. Returns: tf.Tensor: Encoder KL divergence.
_build_encoder_kl
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _build_inference_loss(self, i): """Build loss function for the inference network. Args: i (namedtuple): Collection of variables to compute inference loss. Returns: tf.Tensor: Inference loss. """ dist = self._infer_network.dist old_dist = sel...
Build loss function for the inference network. Args: i (namedtuple): Collection of variables to compute inference loss. Returns: tf.Tensor: Inference loss.
_build_inference_loss
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _policy_opt_input_values(self, episodes, baselines, embed_eps): """Map episode samples to the policy optimizer inputs. Args: episodes (EpisodeBatch): Batch of episodes. baselines (np.ndarray): Baseline predictions. embed_eps (np.ndarray): Embedding episodes. ...
Map episode samples to the policy optimizer inputs. Args: episodes (EpisodeBatch): Batch of episodes. baselines (np.ndarray): Baseline predictions. embed_eps (np.ndarray): Embedding episodes. Returns: list(np.ndarray): Flatten policy optimization input v...
_policy_opt_input_values
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _inference_opt_input_values(self, episodes, embed_eps, embed_ep_infos): """Map episode samples to the inference optimizer inputs. Args: episodes (EpisodeBatch): Batch of episodes. embed_eps (np.ndarray): Embedding episodes. embed_ep_infos (dict): Embedding distri...
Map episode samples to the inference optimizer inputs. Args: episodes (EpisodeBatch): Batch of episodes. embed_eps (np.ndarray): Embedding episodes. embed_ep_infos (dict): Embedding distribution information. Returns: list(np.ndarray): Flatten inference o...
_inference_opt_input_values
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _evaluate(self, policy_opt_input_values, episodes, baselines, embed_ep_infos): """Evaluate rewards and everything else. Args: policy_opt_input_values (list[np.ndarray]): Flattened policy optimization input values. episodes (EpisodeBatch): Ba...
Evaluate rewards and everything else. Args: policy_opt_input_values (list[np.ndarray]): Flattened policy optimization input values. episodes (EpisodeBatch): Batch of episodes. baselines (np.ndarray): Baseline predictions. embed_ep_infos (dict): Em...
_evaluate
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _train_policy_and_encoder_networks(self, policy_opt_input_values): """Joint optimization of policy and encoder networks. Args: policy_opt_input_values (list(np.ndarray)): Flatten policy optimization input values. Returns: float: Policy loss after opt...
Joint optimization of policy and encoder networks. Args: policy_opt_input_values (list(np.ndarray)): Flatten policy optimization input values. Returns: float: Policy loss after optimization.
_train_policy_and_encoder_networks
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _train_inference_network(self, inference_opt_input_values): """Optimize inference network. Args: inference_opt_input_values (list(np.ndarray)): Flatten inference optimization input values. Returns: float: Inference loss after optmization. ""...
Optimize inference network. Args: inference_opt_input_values (list(np.ndarray)): Flatten inference optimization input values. Returns: float: Inference loss after optmization.
_train_inference_network
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def _get_latent_space(cls, latent_dim): """Get latent space given latent length. Args: latent_dim (int): Length of latent. Returns: akro.Space: Space of latent. """ latent_lb = np.zeros(latent_dim, ) latent_up = np.ones(latent_dim, ) ret...
Get latent space given latent length. Args: latent_dim (int): Length of latent. Returns: akro.Space: Space of latent.
_get_latent_space
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def get_encoder_spec(cls, task_space, latent_dim): """Get the embedding spec of the encoder. Args: task_space (akro.Space): Task spec. latent_dim (int): Latent dimension. Returns: garage.InOutSpec: Encoder spec. """ latent_space = cls._get_l...
Get the embedding spec of the encoder. Args: task_space (akro.Space): Task spec. latent_dim (int): Latent dimension. Returns: garage.InOutSpec: Encoder spec.
get_encoder_spec
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def get_infer_spec(cls, env_spec, latent_dim, inference_window_size): """Get the embedding spec of the inference. Every `inference_window_size` timesteps in the trajectory will be used as the inference network input. Args: env_spec (garage.envs.EnvSpec): Environment spec. ...
Get the embedding spec of the inference. Every `inference_window_size` timesteps in the trajectory will be used as the inference network input. Args: env_spec (garage.envs.EnvSpec): Environment spec. latent_dim (int): Latent dimension. inference_window_size ...
get_infer_spec
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def __getstate__(self): """Parameters to save in snapshot. Returns: dict: Parameters to save. """ data = self.__dict__.copy() del data['_name_scope'] del data['_inference_opt_inputs'] del data['_policy_opt_inputs'] del data['_f_inference_ce']...
Parameters to save in snapshot. Returns: dict: Parameters to save.
__getstate__
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def __setstate__(self, state): """Parameters to restore from snapshot. Args: state (dict): Parameters to restore from. """ self.__dict__ = state self._name_scope = tf.name_scope(self._name) self._init_opt()
Parameters to restore from snapshot. Args: state (dict): Parameters to restore from.
__setstate__
python
rlworkgroup/garage
src/garage/tf/algos/te_npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/te_npo.py
MIT
def optimize_policy(self, episodes): """Optimize policy. Args: episodes (EpisodeBatch): Batch of episodes. """ # Baseline predictions with all zeros for feeding inputs of Tensorflow baselines = np.zeros((len(episodes.lengths), max(episodes.lengths))) return...
Optimize policy. Args: episodes (EpisodeBatch): Batch of episodes.
optimize_policy
python
rlworkgroup/garage
src/garage/tf/algos/_rl2npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/_rl2npo.py
MIT
def _get_baseline_prediction(self, episodes): """Get baseline prediction. Args: episodes (EpisodeBatch): Batch of episodes. Returns: np.ndarray: Baseline prediction, with shape :math:`(N, max_episode_length * episode_per_task)`. """ obs ...
Get baseline prediction. Args: episodes (EpisodeBatch): Batch of episodes. Returns: np.ndarray: Baseline prediction, with shape :math:`(N, max_episode_length * episode_per_task)`.
_get_baseline_prediction
python
rlworkgroup/garage
src/garage/tf/algos/_rl2npo.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/algos/_rl2npo.py
MIT
def fit(self, paths): """Fit regressor based on paths. Args: paths (dict[numpy.ndarray]): Sample paths. """ xs = np.concatenate([p['observations'] for p in paths]) if not isinstance(xs, np.ndarray) or len(xs.shape) > 2: xs = self._env_spec.observation_sp...
Fit regressor based on paths. Args: paths (dict[numpy.ndarray]): Sample paths.
fit
python
rlworkgroup/garage
src/garage/tf/baselines/continuous_mlp_baseline.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/baselines/continuous_mlp_baseline.py
MIT
def predict(self, paths): """Predict value based on paths. Args: paths (dict[numpy.ndarray]): Sample paths. Returns: numpy.ndarray: Predicted value. """ obs = paths['observations'] if not isinstance(obs, np.ndarray) or len(obs.shape) > 2: ...
Predict value based on paths. Args: paths (dict[numpy.ndarray]): Sample paths. Returns: numpy.ndarray: Predicted value.
predict
python
rlworkgroup/garage
src/garage/tf/baselines/continuous_mlp_baseline.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/baselines/continuous_mlp_baseline.py
MIT
def __getstate__(self): """Object.__getstate__. Returns: dict: the state to be pickled for the instance. """ new_dict = super().__getstate__() del new_dict['_f_predict'] del new_dict['_x_mean'] del new_dict['_x_std'] del new_dict['_y_hat'] ...
Object.__getstate__. Returns: dict: the state to be pickled for the instance.
__getstate__
python
rlworkgroup/garage
src/garage/tf/baselines/continuous_mlp_baseline.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/baselines/continuous_mlp_baseline.py
MIT
def fit(self, paths): """Fit regressor based on paths. Args: paths (dict[numpy.ndarray]): Sample paths. """ xs = np.concatenate([p['observations'] for p in paths]) if isinstance(self._env_spec.observation_space, akro.Image) and \ len(xs[0].shape) < \...
Fit regressor based on paths. Args: paths (dict[numpy.ndarray]): Sample paths.
fit
python
rlworkgroup/garage
src/garage/tf/baselines/gaussian_cnn_baseline.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/baselines/gaussian_cnn_baseline.py
MIT
def predict(self, paths): """Predict ys based on input xs. Args: paths (dict[numpy.ndarray]): Sample paths. Return: numpy.ndarray: The predicted ys. """ xs = paths['observations'] if isinstance(self._env_spec.observation_space, akro.Image) and \...
Predict ys based on input xs. Args: paths (dict[numpy.ndarray]): Sample paths. Return: numpy.ndarray: The predicted ys.
predict
python
rlworkgroup/garage
src/garage/tf/baselines/gaussian_cnn_baseline.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/baselines/gaussian_cnn_baseline.py
MIT
def __getstate__(self): """Object.__getstate__. Returns: dict: The state to be pickled for the instance. """ new_dict = super().__getstate__() del new_dict['_f_predict'] del new_dict['_old_network'] del new_dict['_x_mean'] del new_dict['_x_st...
Object.__getstate__. Returns: dict: The state to be pickled for the instance.
__getstate__
python
rlworkgroup/garage
src/garage/tf/baselines/gaussian_cnn_baseline.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/baselines/gaussian_cnn_baseline.py
MIT
def network_output_spec(self): """Network output spec. Return: list[str]: List of key(str) for the network outputs. """ return [ 'sample', 'std_param', 'normalized_dist', 'normalized_mean', 'normalized_log_std', 'dist', 'mean', 'log_std', 'x_mean', '...
Network output spec. Return: list[str]: List of key(str) for the network outputs.
network_output_spec
python
rlworkgroup/garage
src/garage/tf/baselines/gaussian_cnn_baseline_model.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/baselines/gaussian_cnn_baseline_model.py
MIT
def _build(self, state_input, name=None): """Build model given input placeholder(s). Args: state_input (tf.Tensor): Place holder for state input. name (str): Inner model name, also the variable scope of the inner model, if exist. One example is ga...
Build model given input placeholder(s). Args: state_input (tf.Tensor): Place holder for state input. name (str): Inner model name, also the variable scope of the inner model, if exist. One example is garage.tf.models.Sequential. Return: ...
_build
python
rlworkgroup/garage
src/garage/tf/baselines/gaussian_cnn_baseline_model.py
https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/baselines/gaussian_cnn_baseline_model.py
MIT