Response Surfaces (Utils)

Utilities for building response surface approximations.

class active_subspaces.utils.response_surfaces.PolynomialApproximation(N=2)

Least-squares-fit, global, multivariate polynomial approximation.

poly_weights

ndarray

an ndarray of coefficients for the polynomial approximation in the monomial basis

g

ndarray

contains the m coefficients corresponding to the degree 1 monomials in the polynomial approximation

H

ndarray

an ndarray of shape m-by-m that contains the coefficients of the degree 2 monomials in the approximation

See also

utils.response_surfaces.RadialBasisApproximation

Notes

All attributes besides the degree N are set when the class’s train method is called.

predict(X, compgrad=False)

Evaluate least-squares-fit polynomial approximation at new points.

Parameters:
  • X (ndarray) – an ndarray of points to evaluate the polynomial approximation. The shape is M-by-m, where m is the number of dimensions.
  • compgrad (bool, optional) – a flag to decide whether or not to compute the gradient of the polynomial approximation at the points X. (default False)
Returns:

  • f (ndarray) – an ndarray of predictions from the polynomial approximation. The shape of f is M-by-1.
  • df (ndarray) – an ndarray of gradient predictions from the polynomial approximation. The shape of df is M-by-m.

train(X, f, weights=None)

Train the least-squares-fit polynomial approximation.

Parameters:
  • X (ndarray) – an ndarray of training points for the polynomial approximation. The shape is M-by-m, where m is the number of dimensions.
  • f (ndarray) – an ndarray of function values used to train the polynomial approximation. The shape of f is M-by-1.
  • weights (ndarray, optional) – an ndarray of weights for the least-squares. (default is None, which means uniform weights)

Notes

This method sets all the attributes of the class for use in the predict method.

class active_subspaces.utils.response_surfaces.RadialBasisApproximation(N=2)

Approximate a multivariate function with a radial basis.

A class for global, multivariate radial basis approximation with anisotropic squared-exponential radial basis and a weighted-least-squares-fit monomial basis.

radial_weights

ndarray

an ndarray of coefficients radial basis functions in the model

poly_weights

poly_weights

an ndarray of coefficients for the polynomial approximation in the monomial basis

K

ndarray

an ndarray of shape M-by-M that contains the matrix of radial basis functions evaluated at the training points

ell

ndarray

an ndarray of shape m-by-1 that contains the characteristic length scales along each of the inputs

See also

utils.response_surfaces.PolynomialApproximation

Notes

All attributes besides the degree N are set when the class’s train method is called.

predict(X, compgrad=False)

Evaluate the radial basis approximation at new points.

Parameters:
  • X (ndarray) – an ndarray of points to evaluate the polynomial approximation. The shape is M-by-m, where m is the number of dimensions.
  • compgrad (bool, optional) – a flag to decide whether or not to compute the gradient of the polynomial approximation at the points X. (default False)
Returns:

  • f (ndarray) – an ndarray of predictions from the polynomial approximation. The shape of f is M-by-1.
  • df (ndarray) – an ndarray of gradient predictions from the polynomial approximation. The shape of df is M-by-m.

Notes

I’ll tell you what. I just refactored this code to use terminology from radial basis functions instead of Gaussian processes, and I feel so much better about it. Now I don’t have to compute that silly prediction variance and try to pretend that it has anything to do with the actual error in the approximation. Also, computing that variance requires another system solve, which might be expensive. So it’s both expensive and of dubious value. So I got rid of it. Sorry, Gaussian processes.

train(X, f, v=None, e=None)

Train the radial basis approximation.

Parameters:
  • X (ndarray) – an ndarray of training points for the polynomial approximation. The shape is M-by-m, where m is the number of dimensions.
  • f (ndarray) – an ndarray of function values used to train the polynomial approximation. The shape of f is M-by-1.
  • v (ndarray, optional) – contains the regularization parameters that model error in the function values (default None)
  • e (ndarray, optional) – an ndarray containing the eigenvalues from the active subspace analysis. If present, the radial basis uses it to determine the appropriate anisotropy in the length scales. (default None)

Notes

The approximation uses an multivariate, squared exponential radial basis. If e is not None, then the radial basis is anisotropic with length scales determined by e. Otherwise, the basis is isotropic. The length scale parameters (i.e., the rbf shape parameters) are determined with a maximum likelihood heuristic inspired by techniques for fitting a Gaussian process model.

The approximation also includes a monomial basis with monomials of total degree up to order N. These are fit with weighted least-squares, where the weight matrix is the inverse of the matrix of radial basis functions evaluated at the training points.

This method sets all the attributes of the class for use in the predict method.

class active_subspaces.utils.response_surfaces.ResponseSurface(N=2)

An abstract class for response surfaces.

N

int

maximum degree of global polynomial in the response surface

Rsqr

float

the R-squared coefficient for the response surface

X

ndarray

an ndarray of training points for the response surface. The shape is M-by-m, where m is the number of dimensions.

f

ndarray

an ndarray of function values used to train the response surface. The shape of f is M-by-1.

See also

utils.response_surfaces.PolynomialApproximation, utils.response_surfaces.RadialBasisApproximation

active_subspaces.utils.response_surfaces.exponential_squared(X1, X2, sigma, ell)

Compute the matrix of radial basis functions.

Parameters:
  • X1 (ndarray) – contains the centers of the radial functions
  • X2 (ndarray) – the evaluation points of the radial functions
  • sigma (float) – scales the radial functions
  • ell (ndarray) – contains the length scales of each dimension
Returns:

C – the matrix of radial functions centered at X1 and evaluated at X2. The shape of C is X1.shape[0]-by-X2.shape[0].

Return type:

ndarray

active_subspaces.utils.response_surfaces.grad_exponential_squared(X1, X2, sigma, ell)

Compute the matrices of radial basis function gradients.

Parameters:
  • X1 (ndarray) – contains the centers of the radial functions
  • X2 (ndarray) – the evaluation points of the radial functions
  • sigma (float) – scales the radial functions
  • ell (ndarray) – contains the length scales of each dimension
Returns:

dC – the matrix of radial function gradients centered at X1 and evaluated at X2. The shape of dC is X1.shape[0]-by-X2.shape[0]-by-m. dC is a three-dimensional ndarray. The third dimension indexes the partial derivatives in each gradient.

Return type:

ndarray

active_subspaces.utils.response_surfaces.grad_polynomial_bases(X, N)

Compute the gradients of the monomial bases.

Parameters:
  • X (ndarray) – contains the points to evaluate the monomials
  • N (int) – the maximum degree of the monomial basis
Returns:

dB – contains the gradients of the monomials evaluate at X. dB is a three-dimensional ndarray. The third dimension indexes the partial derivatives in each gradient.

Return type:

ndarray

active_subspaces.utils.response_surfaces.index_set(n, d)

Enumerate multi-indices for a total degree of order n in d variables.

Parameters:
  • n (int) – degree of polynomial
  • d (int) – number of variables, dimension
Returns:

I – multi-indices ordered as columns

Return type:

ndarray

active_subspaces.utils.response_surfaces.polynomial_bases(X, N)

Compute the monomial bases.

Parameters:
  • X (ndarray) – contains the points to evaluate the monomials
  • N (int) – the maximum degree of the monomial basis
Returns:

  • B (ndarray) – contains the monomial evaluations
  • I (ndarray) – contains the multi-indices that tell the degree of each univariate monomial term in the multivariate monomial