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 _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_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 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 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 |
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_mlp_baseline_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/baselines/gaussian_mlp_baseline_model.py | MIT |
def get_latent(self, input_value):
"""Get a sample of embedding for the given input.
Args:
input_value (numpy.ndarray): Tensor to encode.
Returns:
numpy.ndarray: An embedding sampled from embedding distribution.
dict: Embedding distribution information.
... | Get a sample of embedding for the given input.
Args:
input_value (numpy.ndarray): Tensor to encode.
Returns:
numpy.ndarray: An embedding sampled from embedding distribution.
dict: Embedding distribution information.
Note:
It returns an embedding... | get_latent | python | rlworkgroup/garage | src/garage/tf/embeddings/encoder.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/embeddings/encoder.py | MIT |
def get_latents(self, input_values):
"""Get samples of embedding for the given inputs.
Args:
input_values (numpy.ndarray): Tensors to encode.
Returns:
numpy.ndarray: Embeddings sampled from embedding distribution.
dict: Embedding distribution information.
... | Get samples of embedding for the given inputs.
Args:
input_values (numpy.ndarray): Tensors to encode.
Returns:
numpy.ndarray: Embeddings sampled from embedding distribution.
dict: Embedding distribution information.
Note:
It returns an embedding... | get_latents | python | rlworkgroup/garage | src/garage/tf/embeddings/encoder.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/embeddings/encoder.py | MIT |
def build(self, embedding_input, name=None):
"""Build encoder.
After buil, self.distribution is a Gaussian distribution conitioned
on embedding_input.
Args:
embedding_input (tf.Tensor) : Embedding input.
name (str): Name of the model, which is also the name scope.
... | Build encoder.
After buil, self.distribution is a Gaussian distribution conitioned
on embedding_input.
Args:
embedding_input (tf.Tensor) : Embedding input.
name (str): Name of the model, which is also the name scope.
| build | python | rlworkgroup/garage | src/garage/tf/embeddings/encoder.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/embeddings/encoder.py | MIT |
def build(self, embedding_input, name=None):
"""Build encoder.
Args:
embedding_input (tf.Tensor) : Embedding input.
name (str): Name of the model, which is also the name scope.
Returns:
tfp.distributions.MultivariateNormalDiag: Distribution.
tf.t... | Build encoder.
Args:
embedding_input (tf.Tensor) : Embedding input.
name (str): Name of the model, which is also the name scope.
Returns:
tfp.distributions.MultivariateNormalDiag: Distribution.
tf.tensor: Mean.
tf.Tensor: Log of standard devi... | build | python | rlworkgroup/garage | src/garage/tf/embeddings/gaussian_mlp_encoder.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/embeddings/gaussian_mlp_encoder.py | MIT |
def _build(self, state_input, name=None):
"""Build model.
Args:
state_input (tf.Tensor): Observation inputs.
name (str): Inner model name, also the variable scope of the
inner model, if exist. One example is
garage.tf.models.Sequential.
R... | Build model.
Args:
state_input (tf.Tensor): Observation inputs.
name (str): Inner model name, also the variable scope of the
inner model, if exist. One example is
garage.tf.models.Sequential.
Returns:
tfp.distributions.OneHotCategoric... | _build | python | rlworkgroup/garage | src/garage/tf/models/categorical_cnn_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/categorical_cnn_model.py | MIT |
def _build(self, state_input, step_input, step_hidden, name=None):
"""Build model.
Args:
state_input (tf.Tensor): Full observation input, with shape
:math:`(N, T, S^*)`.
step_input (tf.Tensor): Step observation input, with shape
:math:`(N, S^*)`.
... | Build model.
Args:
state_input (tf.Tensor): Full observation input, with shape
:math:`(N, T, S^*)`.
step_input (tf.Tensor): Step observation input, with shape
:math:`(N, S^*)`.
step_hidden (tf.Tensor): Hidden state for step, with shape
... | _build | python | rlworkgroup/garage | src/garage/tf/models/categorical_gru_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/categorical_gru_model.py | MIT |
def network_output_spec(self):
"""Network output spec.
Returns:
list[str]: Name of the model outputs, in order.
"""
return [
'dist', 'step_output', 'step_hidden', 'step_cell', 'init_hidden',
'init_cell'
] | Network output spec.
Returns:
list[str]: Name of the model outputs, in order.
| network_output_spec | python | rlworkgroup/garage | src/garage/tf/models/categorical_lstm_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/categorical_lstm_model.py | MIT |
def _build(self,
state_input,
step_input,
step_hidden,
step_cell,
name=None):
"""Build model.
Args:
state_input (tf.Tensor): Entire time-series observation input,
with shape :math:`(N, T, S^*)`.
... | Build model.
Args:
state_input (tf.Tensor): Entire time-series observation input,
with shape :math:`(N, T, S^*)`.
step_input (tf.Tensor): Single timestep observation input,
with shape :math:`(N, S^*)`.
step_hidden (tf.Tensor): Hidden state for... | _build | python | rlworkgroup/garage | src/garage/tf/models/categorical_lstm_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/categorical_lstm_model.py | MIT |
def cnn(input_var,
input_dim,
filters,
strides,
name,
padding,
hidden_nonlinearity=tf.nn.relu,
hidden_w_init=tf.initializers.glorot_uniform(
seed=deterministic.get_tf_seed_stream()),
hidden_b_init=tf.zeros_initializer()):
"""Convolutional n... | Convolutional neural network (CNN).
Note:
Based on 'NHWC' data format: [batch, height, width, channel].
Args:
input_var (tf.Tensor): Input tf.Tensor to the CNN.
input_dim (Tuple[int, int, int]): Dimensions of unflattened input,
which means [in_height, in_width, in_channels]... | cnn | python | rlworkgroup/garage | src/garage/tf/models/cnn.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/cnn.py | MIT |
def cnn_with_max_pooling(input_var,
input_dim,
filters,
strides,
name,
pool_shapes,
pool_strides,
padding,
hidden_nonlin... | Convolutional neural network (CNN) with max-pooling.
Note:
Based on 'NHWC' data format: [batch, height, width, channel].
Args:
input_var (tf.Tensor): Input tf.Tensor to the CNN.
input_dim (Tuple[int, int, int]): Dimensions of unflattened input,
which means [in_height, in_wi... | cnn_with_max_pooling | python | rlworkgroup/garage | src/garage/tf/models/cnn.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/cnn.py | MIT |
def _conv(input_var, name, filter_size, num_filter, strides, hidden_w_init,
hidden_b_init, padding):
"""Helper function for performing convolution.
Args:
input_var (tf.Tensor): Input tf.Tensor to the CNN.
name (str): Variable scope of the convolution Op.
filter_size (tuple[int... | Helper function for performing convolution.
Args:
input_var (tf.Tensor): Input tf.Tensor to the CNN.
name (str): Variable scope of the convolution Op.
filter_size (tuple[int]): Dimension of the filter. For example,
(3, 5) means the dimension of the filter is (3 x 5).
num... | _conv | python | rlworkgroup/garage | src/garage/tf/models/cnn.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/cnn.py | MIT |
def _build(self, state, action, name=None):
"""Build the model and return the outputs.
This builds the model such that the output of the CNN is fed
to the MLP. The CNN receives the state as the input. The MLP
receives two inputs, the output of the CNN and the action
tensor.
... | Build the model and return the outputs.
This builds the model such that the output of the CNN is fed
to the MLP. The CNN receives the state as the input. The MLP
receives two inputs, the output of the CNN and the action
tensor.
Args:
state (tf.Tensor): State placeho... | _build | python | rlworkgroup/garage | src/garage/tf/models/cnn_mlp_merge_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/cnn_mlp_merge_model.py | MIT |
def _build(self, state_input, name=None):
"""Build model given input placeholder(s).
Args:
state_input (tf.Tensor): Tensor input for state.
name (str): Inner model name, also the variable scope of the
inner model, if exist. One example is
garage.t... | Build model given input placeholder(s).
Args:
state_input (tf.Tensor): Tensor input for state.
name (str): Inner model name, also the variable scope of the
inner model, if exist. One example is
garage.tf.models.Sequential.
Return:
tf.... | _build | python | rlworkgroup/garage | src/garage/tf/models/cnn_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/cnn_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/models/gaussian_cnn_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/gaussian_cnn_model.py | MIT |
def _build(self, state_input, step_input, step_hidden, name=None):
"""Build model.
Args:
state_input (tf.Tensor): Entire time-series observation input,
with shape :math:`(N, T, S^*)`.
step_input (tf.Tensor): Single timestep observation input,
with... | Build model.
Args:
state_input (tf.Tensor): Entire time-series observation input,
with shape :math:`(N, T, S^*)`.
step_input (tf.Tensor): Single timestep observation input,
with shape :math:`(N, S^*)`.
step_hidden (tf.Tensor): Hidden state for... | _build | python | rlworkgroup/garage | src/garage/tf/models/gaussian_gru_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/gaussian_gru_model.py | MIT |
def network_input_spec(self):
"""Network input spec.
Returns:
list[str]: Name of the model inputs, in order.
"""
return [
'full_input', 'step_input', 'step_hidden_input', 'step_cell_input'
] | Network input spec.
Returns:
list[str]: Name of the model inputs, in order.
| network_input_spec | python | rlworkgroup/garage | src/garage/tf/models/gaussian_lstm_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/gaussian_lstm_model.py | MIT |
def _build(self,
state_input,
step_input,
step_hidden,
step_cell,
name=None):
"""Build model.
Args:
state_input (tf.Tensor): Entire time-series observation input,
with shape :math:`(N, T, S^*)`.
... | Build model.
Args:
state_input (tf.Tensor): Entire time-series observation input,
with shape :math:`(N, T, S^*)`.
step_input (tf.Tensor): Single timestep observation input,
with shape :math:`(N, S^*)`.
step_hidden (tf.Tensor): Hidden state for... | _build | python | rlworkgroup/garage | src/garage/tf/models/gaussian_lstm_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/gaussian_lstm_model.py | MIT |
def _build(self, state_input, name=None):
"""Build model.
Args:
state_input (tf.Tensor): Entire time-series observation input.
name (str): Inner model name, also the variable scope of the
inner model, if exist. One example is
garage.tf.models.Sequ... | Build model.
Args:
state_input (tf.Tensor): Entire time-series observation input.
name (str): Inner model name, also the variable scope of the
inner model, if exist. One example is
garage.tf.models.Sequential.
Returns:
tfp.distributio... | _build | python | rlworkgroup/garage | src/garage/tf/models/gaussian_mlp_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/gaussian_mlp_model.py | MIT |
def gru(name,
gru_cell,
all_input_var,
step_input_var,
step_hidden_var,
output_nonlinearity_layer,
hidden_state_init=tf.zeros_initializer(),
hidden_state_init_trainable=False):
r"""Gated Recurrent Unit (GRU).
Args:
name (str): Name of the variable... | Gated Recurrent Unit (GRU).
Args:
name (str): Name of the variable scope.
gru_cell (tf.keras.layers.Layer): GRU cell used to generate
outputs.
all_input_var (tf.Tensor): Place holder for entire time-series inputs,
with shape :math:`(N, T, S^*)`.
step_input_va... | gru | python | rlworkgroup/garage | src/garage/tf/models/gru.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/gru.py | MIT |
def _build(self,
all_input_var,
step_input_var,
step_hidden_var,
name=None):
"""Build model given input placeholder(s).
Args:
all_input_var (tf.Tensor): Place holder for entire time-series
inputs.
step_i... | Build model given input placeholder(s).
Args:
all_input_var (tf.Tensor): Place holder for entire time-series
inputs.
step_input_var (tf.Tensor): Place holder for step inputs.
step_hidden_var (tf.Tensor): Place holder for step hidden state.
name (s... | _build | python | rlworkgroup/garage | src/garage/tf/models/gru_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/gru_model.py | MIT |
def lstm(name,
lstm_cell,
all_input_var,
step_input_var,
step_hidden_var,
step_cell_var,
output_nonlinearity_layer,
hidden_state_init=tf.zeros_initializer(),
hidden_state_init_trainable=False,
cell_state_init=tf.zeros_initializer(),
... | Long Short-Term Memory (LSTM).
Args:
name (str): Name of the variable scope.
lstm_cell (tf.keras.layers.Layer): LSTM cell used to generate
outputs.
all_input_var (tf.Tensor): Place holder for entire time-seried inputs,
with shape :math:`(N, T, S^*)`.
step_inp... | lstm | python | rlworkgroup/garage | src/garage/tf/models/lstm.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/lstm.py | MIT |
def network_input_spec(self):
"""Network input spec.
Return:
list[str]: List of key(str) for the network outputs.
"""
return [
'full_input', 'step_input', 'step_hidden_input', 'step_cell_input'
] | Network input spec.
Return:
list[str]: List of key(str) for the network outputs.
| network_input_spec | python | rlworkgroup/garage | src/garage/tf/models/lstm_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/lstm_model.py | MIT |
def _build(self,
all_input_var,
step_input_var,
step_hidden_var,
step_cell_var,
name=None):
"""Build model given input placeholder(s).
Args:
all_input_var (tf.Tensor): Place holder for entire time-series
... | Build model given input placeholder(s).
Args:
all_input_var (tf.Tensor): Place holder for entire time-series
inputs.
step_input_var (tf.Tensor): Place holder for step inputs.
step_hidden_var (tf.Tensor): Place holder for step hidden state.
step_ce... | _build | python | rlworkgroup/garage | src/garage/tf/models/lstm_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/lstm_model.py | MIT |
def mlp(input_var,
output_dim,
hidden_sizes,
name,
input_var2=None,
concat_layer=-2,
hidden_nonlinearity=tf.nn.relu,
hidden_w_init=tf.initializers.glorot_uniform(
seed=deterministic.get_tf_seed_stream()),
hidden_b_init=tf.zeros_initializer(),
... | Multi-layer perceptron (MLP).
It maps real-valued inputs to real-valued outputs.
Args:
input_var (tf.Tensor): Input tf.Tensor to the MLP.
output_dim (int): Dimension of the network output.
hidden_sizes (list[int]): Output dimension of dense layer(s).
For example, (32, 32) m... | mlp | python | rlworkgroup/garage | src/garage/tf/models/mlp.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/mlp.py | MIT |
def _build(self, state_input, action_input, name=None):
"""Build model given input placeholder(s).
Args:
state_input (tf.Tensor): Tensor input for state.
action_input (tf.Tensor): Tensor input for action.
name (str): Inner model name, also the variable scope of the
... | Build model given input placeholder(s).
Args:
state_input (tf.Tensor): Tensor input for state.
action_input (tf.Tensor): Tensor input for action.
name (str): Inner model name, also the variable scope of the
inner model, if exist. One example is
... | _build | python | rlworkgroup/garage | src/garage/tf/models/mlp_merge_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/mlp_merge_model.py | MIT |
def build(self, *inputs, name=None):
"""Output of model with the given input placeholder(s).
This function is implemented by subclasses to create their computation
graphs, which will be managed by Model. Generally, subclasses should
implement `build()` directly.
Args:
... | Output of model with the given input placeholder(s).
This function is implemented by subclasses to create their computation
graphs, which will be managed by Model. Generally, subclasses should
implement `build()` directly.
Args:
inputs (object): Input(s) for the model.
... | build | python | rlworkgroup/garage | src/garage/tf/models/model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/model.py | MIT |
def parameters(self):
"""Parameters of the Model.
The output of a model is determined by its parameter. It could be
the weights of a neural network model or parameters of a loss
function model.
Returns:
list[tf.Tensor]: Parameters.
""" | Parameters of the Model.
The output of a model is determined by its parameter. It could be
the weights of a neural network model or parameters of a loss
function model.
Returns:
list[tf.Tensor]: Parameters.
| parameters | python | rlworkgroup/garage | src/garage/tf/models/model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/model.py | MIT |
def parameters(self, parameters):
"""Set parameters of the Model.
Args:
parameters (list[tf.Tensor]): Parameters.
""" | Set parameters of the Model.
Args:
parameters (list[tf.Tensor]): Parameters.
| parameters | python | rlworkgroup/garage | src/garage/tf/models/model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/model.py | MIT |
def build(self, *inputs, name=None):
"""Build a Network with the given input(s).
***
Do not call tf.global_variable_initializers() after building a model
as it will reassign random weights to the model.
The parameters inside a model will be initialized when calling build().
... | Build a Network with the given input(s).
***
Do not call tf.global_variable_initializers() after building a model
as it will reassign random weights to the model.
The parameters inside a model will be initialized when calling build().
***
It uses the same, fixed variabl... | build | python | rlworkgroup/garage | src/garage/tf/models/model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/model.py | MIT |
def _build(self, *inputs, name=None):
"""Build this model given input placeholder(s).
User should implement _build() inside their subclassed model,
and construct the computation graphs in this function.
Args:
inputs: Tensor input(s), recommended to be position arguments, e.... | Build this model given input placeholder(s).
User should implement _build() inside their subclassed model,
and construct the computation graphs in this function.
Args:
inputs: Tensor input(s), recommended to be position arguments, e.g.
def _build(self, state_input, ... | _build | python | rlworkgroup/garage | src/garage/tf/models/model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/model.py | MIT |
def parameters(self):
"""Parameters of the model.
Returns:
np.ndarray: Parameters
"""
_variables = self._get_variables()
if _variables:
return tf.compat.v1.get_default_session().run(_variables)
else:
return _variables | Parameters of the model.
Returns:
np.ndarray: Parameters
| parameters | python | rlworkgroup/garage | src/garage/tf/models/model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/model.py | MIT |
def parameters(self, parameters):
"""Set model parameters.
Args:
parameters (tf.Tensor): Parameters.
"""
variables = self._get_variables()
for name, var in variables.items():
found = False
# param name without model name
param_nam... | Set model parameters.
Args:
parameters (tf.Tensor): Parameters.
| parameters | python | rlworkgroup/garage | src/garage/tf/models/model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/model.py | MIT |
def _get_variables(self):
"""Get variables of this model.
Returns:
dict[str: tf.Tensor]: Variables of this model.
"""
if self._variable_scope:
return {v.name: v for v in self._variable_scope.global_variables()}
else:
return dict() | Get variables of this model.
Returns:
dict[str: tf.Tensor]: Variables of this model.
| _get_variables | python | rlworkgroup/garage | src/garage/tf/models/model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/model.py | MIT |
def __setstate__(self, state):
"""Object.__setstate__.
Args:
state (dict): unpickled state.
"""
super().__setstate__(state)
self._networks = {} | Object.__setstate__.
Args:
state (dict): unpickled state.
| __setstate__ | python | rlworkgroup/garage | src/garage/tf/models/model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/model.py | MIT |
def reset(self, do_resets=None):
"""Reset the module.
This is effective only to recurrent modules. do_resets is effective
only to vectoried modules.
For a vectorized modules, do_resets is an array of boolean indicating
which internal states to be reset. The length of do_resets ... | Reset the module.
This is effective only to recurrent modules. do_resets is effective
only to vectoried modules.
For a vectorized modules, do_resets is an array of boolean indicating
which internal states to be reset. The length of do_resets should be
equal to the length of inp... | reset | python | rlworkgroup/garage | src/garage/tf/models/module.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/module.py | MIT |
def get_regularizable_vars(self):
"""Get all network weight variables in the current scope.
Returns:
List[tf.Variable]: A list of network weight variables in the
current variable scope.
"""
trainable = self._variable_scope.global_variables()
return [... | Get all network weight variables in the current scope.
Returns:
List[tf.Variable]: A list of network weight variables in the
current variable scope.
| get_regularizable_vars | python | rlworkgroup/garage | src/garage/tf/models/module.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/module.py | MIT |
def get_params(self):
"""Get the trainable variables.
Returns:
List[tf.Variable]: A list of trainable variables in the current
variable scope.
"""
if self._cached_params is None:
self._cached_params = self.get_trainable_vars()
return self... | Get the trainable variables.
Returns:
List[tf.Variable]: A list of trainable variables in the current
variable scope.
| get_params | python | rlworkgroup/garage | src/garage/tf/models/module.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/module.py | MIT |
def get_param_shapes(self):
"""Get parameter shapes.
Returns:
List[tuple]: A list of variable shapes.
"""
if self._cached_param_shapes is None:
params = self.get_params()
param_values = tf.compat.v1.get_default_session().run(params)
self.... | Get parameter shapes.
Returns:
List[tuple]: A list of variable shapes.
| get_param_shapes | python | rlworkgroup/garage | src/garage/tf/models/module.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/module.py | MIT |
def get_param_values(self):
"""Get param values.
Returns:
np.ndarray: Values of the parameters evaluated in
the current session
"""
params = self.get_params()
param_values = tf.compat.v1.get_default_session().run(params)
return flatten_tensor... | Get param values.
Returns:
np.ndarray: Values of the parameters evaluated in
the current session
| get_param_values | python | rlworkgroup/garage | src/garage/tf/models/module.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/module.py | MIT |
def set_param_values(self, param_values):
"""Set param values.
Args:
param_values (np.ndarray): A numpy array of parameter values.
"""
param_values = unflatten_tensors(param_values, self.get_param_shapes())
for param, value in zip(self.get_params(), param_values):
... | Set param values.
Args:
param_values (np.ndarray): A numpy array of parameter values.
| set_param_values | python | rlworkgroup/garage | src/garage/tf/models/module.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/module.py | MIT |
def parameter(input_var,
length,
initializer=tf.zeros_initializer(),
dtype=tf.float32,
trainable=True,
name='parameter'):
"""Parameter layer.
Used as layer that could be broadcast to a certain shape to
match with input variable during tr... | Parameter layer.
Used as layer that could be broadcast to a certain shape to
match with input variable during training.
For recurrent usage, use garage.tf.models.recurrent_parameter().
Example: A trainable parameter variable with shape (2,), it needs to be
broadcasted to (32, 2) when applied to a... | parameter | python | rlworkgroup/garage | src/garage/tf/models/parameter.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/parameter.py | MIT |
def recurrent_parameter(input_var,
step_input_var,
length,
initializer=tf.zeros_initializer(),
dtype=tf.float32,
trainable=True,
name='recurrent_parameter'):
"""Parameter l... | Parameter layer for recurrent networks.
Used as layer that could be broadcast to a certain shape to
match with input variable during training.
Example: A trainable parameter variable with shape (2,), it needs to be
broadcasted to (32, 4, 2) when applied to a batch with size 32 and
time-length 4.
... | recurrent_parameter | python | rlworkgroup/garage | src/garage/tf/models/parameter.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/parameter.py | MIT |
def _build(self, input_var, name=None):
"""Build model given input placeholder(s).
Args:
input_var (tf.Tensor): Tensor input.
name (str): Inner model name, also the variable scope of the
inner model.
Return:
tf.Tensor: Tensor output of the mo... | Build model given input placeholder(s).
Args:
input_var (tf.Tensor): Tensor input.
name (str): Inner model name, also the variable scope of the
inner model.
Return:
tf.Tensor: Tensor output of the model.
| _build | python | rlworkgroup/garage | src/garage/tf/models/sequential.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/sequential.py | MIT |
def __setstate__(self, state):
"""Object.__setstate__.
Args:
state (dict): Unpickled state.
"""
super().__setstate__(state)
self._first_network = None
self._last_network = None | Object.__setstate__.
Args:
state (dict): Unpickled state.
| __setstate__ | python | rlworkgroup/garage | src/garage/tf/models/sequential.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/sequential.py | MIT |
def update_hvp(self, f, target, inputs, reg_coeff, name=None):
"""Build the symbolic graph to compute the Hessian-vector product.
Args:
f (tf.Tensor): The function whose Hessian needs to be computed.
target (garage.tf.policies.Policy): A parameterized object to
o... | Build the symbolic graph to compute the Hessian-vector product.
Args:
f (tf.Tensor): The function whose Hessian needs to be computed.
target (garage.tf.policies.Policy): A parameterized object to
optimize over.
inputs (tuple[tf.Tensor]): The inputs for functi... | update_hvp | python | rlworkgroup/garage | src/garage/tf/optimizers/conjugate_gradient_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/conjugate_gradient_optimizer.py | MIT |
def build_eval(self, inputs):
"""Build the evaluation function. # noqa: D202, E501 # https://github.com/PyCQA/pydocstyle/pull/395.
Args:
inputs (tuple[numpy.ndarray]): Function f will be evaluated on
these inputs.
Returns:
function: It can be called to ... | Build the evaluation function. # noqa: D202, E501 # https://github.com/PyCQA/pydocstyle/pull/395.
Args:
inputs (tuple[numpy.ndarray]): Function f will be evaluated on
these inputs.
Returns:
function: It can be called to get the final result.
| build_eval | python | rlworkgroup/garage | src/garage/tf/optimizers/conjugate_gradient_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/conjugate_gradient_optimizer.py | MIT |
def _eval(v):
"""The evaluation function.
Args:
v (numpy.ndarray): The vector to be multiplied with Hessian.
Returns:
numpy.ndarray: The product of Hessian of function f and v.
"""
xs = tuple(self._target.flat_to_params(v))
... | The evaluation function.
Args:
v (numpy.ndarray): The vector to be multiplied with Hessian.
Returns:
numpy.ndarray: The product of Hessian of function f and v.
| _eval | python | rlworkgroup/garage | src/garage/tf/optimizers/conjugate_gradient_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/conjugate_gradient_optimizer.py | MIT |
def hx_plain():
"""Computes product of Hessian(f) and vector v.
Returns:
tf.Tensor: Symbolic result.
"""
with tf.name_scope('hx_plain'):
with tf.name_scope('hx_function'):
hx_f = tf.reduce_s... | Computes product of Hessian(f) and vector v.
Returns:
tf.Tensor: Symbolic result.
| hx_plain | python | rlworkgroup/garage | src/garage/tf/optimizers/conjugate_gradient_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/conjugate_gradient_optimizer.py | MIT |
def f_hx_plain(*args):
"""Computes product of Hessian(f) and vector v.
Args:
args (tuple[numpy.ndarray]): Contains inputs of function f
, and vector v.
Returns:
tf.Tensor: Symbolic result.
... | Computes product of Hessian(f) and vector v.
Args:
args (tuple[numpy.ndarray]): Contains inputs of function f
, and vector v.
Returns:
tf.Tensor: Symbolic result.
| f_hx_plain | python | rlworkgroup/garage | src/garage/tf/optimizers/conjugate_gradient_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/conjugate_gradient_optimizer.py | MIT |
def update_opt(
self,
loss,
target,
leq_constraint,
inputs,
extra_inputs=None,
name='ConjugateGradientOptimizer',
constraint_name='constraint',
):
"""Update the optimizer.
Build the functions for computing loss, gradient, and
t... | Update the optimizer.
Build the functions for computing loss, gradient, and
the constraint value.
Args:
loss (tf.Tensor): Symbolic expression for the loss function.
target (garage.tf.policies.Policy): A parameterized object to
optimize over.
... | update_opt | python | rlworkgroup/garage | src/garage/tf/optimizers/conjugate_gradient_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/conjugate_gradient_optimizer.py | MIT |
def loss(self, inputs, extra_inputs=None):
"""Compute the loss value.
Args:
inputs (list[numpy.ndarray]): A list inputs, which could be
subsampled if needed. It is assumed that the first dimension
of these inputs should correspond to the number of data points... | Compute the loss value.
Args:
inputs (list[numpy.ndarray]): A list inputs, which could be
subsampled if needed. It is assumed that the first dimension
of these inputs should correspond to the number of data points
extra_inputs (list[numpy.ndarray]): A lis... | loss | python | rlworkgroup/garage | src/garage/tf/optimizers/conjugate_gradient_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/conjugate_gradient_optimizer.py | MIT |
def constraint_val(self, inputs, extra_inputs=None):
"""Constraint value.
Args:
inputs (list[numpy.ndarray]): A list inputs, which could be
subsampled if needed. It is assumed that the first dimension
of these inputs should correspond to the number of data po... | Constraint value.
Args:
inputs (list[numpy.ndarray]): A list inputs, which could be
subsampled if needed. It is assumed that the first dimension
of these inputs should correspond to the number of data points
extra_inputs (list[numpy.ndarray]): A list of e... | constraint_val | python | rlworkgroup/garage | src/garage/tf/optimizers/conjugate_gradient_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/conjugate_gradient_optimizer.py | MIT |
def optimize(self,
inputs,
extra_inputs=None,
subsample_grouped_inputs=None,
name='optimize'):
"""Optimize the function.
Args:
inputs (list[numpy.ndarray]): A list inputs, which could be
subsampled if needed... | Optimize the function.
Args:
inputs (list[numpy.ndarray]): A list inputs, which could be
subsampled if needed. It is assumed that the first dimension
of these inputs should correspond to the number of data points
extra_inputs (list[numpy.ndarray]): A list... | optimize | python | rlworkgroup/garage | src/garage/tf/optimizers/conjugate_gradient_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/conjugate_gradient_optimizer.py | MIT |
def _cg(f_Ax, b, cg_iters=10, residual_tol=1e-10):
"""Use Conjugate Gradient iteration to solve Ax = b. Demmel p 312.
Args:
f_Ax (function): A function to compute Hessian vector product.
b (numpy.ndarray): Right hand side of the equation to solve.
cg_iters (int): Number of iterations to... | Use Conjugate Gradient iteration to solve Ax = b. Demmel p 312.
Args:
f_Ax (function): A function to compute Hessian vector product.
b (numpy.ndarray): Right hand side of the equation to solve.
cg_iters (int): Number of iterations to run conjugate gradient
algorithm.
res... | _cg | python | rlworkgroup/garage | src/garage/tf/optimizers/conjugate_gradient_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/conjugate_gradient_optimizer.py | MIT |
def _sliced_fn(f, n_slices):
"""Divide function f's inputs into several slices.
Evaluate f on those slices, and then average the result. It is useful when
memory is not enough to process all data at once.
Assume:
1. each of f's inputs is iterable and composed of multiple "samples"
2. outputs ca... | Divide function f's inputs into several slices.
Evaluate f on those slices, and then average the result. It is useful when
memory is not enough to process all data at once.
Assume:
1. each of f's inputs is iterable and composed of multiple "samples"
2. outputs can be averaged over "samples"
Ar... | _sliced_fn | python | rlworkgroup/garage | src/garage/tf/optimizers/conjugate_gradient_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/conjugate_gradient_optimizer.py | MIT |
def update_opt(self, loss, target, inputs, extra_inputs=None, **kwargs):
"""Construct operation graph for the optimizer.
Args:
loss (tf.Tensor): Loss objective to minimize.
target (object): Target object to optimize. The object should
implemenet `get_params()` an... | Construct operation graph for the optimizer.
Args:
loss (tf.Tensor): Loss objective to minimize.
target (object): Target object to optimize. The object should
implemenet `get_params()` and `get_param_values`.
inputs (list[tf.Tensor]): List of input placeholde... | update_opt | python | rlworkgroup/garage | src/garage/tf/optimizers/first_order_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/first_order_optimizer.py | MIT |
def loss(self, inputs, extra_inputs=None):
"""The loss.
Args:
inputs (list[numpy.ndarray]): List of input values.
extra_inputs (list[numpy.ndarray]): List of extra input values.
Returns:
float: Loss.
Raises:
Exception: If loss function i... | The loss.
Args:
inputs (list[numpy.ndarray]): List of input values.
extra_inputs (list[numpy.ndarray]): List of extra input values.
Returns:
float: Loss.
Raises:
Exception: If loss function is None, i.e. not defined.
| loss | python | rlworkgroup/garage | src/garage/tf/optimizers/first_order_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/first_order_optimizer.py | MIT |
def optimize(self, inputs, extra_inputs=None, callback=None):
"""Perform optimization.
Args:
inputs (list[numpy.ndarray]): List of input values.
extra_inputs (list[numpy.ndarray]): List of extra input values.
callback (callable): Function to call during each epoch. D... | Perform optimization.
Args:
inputs (list[numpy.ndarray]): List of input values.
extra_inputs (list[numpy.ndarray]): List of extra input values.
callback (callable): Function to call during each epoch. Default
is None.
Raises:
NotImplement... | optimize | python | rlworkgroup/garage | src/garage/tf/optimizers/first_order_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/first_order_optimizer.py | MIT |
def update_opt(self,
loss,
target,
inputs,
extra_inputs=None,
name='LBFGSOptimizer',
**kwargs):
"""Construct operation graph for the optimizer.
Args:
loss (tf.Tensor): Loss obje... | Construct operation graph for the optimizer.
Args:
loss (tf.Tensor): Loss objective to minimize.
target (object): Target object to optimize. The object should
implemenet `get_params()` and `get_param_values`.
inputs (list[tf.Tensor]): List of input placeholde... | update_opt | python | rlworkgroup/garage | src/garage/tf/optimizers/lbfgs_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/lbfgs_optimizer.py | MIT |
def get_opt_output():
"""Helper function to construct graph.
Returns:
list[tf.Tensor]: Loss and gradient tensor.
"""
with tf.name_scope('get_opt_output'):
flat_grad = flatten_tensor_variables(
... | Helper function to construct graph.
Returns:
list[tf.Tensor]: Loss and gradient tensor.
| get_opt_output | python | rlworkgroup/garage | src/garage/tf/optimizers/lbfgs_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/lbfgs_optimizer.py | MIT |
def optimize(self, inputs, extra_inputs=None, name='optimize'):
"""Perform optimization.
Args:
inputs (list[numpy.ndarray]): List of input values.
extra_inputs (list[numpy.ndarray]): List of extra input values.
name (str): Name scope.
Raises:
Exc... | Perform optimization.
Args:
inputs (list[numpy.ndarray]): List of input values.
extra_inputs (list[numpy.ndarray]): List of extra input values.
name (str): Name scope.
Raises:
Exception: If loss function is None, i.e. not defined.
| optimize | python | rlworkgroup/garage | src/garage/tf/optimizers/lbfgs_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/lbfgs_optimizer.py | MIT |
def f_opt_wrapper(flat_params):
"""Helper function to set parameters values.
Args:
flat_params (numpy.ndarray): Flattened parameter values.
Returns:
list[tf.Tensor]: Loss and gradient tensor.
"""
s... | Helper function to set parameters values.
Args:
flat_params (numpy.ndarray): Flattened parameter values.
Returns:
list[tf.Tensor]: Loss and gradient tensor.
| f_opt_wrapper | python | rlworkgroup/garage | src/garage/tf/optimizers/lbfgs_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/lbfgs_optimizer.py | MIT |
def opt_callback(params):
"""Callback function wrapper.
Args:
params (numpy.ndarray): Parameters.
"""
loss = self._opt_fun['f_loss'](*(inputs + extra_inputs))
elapsed = time.time() - start_time
... | Callback function wrapper.
Args:
params (numpy.ndarray): Parameters.
| opt_callback | python | rlworkgroup/garage | src/garage/tf/optimizers/lbfgs_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/lbfgs_optimizer.py | MIT |
def update_opt(self,
loss,
target,
leq_constraint,
inputs,
constraint_name='constraint',
name='PenaltyLBFGSOptimizer',
**kwargs):
"""Construct operation graph for the optimizer.
... | Construct operation graph for the optimizer.
Args:
loss (tf.Tensor): Loss objective to minimize.
target (object): Target object to optimize. The object should
implemenet `get_params()` and `get_param_values`.
leq_constraint (tuple): It contains a tf.Tensor an... | update_opt | python | rlworkgroup/garage | src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | MIT |
def get_opt_output():
"""Helper function to construct graph.
Returns:
list[tf.Tensor]: Penalized loss and gradient tensor.
"""
with tf.name_scope('get_opt_output'):
grads = tf.gradients(penalized_loss, params)
... | Helper function to construct graph.
Returns:
list[tf.Tensor]: Penalized loss and gradient tensor.
| get_opt_output | python | rlworkgroup/garage | src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | MIT |
def loss(self, inputs):
"""The loss.
Args:
inputs (list[numpy.ndarray]): List of input values.
Returns:
float: Loss.
Raises:
Exception: If loss function is None, i.e. not defined.
"""
if self._opt_fun is None:
raise Exce... | The loss.
Args:
inputs (list[numpy.ndarray]): List of input values.
Returns:
float: Loss.
Raises:
Exception: If loss function is None, i.e. not defined.
| loss | python | rlworkgroup/garage | src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | MIT |
def constraint_val(self, inputs):
"""The constraint value.
Args:
inputs (list[numpy.ndarray]): List of input values.
Returns:
float: Constraint value.
Raises:
Exception: If loss function is None, i.e. not defined.
"""
if self._opt_f... | The constraint value.
Args:
inputs (list[numpy.ndarray]): List of input values.
Returns:
float: Constraint value.
Raises:
Exception: If loss function is None, i.e. not defined.
| constraint_val | python | rlworkgroup/garage | src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | MIT |
def optimize(self, inputs, name='optimize'):
"""Perform optimization.
Args:
inputs (list[numpy.ndarray]): List of input values.
name (str): Name scope.
Raises:
Exception: If loss function is None, i.e. not defined.
"""
if self._opt_fun is No... | Perform optimization.
Args:
inputs (list[numpy.ndarray]): List of input values.
name (str): Name scope.
Raises:
Exception: If loss function is None, i.e. not defined.
| optimize | python | rlworkgroup/garage | src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | MIT |
def gen_f_opt(penalty): # noqa: D202
"""Return a function that set parameters values.
Args:
penalty (float): Penalty.
Returns:
callable: Function that set parameters values.
"""
def f(flat_params... | Return a function that set parameters values.
Args:
penalty (float): Penalty.
Returns:
callable: Function that set parameters values.
| gen_f_opt | python | rlworkgroup/garage | src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | MIT |
def f(flat_params):
"""Helper function to set parameters values.
Args:
flat_params (numpy.ndarray): Flatten parameter values.
Returns:
list[tf.Tensor]: Penalized loss and gradient tensor.
"... | Helper function to set parameters values.
Args:
flat_params (numpy.ndarray): Flatten parameter values.
Returns:
list[tf.Tensor]: Penalized loss and gradient tensor.
| f | python | rlworkgroup/garage | src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/penalty_lbfgs_optimizer.py | MIT |
def __getitem__(self, key):
"""See :meth:`object.__getitem__`.
Args:
key (Hashable): Key associated with the value to retrieve.
Returns:
object: Lazily-evaluated value of the :class:`Callable` associated
with key.
"""
if key not in self._d... | See :meth:`object.__getitem__`.
Args:
key (Hashable): Key associated with the value to retrieve.
Returns:
object: Lazily-evaluated value of the :class:`Callable` associated
with key.
| __getitem__ | python | rlworkgroup/garage | src/garage/tf/optimizers/_dtypes.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/_dtypes.py | MIT |
def get(self, key, default=None):
"""See :meth:`dict.get`.
Args:
key (Hashable): Key associated with the value to retreive.
default (object): Value to return if key is not present in this
:class:`LazyDict`.
Returns:
object: Value associated wi... | See :meth:`dict.get`.
Args:
key (Hashable): Key associated with the value to retreive.
default (object): Value to return if key is not present in this
:class:`LazyDict`.
Returns:
object: Value associated with key if the key is present, otherwise
... | get | python | rlworkgroup/garage | src/garage/tf/optimizers/_dtypes.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/optimizers/_dtypes.py | MIT |
def update_plot(self, policy, max_length=np.inf):
"""Update the policy being plotted.
Args:
policy (garage.tf.Policy): Policy to visualize.
max_length (int or float): The maximum length to allow an episode
to be. Defaults to infinity.
"""
if self... | Update the policy being plotted.
Args:
policy (garage.tf.Policy): Policy to visualize.
max_length (int or float): The maximum length to allow an episode
to be. Defaults to infinity.
| update_plot | python | rlworkgroup/garage | src/garage/tf/plotter/plotter.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/plotter/plotter.py | MIT |
def get_action(self, observation):
"""Return a single action.
Args:
observation (numpy.ndarray): Observations.
Returns:
int: Action given input observation.
dict(numpy.ndarray): Distribution parameters.
"""
sample, prob = self.get_actions([o... | Return a single action.
Args:
observation (numpy.ndarray): Observations.
Returns:
int: Action given input observation.
dict(numpy.ndarray): Distribution parameters.
| get_action | python | rlworkgroup/garage | src/garage/tf/policies/categorical_cnn_policy.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/policies/categorical_cnn_policy.py | MIT |
def get_actions(self, observations):
"""Return multiple actions.
Args:
observations (numpy.ndarray): Observations.
Returns:
list[int]: Actions given input observations.
dict(numpy.ndarray): Distribution parameters.
"""
if not isinstance(obse... | Return multiple actions.
Args:
observations (numpy.ndarray): Observations.
Returns:
list[int]: Actions given input observations.
dict(numpy.ndarray): Distribution parameters.
| get_actions | python | rlworkgroup/garage | src/garage/tf/policies/categorical_cnn_policy.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/policies/categorical_cnn_policy.py | MIT |
def build(self, state_input, name=None):
"""Build policy.
Args:
state_input (tf.Tensor) : State input.
name (str): Name of the policy, which is also the name scope.
Returns:
tfp.distributions.OneHotCategorical: Policy distribution.
tf.Tensor: Ste... | Build policy.
Args:
state_input (tf.Tensor) : State input.
name (str): Name of the policy, which is also the name scope.
Returns:
tfp.distributions.OneHotCategorical: Policy distribution.
tf.Tensor: Step output, with shape :math:`(N, S^*)`.
t... | build | python | rlworkgroup/garage | src/garage/tf/policies/categorical_gru_policy.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/policies/categorical_gru_policy.py | MIT |
def reset(self, do_resets=None):
"""Reset the policy.
Note:
If `do_resets` is None, it will be by default np.array([True]),
which implies the policy will not be "vectorized", i.e. number of
paralle environments for training data sampling = 1.
Args:
... | Reset the policy.
Note:
If `do_resets` is None, it will be by default np.array([True]),
which implies the policy will not be "vectorized", i.e. number of
paralle environments for training data sampling = 1.
Args:
do_resets (numpy.ndarray): Bool that indi... | reset | python | rlworkgroup/garage | src/garage/tf/policies/categorical_gru_policy.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/policies/categorical_gru_policy.py | MIT |
def state_info_specs(self):
"""State info specifcation.
Returns:
List[str]: keys and shapes for the information related to the
policy's state when taking an action.
"""
if self._state_include_action:
return [
('prev_action', (self... | State info specifcation.
Returns:
List[str]: keys and shapes for the information related to the
policy's state when taking an action.
| state_info_specs | python | rlworkgroup/garage | src/garage/tf/policies/categorical_gru_policy.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/policies/categorical_gru_policy.py | MIT |
def build(self, state_input, name=None):
"""Build policy.
Args:
state_input (tf.Tensor) : State input.
name (str): Name of the policy, which is also the name scope.
Returns:
tfp.distributions.OneHotCategorical: Policy distribution.
tf.Tensor: Ste... | Build policy.
Args:
state_input (tf.Tensor) : State input.
name (str): Name of the policy, which is also the name scope.
Returns:
tfp.distributions.OneHotCategorical: Policy distribution.
tf.Tensor: Step output, with shape :math:`(N, S^*)`
tf... | build | python | rlworkgroup/garage | src/garage/tf/policies/categorical_lstm_policy.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/policies/categorical_lstm_policy.py | MIT |
def get_regularizable_vars(self):
"""Get regularizable weight variables under the Policy scope.
Returns:
list[tf.Tensor]: Trainable variables.
"""
trainable = self.get_trainable_vars()
return [
var for var in trainable
if 'hidden' in var.name... | Get regularizable weight variables under the Policy scope.
Returns:
list[tf.Tensor]: Trainable variables.
| get_regularizable_vars | python | rlworkgroup/garage | src/garage/tf/policies/categorical_mlp_policy.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/policies/categorical_mlp_policy.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.