Tensors
- class ConstantTensor(*args: Any, **kwargs: Any)[source]
Bases:
Module
Pytorch module to implement a constant function (always one).
- class GenericBasisTensor(*args: Any, **kwargs: Any)[source]
Bases:
Module
Abstract Pytorch module to implement a generic basis function. All the basis function generated by this module are
- __init__(mu, scale, dim=None, normalized=False)[source]
Constructor.
- Parameters:
mu (np.ndarray) – centers of the gaussian RBFs;
scale (np.ndarray) – scales for the RBFs;
dim (np.ndarray, None) – list of dimension to be considered for the computation of the features. If None, all dimension are used to compute the features;
normalized (bool, False) – whether the features need to be normalized to sum to one or not;
- static _convert_to_scale(w)[source]
Converts width of a basis function to scale
- Parameters:
w (np.ndarray) – array of widths of basis function for every dimension
- Returns:
The array of scales for each basis function in any given dimension
- classmethod is_cyclic()[source]
Method used to change the basis generation in case of cyclic features. :returns: Whether the space we consider is cyclic or not.
- classmethod generate(n_centers, low, high, dimensions=None, eta=0.25, normalized=False)[source]
Factory method that generates the list of dictionaries to build the tensors representing a set of uniformly spaced radial basis functions with eta overlap.
- Parameters:
n_centers (list) – list of the number of radial basis functions to be used for each dimension;
low (np.ndarray) – lowest value for each dimension;
high (np.ndarray) – highest value for each dimension;
dimensions (list, None) – list of the dimensions of the input to be considered by the feature. The number of dimensions must match the number of elements in
high
andlow
;eta (float, 0.25) – percentage of overlap between the features;
normalized (bool, False) – whether the features need to be normalized to sum to one or not.
- Returns:
The tensor list.
- class GaussianRBFTensor(*args: Any, **kwargs: Any)[source]
Bases:
GenericBasisTensor
- class VonMisesBFTensor(*args: Any, **kwargs: Any)[source]
Bases:
GenericBasisTensor
- class RandomFourierBasis(*args: Any, **kwargs: Any)[source]
Bases:
Module
Class implementing Random Fourier basis functions. The value of the feature is computed using the formula:
\[\sin{\dfrac{PX}{\nu}+\varphi}\]where \(X\) is the input, \(P\) is a random weights matrix, \(\nu\) is the bandwidth parameter and \(\varphi\) is a bias vector.
These features have been presented in:
“Towards generalization and simplicity in continuous control”. Rajeswaran A. et Al.. 2017.
- __init__(P, phi, nu)[source]
Constructor.
- Parameters:
P (np.ndarray) – weights matrix, every weight should be drawn from a normal distribution;
phi (np.ndarray) – bias vector, every weight should be drawn from a uniform distribution in the interval :math: [-pi, pi);
nu (float) – bandwidth parameter, it should be chosen approximately as the average pairwise distances between different observation vectors.
- static generate(nu, n_output, input_size, use_bias=True)[source]
Factory method to build random fourier basis. Includes a constant tensor into the output.
- Parameters:
nu (float) – bandwidth parameter, it should be chosen approximately as the average pairwise distances between different observation vectors.
n_output (int) – number of basis to use;
input_size (int) – size of the input.
- Returns:
The list of the generated fourier basis functions.