Domains¶
Utilities for building the domains and maps for active variables.
-
class
active_subspaces.domains.
ActiveVariableDomain
¶ A base class for the domain of functions of active variables.
-
subspaces
¶ Subspaces
subspaces that define the domain
-
m
¶ int
the dimension of the simulation inputs
-
n
¶ int
the dimension of the active subspace
-
vertY
¶ ndarray
n-dimensional vertices that define the boundary of the domain when the m-dimensional space is a hypercube
-
vertX
¶ ndarray
corners of the m-dimensional hypercube that map to the points vertY
-
convhull
¶ scipy.spatial.ConvexHull
the ConvexHull object defined by the vertices vertY
-
constraints
¶ dict
a dictionary of linear inequality constraints conforming to the specifications used in the scipy.optimizer library
Notes
Attributes vertY, vertX, convhull, and constraints are None when the m-dimensional parameter space is unbounded.
-
-
class
active_subspaces.domains.
ActiveVariableMap
(domain)¶ A base class for the map between active/inactive and original variables.
-
domain
¶ ActiveVariableDomain
an ActiveVariableDomain object
See also
domains.UnboundedActiveVariableMap
,domains.BoundedActiveVariableMap
-
forward
(X)¶ Map full variables to active variables.
Map the points in the original input space to the active and inactive variables.
Parameters: X (ndarray) – an M-by-m matrix, each row of X is a point in the original parameter space Returns: - Y (ndarray) – M-by-n matrix that contains points in the space of active variables. Each row of Y corresponds to a row of X.
- Z (ndarray) – M-by-(m-n) matrix that contains points in the space of inactive variables. Each row of Z corresponds to a row of X.
-
inverse
(Y, N=1)¶ Find points in full space that map to active variable points.
Map the points in the active variable space to the original parameter space.
Parameters: - Y (ndarray) – M-by-n matrix that contains points in the space of active variables
- N (int, optional) – the number of points in the original parameter space that are returned that map to the given active variables (default 1)
Returns: - X (ndarray) – (M*N)-by-m matrix that contains points in the original parameter space
- ind (ndarray) – (M*N)-by-1 matrix that contains integer indices. These indices identify which rows of X map to which rows of Y.
Notes
The inverse map depends critically on the regularize_z function.
-
regularize_z
(Y, N)¶ Pick inactive variables associated active variables.
Find points in the space of inactive variables to complete the inverse map.
Parameters: - Y (ndarray) – M-by-n matrix that contains points in the space of active variables
- N (int) – The number of points in the original parameter space that are returned that map to the given active variables
Returns: Z – (M)-by-(m-n)-by-N matrix that contains values of the inactive variables
Return type: ndarray
Notes
The base class does not implement regularize_z. Specific implementations depend on whether the original variables are bounded or unbounded. They also depend on what the weight function is on the original parameter space.
-
-
class
active_subspaces.domains.
BoundedActiveVariableDomain
(subspaces)¶ Domain of functions with bounded domains (uniform on hypercube).
An class for the domain of functions of active variables when the space of simulation parameters is bounded.
Notes
Using this class assumes that the space of simulation inputs is equipped with a uniform weight function. And the space itself is a hypercube.
-
compute_boundary
()¶ Compute and set the boundary of the domain.
Notes
This function computes the boundary of the active variable range, i.e., the domain of a function of the active variables, and it sets the attributes to the computed components. It is called when the BoundedActiveVariableDomain is initialized. If the dimension of the active subspaces is manually changed, then this function must be called again to recompute the boundary of the domain.
-
-
class
active_subspaces.domains.
BoundedActiveVariableMap
(domain)¶ Class for mapping between active and bounded full variables.
A class for the map between active/inactive and original variables when the original variables are bounded by a hypercube with a uniform density.
See also
domains.UnboundedActiveVariableMap
-
regularize_z
(Y, N)¶ Pick inactive variables associated active variables.
Find points in the space of inactive variables to complete the inverse map.
Parameters: - Y (ndarray) – M-by-n matrix that contains points in the space of active variables
- N (int) – The number of points in the original parameter space that are returned that map to the given active variables
Returns: Z – (M)-by-(m-n)-by-N matrix that contains values of the inactive variables
Return type: ndarray
Notes
This implementation of regularize_z uses the function sample_z to randomly sample values of the inactive variables to complement the given values of the active variables.
-
-
class
active_subspaces.domains.
UnboundedActiveVariableDomain
(subspaces)¶ Domain of functions with unbounded domains (Gaussian weight).
An class for the domain of functions of active variables when the space of simulation parameters is unbounded.
Notes
Using this class assumes that the space of simulation inputs is equipped with a Gaussian weight function.
-
class
active_subspaces.domains.
UnboundedActiveVariableMap
(domain)¶ Class for mapping between active and unbounded full variables.
A class for the map between active/inactive and original variables when the original variables are ubbounded and the space is equipped with a standard Gaussian density.
See also
domains.BoundedActiveVariableMap
-
regularize_z
(Y, N)¶ Pick inactive variables associated active variables.
Find points in the space of inactive variables to complete the inverse map.
Parameters: - Y (ndarray) – M-by-n matrix that contains points in the space of active variables
- N (int) – The number of points in the original parameter space that are returned that map to the given active variables
Returns: Z – (M)-by-(m-n)-by-N matrix that contains values of the inactive variables
Return type: ndarray
Notes
This implementation of regularize_z samples the inactive variables from a standard (m-n)-variate Gaussian distribution.
-
-
active_subspaces.domains.
hit_and_run_z
(N, y, W1, W2)¶ A hit and run method for sampling the inactive variables from a polytope.
See also
domains.sample_z()
-
active_subspaces.domains.
interval_endpoints
(W1)¶ Compute the range of a 1d active variable.
Parameters: W1 (ndarray) – m-by-1 matrix that contains the eigenvector that defines the first active variable Returns: - Y (ndarray) – 2-by-1 matrix that contains the endpoints of the interval defining the range of the 1d active variable
- X (ndarray) – 2-by-m matrix that contains the corners of the m-dimensional hypercube that map to the active variable endpoints
-
active_subspaces.domains.
nzv
(m, n)¶ Number of zonotope vertices.
Compute the number of zonotope vertices for a linear map from R^m to R^n.
Parameters: - m (int) – the dimension of the hypercube
- n (int) – the dimension of the low-dimesional subspace
Returns: N – the number of vertices defining the zonotope
Return type: int
-
active_subspaces.domains.
random_walk_z
(N, y, W1, W2)¶ A random walk method for sampling from a polytope.
See also
domains.sample_z()
-
active_subspaces.domains.
rejection_sampling_z
(N, y, W1, W2)¶ A rejection sampling method for sampling the from a polytope.
See also
domains.sample_z()
-
active_subspaces.domains.
sample_z
(N, y, W1, W2)¶ Sample inactive variables.
Sample values of the inactive variables for a fixed value of the active variables when the original variables are bounded by a hypercube.
Parameters: - N (int) – the number of inactive variable samples
- y (ndarray) – the value of the active variables
- W1 (ndarray) – m-by-n matrix that contains the eigenvector bases of the n-dimensional active subspace
- W2 (ndarray) – m-by-(m-n) matrix that contains the eigenvector bases of the (m-n)-dimensional inactive subspace
Returns: Z – N-by-(m-n) matrix that contains values of the active variable that correspond to the given y
Return type: ndarray
Notes
The trick here is to sample the inactive variables z so that -1 <= W1*y + W2*z <= 1, where y is the given value of the active variables. In other words, we need to sample z such that it respects the linear equalities W2*z <= 1 - W1*y, -W2*z <= 1 + W1*y. These inequalities define a polytope in R^(m-n). We want to sample N points uniformly from the polytope.
This function first tries a simple rejection sampling scheme, which (i) finds a bounding hyperbox for the polytope, (ii) draws points uniformly from the bounding hyperbox, and (iii) rejects points outside the polytope.
If that method does not return enough samples, the method tries a “hit and run” method for sampling from the polytope.
If that doesn’t work, it returns an array with N copies of a feasible point computed as the Chebyshev center of the polytope. Thanks to David Gleich for showing me Chebyshev centers.
-
active_subspaces.domains.
unique_rows
(S)¶ Return the unique rows from ndarray
Parameters: S (ndarray) – array with rows to reduces Returns: T – version of S with unique rows Return type: ndarray Notes
http://stackoverflow.com/questions/16970982/find-unique-rows-in-numpy-array
-
active_subspaces.domains.
zonotope_vertices
(W1, Nsamples=10000, maxcount=100000)¶ Compute the vertices of the zonotope.
Parameters: - W1 (ndarray) – m-by-n matrix that contains the eigenvector bases of the n-dimensional active subspace
- Nsamples (int, optional) – number of samples per iteration to check (default 1e4)
- maxcount (int, optional) – maximum number of iterations (default 1e5)
Returns: - Y (ndarray) – nzv-by-n matrix that contains the zonotope vertices
- X (ndarray) – nzv-by-m matrix that contains the corners of the m-dimensional hypercube that map to the zonotope vertices