Basis

Fourier

class FourierBasis(low, delta, c, dimensions=None)[source]

Bases: object

Class implementing Fourier basis functions. The value of the feature is computed using the formula:

\[\sum \cos{\pi(X - m)/\Delta c}\]

where X is the input, m is the vector of the minumum input values (for each dimensions) , Delta is the vector of maximum

__init__(low, delta, c, dimensions=None)[source]

Constructor.

Parameters:
  • low (np.ndarray) – vector of minimum values of the input variables;

  • delta (np.ndarray) – vector of the maximum difference between two values of the input variables, i.e. delta = high - low;

  • c (np.ndarray) – vector of weights for the state variables;

  • dimensions (list, None) – list of the dimensions of the input to be considered by the feature.

__call__(x)[source]

Call self as a function.

static generate(low, high, n, dimensions=None)[source]

Factory method to build a set of fourier basis.

Parameters:
  • low (np.ndarray) – vector of minimum values of the input variables;

  • high (np.ndarray) – vector of maximum values of the input variables;

  • n (int) – number of harmonics to consider for each state variable

  • dimensions (list, None) – list of the dimensions of the input to be considered by the features.

Returns:

The list of the generated fourier basis functions.

Gaussian RBF

class GaussianRBF(mean, scale, dimensions=None)[source]

Bases: object

Class implementing Gaussian radial basis functions. The value of the feature is computed using the formula:

\[\sum \dfrac{(X_i - \mu_i)^2}{\sigma_i}\]

where X is the input, mu is the mean vector and sigma is the scale parameter vector.

__init__(mean, scale, dimensions=None)[source]

Constructor.

Parameters:
  • mean (np.ndarray) – the mean vector of the feature;

  • scale (np.ndarray) – the scale vector of the feature;

  • dimensions (list, None) – list of the dimensions of the input to be considered by the feature. The number of dimensions must match the dimensionality of mean and scale.

__call__(x)[source]

Call self as a function.

static generate(n_centers, low, high, dimensions=None, eta=0.25)[source]

Factory method to build uniformly spaced gaussian 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 n_centers and low;

  • eta (float, 0.25) – percentage of overlap between the features.

Returns:

The list of the generated radial basis functions.

Polynomial

class PolynomialBasis(dimensions=None, degrees=None, low=None, high=None)[source]

Bases: object

Class implementing polynomial basis functions. The value of the feature is computed using the formula:

\[\prod X_i^{d_i}\]

where X is the input and d is the vector of the exponents of the polynomial.

__init__(dimensions=None, degrees=None, low=None, high=None)[source]

Constructor. If both parameters are None, the constant feature is built.

Parameters:
  • dimensions (list, None) – list of the dimensions of the input to be considered by the feature;

  • degrees (list, None) – list of the degrees of each dimension to be considered by the feature. It must match the number of elements of dimensions;

  • low (np.ndarray, None) – array specifying the lower bound of the action space, used to normalize the state between -1 and 1;

  • high (np.ndarray, None) – array specifying the lower bound of the action space, used to normalize the state between -1 and 1;

__call__(x)[source]

Call self as a function.

static _compute_exponents(order, n_variables)[source]

Find the exponents of a multivariate polynomial expression of order order and n_variables number of variables.

Parameters:
  • order (int) – the maximum order of the polynomial;

  • n_variables (int) – the number of elements of the input vector.

Yields:

The current exponent of the polynomial.

static generate(max_degree, input_size, low=None, high=None)[source]

Factory method to build a polynomial of order max_degree based on the first input_size dimensions of the input.

Parameters:
  • max_degree (int) – maximum degree of the polynomial;

  • input_size (int) – size of the input;

  • low (np.ndarray, None) – array specifying the lower bound of the action space, used to normalize the state between -1 and 1;

  • high (np.ndarray, None) – array specifying the lower bound of the action space, used to normalize the state between -1 and 1;

Returns:

The list of the generated polynomial basis functions.