def integration_rule(self): ''' Return the integration rule associated with the measure Returns ------- tensap.IntegrationRule The integration rule associated with the measure ''' return tensap.IntegrationRule(self.values, self.weights)
def integration_rule(self): ''' Return the integration rule object associated with the discrete random variable. Returns ------- tensap.IntegrationRule The integration rule object associated with the discrete random variable. ''' return tensap.IntegrationRule(self.values, self.probabilities)
def gauss_integration_rule(self, nb_pts): ''' Return the nb_pts-points gauss integration rule associated with the measure of self, using Golub-Welsch algorithm. Parameters ---------- nb_pts : int The number of integration points. Returns ------- tensap.IntegrationRule The integration rule associated with the measure of self. ''' poly = self.orthonormal_polynomials(nb_pts + 1) if isinstance(poly, tensap.ShiftedOrthonormalPolynomials): shift = poly.shift scaling = poly.scaling poly = poly.polynomials flag = True else: flag = False coef = poly._recurrence_coefficients if coef.shape[1] < nb_pts: coef = poly.recurrence(poly.measure, nb_pts - 1) else: coef = coef[:, :nb_pts] # Jacobi matrix if nb_pts == 1: jacobi_matrix = np.diag(coef[0, :]) else: jacobi_matrix = np.diag(coef[0, :]) + \ np.diag(np.sqrt(coef[1, 1:]), -1) + \ np.diag(np.sqrt(coef[1, 1:]), 1) # Quadrature points are the eigenvalues of the Jacobi matrix, weights # are deduced from the eigenvectors eig_values, eig_vectors = np.linalg.eig(jacobi_matrix) points = np.sort(eig_values) ind = np.argsort(eig_values) eig_vectors = eig_vectors[:, ind] weights = eig_vectors[0, :]**2 / np.sqrt(np.sum(eig_vectors**2, 0)) if flag: points = shift + scaling * points return tensap.IntegrationRule(points, weights)