def set_model(self, model=None, model_grads=None): """ Computes the coefficients of the polynomial. :param Correlations self: An instance of the Correlations class. :param callable model: The function that needs to be approximated. In the absence of a callable function, the input can be the function evaluated at the quadrature points. :param callable model_grads: The gradient of the function that needs to be approximated. In the absence of a callable gradient function, the input can be a matrix of gradient evaluations at the quadrature points. """ # Need to account for the nataf transform here? model_values = None model_grads_values = None if callable(model): model_values = evaluate_model(self._points, model) else: model_values = model if model_grads is not None: if callable(model_grads): model_grads_values = evaluate_model_gradients( self._points, model_grads) else: model_grads_values = model_grads self.corrected_poly.set_model(model_values, model_grads_values)
def _iterative_quadrature_computation(self, integrand, quadrature_order_output=True): # Keep increasing the order till we reach ORDER_LIMIT quadrature_error = 500.0 quadrature_order = 0 integral_before = 10.0 while quadrature_error >= 1e-6: quadrature_order += QUADRATURE_ORDER_INCREMENT pts, wts = self._get_quadrature_points_and_weights( quadrature_order) integral = float(np.dot(wts, evaluate_model(pts, integrand))) quadrature_error = np.abs(integral - integral_before) integral_before = integral if quadrature_order >= ORDER_LIMIT: raise (RuntimeError, 'Even with ' + str(ORDER_LIMIT + 1) + ' points, an error in the mean of ' + str(1e-4) + 'cannot be obtained.') if quadrature_order_output is True: return integral, quadrature_order else: return integral
def set_model(self, model=None, model_grads=None): """ Computes the coefficients of transformed polynomial (equivalent to calling ``self.get_transformed_poly().set_model(...)``) Parameters ---------- model : ~collections.abc.Callable,numpy.ndarray, optional The function that needs to be approximated. In the absence of a callable function, the input can be the function evaluated at the quadrature points. model_grads : ~collections.abc.Callable,numpy.ndarray, optional The gradient of the function that needs to be approximated. In the absence of a callable gradient function, the input can be a matrix of gradient evaluations at the quadrature points. """ # Need to account for the nataf transform here? model_values = None model_grads_values = None if callable(model): model_values = evaluate_model(self._points, model) else: model_values = model if model_grads is not None: if callable(model_grads): model_grads_values = evaluate_model_gradients(self._points, model_grads) else: model_grads_values = model_grads self.corrected_poly.set_model(model_values, model_grads_values)