diff --git a/Basis_Function.py b/Basis_Function.py index e5b726eee9b2afee7e95637c03bc5994983014c7..0630198c0d29f1a61d124f31d5c6439fc6340f19 100644 --- a/Basis_Function.py +++ b/Basis_Function.py @@ -13,35 +13,121 @@ z = Symbol('z') class Vector(object): + """Class for basis vector. + + Attributes + ---------- + basis : np.array + Array of basis. + wavelet : np.array + Array of wavelet. + + Methods + ------- + get_basis_vector() + Returns basis vector. + get_wavelet_vector + Returns wavelet vector. + get_basis_projections() + Returns basis projections. + get_wavelet_projections() + Returns wavelet projections. + + """ def __init__(self, polynomial_degree): + """Initializes Vector. + + Parameters + ---------- + polynomial_degree : int + Polynomial degree. + + """ self._polynomial_degree = polynomial_degree self._basis = self._build_basis_vector(x) self._wavelet = self._build_wavelet_vector(z) def get_basis_vector(self): + """Returns basis vector.""" return self._basis def _build_basis_vector(self, eval_point): + """Constructs basis vector. + + Parameters + ---------- + eval_point : float + Evaluation point. + + Returns + ------- + np.array + Vector containing basis evaluated at evaluation point. + + """ return [] def get_wavelet_vector(self): + """Returns wavelet vector.""" return self._wavelet def _build_wavelet_vector(self, eval_point): + """Constructs wavelet vector. + + Parameters + ---------- + eval_point : float + Evaluation point. + + Returns + ------- + np.array + Vector containing wavelet evaluated at evaluation point. + + """ return [] def get_basis_projections(self): + """Returns basis projection.""" pass def get_multiwavelet_projections(self): + """Returns wavelet projection.""" pass class Legendre(Vector): + """Class for Legendre basis.""" def _build_basis_vector(self, eval_point): + """Constructs basis vector. + + Parameters + ---------- + eval_point : float + Evaluation point. + + Returns + ------- + np.array + Vector containing basis evaluated at evaluation point. + + """ return self._calculate_legendre_vector(eval_point) def _calculate_legendre_vector(self, eval_point): + """Constructs Legendre vector. + + Parameters + ---------- + eval_point : float + Evaluation point. + + Returns + ------- + np.array + Vector containing Legendre polynomial evaluated at evaluation point. + + """ vector = [] for degree in range(self._polynomial_degree+1): if degree == 0: @@ -57,12 +143,52 @@ class Legendre(Vector): class OrthonormalLegendre(Legendre): + """Class for orthonormal Legendre basis. + + Methods + ------- + get_basis_projection() + Returns basis projection. + get_wavelet_projection() + Returns wavelet projection. + + """ def _build_basis_vector(self, eval_point): + """Constructs basis vector. + + Parameters + ---------- + eval_point : float + Evaluation point. + + Returns + ------- + np.array + Vector containing basis evaluated at evaluation point. + + """ leg_vector = self._calculate_legendre_vector(eval_point) return [leg_vector[degree] * np.sqrt(degree+0.5) for degree in range(self._polynomial_degree+1)] def _build_wavelet_vector(self, eval_point): + """Constructs wavelet vector. + + Parameters + ---------- + eval_point : float + Evaluation point. + + Returns + ------- + np.array + Vector containing wavelet evaluated at evaluation point. + + Notes + ----- + Hardcoded version only for now. + + """ degree = self._polynomial_degree if degree == 0: @@ -97,11 +223,35 @@ class OrthonormalLegendre(Legendre): up to degree 4 for this application') def get_basis_projections(self): + """Returns basis projection. + + Returns + ------- + np.array + Array containing the basis projection based on the integrals of the product + of two basis vectors for each degree combination. + + """ basis_projection_left = self._build_basis_matrix(z, 0.5 * (z - 1)) basis_projection_right = self._build_basis_matrix(z, 0.5 * (z + 1)) return basis_projection_left, basis_projection_right def _build_basis_matrix(self, first_param, second_param): + """Constructs a basis matrix. + + Parameters + ---------- + first_param : float + First parameter. + second_param : float + Second parameter. + + Returns + ------- + np.array + Matrix containing the integral of basis products. + + """ matrix = [] for i in range(self._polynomial_degree + 1): row = [] @@ -114,11 +264,37 @@ class OrthonormalLegendre(Legendre): return matrix def get_multiwavelet_projections(self): + """Returns wavelet projection. + + Returns + ------- + np.array + Array containing the multiwavelet projection based on the integrals of the product + of a basis vector and a wavelet vector for each degree combination. + + """ wavelet_projection_left = self._build_multiwavelet_matrix(z, -0.5*(z-1), True) wavelet_projection_right = self._build_multiwavelet_matrix(z, 0.5*(z+1), False) return wavelet_projection_left, wavelet_projection_right def _build_multiwavelet_matrix(self, first_param, second_param, is_left_matrix): + """Constructs a multiwavelet matrix. + + Parameters + ---------- + first_param : float + First parameter. + second_param : float + Second parameter. + is_left_matrix : boolean + Flag whether the left matrix is calculated. + + Returns + ------- + np.array + Matrix containing the integral of products of a basis and a wavelet vector. + + """ matrix = [] for i in range(self._polynomial_degree+1): row = []