def build_from_data(self, X, f, df=None, avdim=None): X, f, M, m = process_inputs_outputs(X, f) self.X, self.f, self.m = X, f, m # if gradients aren't available, estimate them from data if df is None: df = local_linear_gradients(X, f) # compute the active subspace ss = Subspaces() ss.compute(df) if avdim is not None: ss.partition(avdim) self.n = ss.W1.shape[1] print 'Dimension of subspace is {:d}'.format(self.n) # set up the active variable domain and map if self.bndflag: avdom = BoundedActiveVariableDomain(ss) avmap = BoundedActiveVariableMap(avdom) else: avdom = UnboundedActiveVariableDomain(ss) avmap = UnboundedActiveVariableMap(avdom) # build the response surface avrs = ActiveSubspaceResponseSurface(avmap) avrs.train_with_data(X, f) self.av_respsurf = avrs
def opg_subspace(X, f, weights): """Estimate active subspace with local linear models. This approach is related to the sufficient dimension reduction method known sometimes as the outer product of gradient method. See the 2001 paper 'Structure adaptive approach for dimension reduction' from Hristache, et al. Parameters ---------- X : ndarray M-by-m matrix of input samples, oriented as rows f : ndarray M-by-1 vector of output samples corresponding to the rows of `X` weights : ndarray M-by-1 weight vector, corresponds to numerical quadrature rule used to estimate matrix whose eigenspaces define the active subspace Returns ------- e : ndarray m-by-1 vector of eigenvalues W : ndarray m-by-m orthogonal matrix of eigenvectors """ X, f, M, m = process_inputs_outputs(X, f) # Obtain gradient approximations using local linear regressions df = local_linear_gradients(X, f, weights=weights) # Use gradient approximations to compute active subspace opg_weights = np.ones((df.shape[0], 1)) / df.shape[0] e, W = active_subspace(df, opg_weights) return e, W
def build_from_data(self, X, f, df=None): X, M, m = process_inputs(X) self.X, self.m, self.f = X, m, f # if gradients aren't available, estimate them from data if df is None: df = local_linear_gradients(X, f) self.df = df # compute the active subspaces self.subspaces = build_subspaces(df)
def opg_subspace(X, f, weights): """ TODO: docs """ X, f, M, m = process_inputs_outputs(X, f) # Obtain gradient approximations using local linear regressions df = local_linear_gradients(X, f, weights=weights) # Use gradient approximations to compute active subspace opg_weights = np.ones((df.shape[0], 1)) / df.shape[0] e, W = active_subspace(df, opg_weights) return e, W
def build_from_data(self, X, f, df=None, avdim=None): """ Build the active subspace-enabled model with input/output pairs. :param ndarray X: M-by-m matrix with evaluations of the m-dimensional simulation inputs. :param ndarray f: M-by-1 matrix with corresponding simulation quantities of interest. :param ndarray df: M-by-m matrix that contains the gradients of the simulation quantity of interest, oriented row-wise, that correspond to the rows of `X`. If `df` is not present, then it is estimated with crude local linear models using the pairs `X` and `f`. :param int avdim: The dimension of the active subspace. If `avdim` is not present, a crude heuristic is used to choose an active subspace dimension based on the given data `X` and `f`---and possible `df`. **Notes** This method follows these steps: #. If `df` is None, estimate it with local linear models using the \ input/output pairs `X` and `f`. #. Compute the active and inactive subspaces using `df`. #. Train a response surface using `X` and `f` that exploits the active \ subspace. """ X, f, M, m = process_inputs_outputs(X, f) # check if the given inputs satisfy the assumptions if self.bounded_inputs: if np.any(X) > 1.0 or np.any(X) < -1.0: raise Exception('The supposedly bounded inputs exceed the \ bounds [-1,1].') else: if np.any(X) > 10.0 or np.any(X) < -10.0: raise Exception('There is a very good chance that your \ unbounded inputs are not properly scaled.') self.X, self.f, self.m = X, f, m if df is not None: df, M_df, m_df = process_inputs(df) if m_df != m: raise ValueError('The dimension of the gradients should be \ the same as the dimension of the inputs.') else: # if gradients aren't available, estimate them from data df = local_linear_gradients(X, f) # compute the active subspace ss = Subspaces() ss.compute(df) if avdim is not None: if not isinstance(avdim, int): raise TypeError('avdim should be an integer.') else: ss.partition(avdim) self.n = ss.W1.shape[1] print 'The dimension of the active subspace is {:d}.'.format(self.n) # set up the active variable domain and map if self.bounded_inputs: avdom = BoundedActiveVariableDomain(ss) avmap = BoundedActiveVariableMap(avdom) else: avdom = UnboundedActiveVariableDomain(ss) avmap = UnboundedActiveVariableMap(avdom) # build the response surface asrs = ActiveSubspaceResponseSurface(avmap) asrs.train_with_data(X, f) # set the R-squared coefficient self.Rsqr = asrs.respsurf.Rsqr self.as_respsurf = asrs