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 fit(self, paths):
"""Fit regressor based on paths.
Args:
paths (list[dict]): 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_space.flatt... | Fit regressor based on paths.
Args:
paths (list[dict]): Sample paths.
| fit | python | rlworkgroup/garage | src/garage/tf/baselines/gaussian_mlp_baseline.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/baselines/gaussian_mlp_baseline.py | MIT |
def predict(self, paths):
"""Predict value based on paths.
Args:
paths (list[dict]): Sample paths.
Returns:
numpy.ndarray: Predicted value.
"""
xs = paths['observations']
if not isinstance(xs, np.ndarray) or len(xs.shape) > 2:
xs = s... | Predict value based on paths.
Args:
paths (list[dict]): Sample paths.
Returns:
numpy.ndarray: Predicted value.
| predict | python | rlworkgroup/garage | src/garage/tf/baselines/gaussian_mlp_baseline.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/baselines/gaussian_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_mean']
... | Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
| __getstate__ | python | rlworkgroup/garage | src/garage/tf/baselines/gaussian_mlp_baseline.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/baselines/gaussian_mlp_baseline.py | MIT |
def network_output_spec(self):
"""Network output spec.
Return:
list[str]: List of key(str) for the network outputs.
"""
return [
'normalized_dist', 'normalized_mean', 'normalized_log_std', 'dist',
'mean', 'log_std', 'x_mean', 'x_std', 'y_mean', 'y_st... | 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_mlp_baseline_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/baselines/gaussian_mlp_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 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/gaussian_mlp_encoder.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/embeddings/gaussian_mlp_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/gaussian_mlp_encoder.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/embeddings/gaussian_mlp_encoder.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_dist']
del new_dict['_network']
return new_dict | Object.__getstate__.
Returns:
dict: the state to be pickled for the instance.
| __getstate__ | 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): 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_max_pooling.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/cnn_model_max_pooling.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 network_output_spec(self):
"""Network output spec.
Returns:
list[str]: Name of the model outputs, in order.
"""
return [
'dist', 'step_mean', 'step_log_std', 'step_hidden', 'init_hidden'
] | Network output spec.
Returns:
list[str]: Name of the model outputs, in order.
| network_output_spec | 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 _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 __getstate__(self):
"""Object.__getstate__.
Returns:
dict: the state to be pickled for the instance.
"""
new_dict = super().__getstate__()
del new_dict['_mean_std_gru_cell']
del new_dict['_mean_gru_cell']
del new_dict['_mean_std_output_nonlineari... | Object.__getstate__.
Returns:
dict: the state to be pickled for the instance.
| __getstate__ | 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 network_output_spec(self):
"""Network output spec.
Returns:
list[str]: Name of the model outputs, in order.
"""
return [
'dist', 'step_mean', 'step_log_std', '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/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 __getstate__(self):
"""Object.__getstate__.
Returns:
dict: the state to be pickled for the instance.
"""
new_dict = super().__getstate__()
del new_dict['_mean_std_lstm_cell']
del new_dict['_mean_lstm_cell']
del new_dict['_mean_std_output_nonlinea... | Object.__getstate__.
Returns:
dict: the state to be pickled for the instance.
| __getstate__ | 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 __getstate__(self):
"""Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
"""
new_dict = super().__getstate__()
del new_dict['_gru_cell']
del new_dict['_output_nonlinearity_layer']
return new_dict | Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
| __getstate__ | 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 network_output_spec(self):
"""Network output spec.
Return:
list[str]: List of key(str) for the network outputs.
"""
return [
'all_output', 'step_output', 'step_hidden', 'step_cell',
'init_hidden', 'init_cell'
] | Network output spec.
Return:
list[str]: List of key(str) for the network outputs.
| network_output_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 __getstate__(self):
"""Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
"""
new_dict = super().__getstate__()
del new_dict['_lstm_cell']
del new_dict['_output_nonlinearity_layer']
return new_dict | Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
| __getstate__ | 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, 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/mlp_dueling_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/mlp_dueling_model.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, 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/mlp_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/mlp_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 __getstate__(self):
"""Get the pickle state.
Returns:
dict: The pickled state.
"""
new_dict = super().__getstate__()
del new_dict['_networks']
new_dict['_default_parameters'] = self.parameters
return new_dict | Get the pickle state.
Returns:
dict: The pickled state.
| __getstate__ | 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 __getstate__(self):
"""Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
"""
new_dict = self.__dict__.copy()
del new_dict['_cached_params']
return new_dict | Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
| __getstate__ | python | rlworkgroup/garage | src/garage/tf/models/module.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/module.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/normalized_input_mlp_model.py | https://github.com/rlworkgroup/garage/blob/master/src/garage/tf/models/normalized_input_mlp_model.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 __getstate__(self):
"""Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
"""
new_dict = super().__getstate__()
del new_dict['_first_network']
del new_dict['_last_network']
return new_dict | Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
| __getstate__ | 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 __getstate__(self):
"""Object.__getstate__.
Returns:
dict: the state to be pickled for the instance.
"""
new_dict = self.__dict__.copy()
del new_dict['_hvp_fun']
return new_dict | Object.__getstate__.
Returns:
dict: the state to be pickled for the instance.
| __getstate__ | 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_hvp(self, f, target, inputs, reg_coeff, name='PearlmutterHVP'):
"""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
... | 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 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 update_hvp(self,
f,
target,
inputs,
reg_coeff,
name='FiniteDifferenceHVP'):
"""Build the symbolic graph to compute the Hessian-vector product.
Args:
f (tf.Tensor): The function whose Hessian n... | 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 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 __getstate__(self):
"""Object.__getstate__.
Returns:
dict: the state to be pickled for the instance.
"""
new_dict = self.__dict__.copy()
del new_dict['_opt_fun']
return new_dict | Object.__getstate__.
Returns:
dict: the state to be pickled for the instance.
| __getstate__ | 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 __getstate__(self):
"""Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
"""
new_dict = self.__dict__.copy()
del new_dict['_opt_fun']
del new_dict['_tf_optimizer']
del new_dict['_train_op']
del new_dict['_input... | Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
| __getstate__ | 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 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/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 __getstate__(self):
"""Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
"""
new_dict = self.__dict__.copy()
del new_dict['_opt_fun']
return new_dict | Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
| __getstate__ | 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 __getstate__(self):
"""Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
"""
new_dict = self.__dict__.copy()
del new_dict['_opt_fun']
return new_dict | Object.__getstate__.
Returns:
dict: The state to be pickled for the instance.
| __getstate__ | 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 |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves Python code examples from Django repository that contain 'django' in the code, which helps identify Django-specific code snippets but provides limited analytical insights beyond basic filtering.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.