Class definitions

This module contains the definitions of the objects used to represent function spaces and functions, in both one- and multi-dimensional form. A few methods to operate on tensors as equivalent one-dimensional arrays are also included.

Todo

Knot optimization for B-spline approximations is not supported yet.

Todo

Chebyshev multi-dimensional representations are not provided and should be implemented in the FORTRAN library. This development is postponed, as it hasn’t been needed so far.

Todo

Conversion from B-spline form to PP form in case of multi-dimensional representation is currently not supported.

class pppack.Fd(*args, **kwargs)

Bases: list

Class representing the space \(Fd \in \mathbb{R}\) of real-valued functions defined on a d-dimensional domain obtained by Cartisian products as \(V^{(d)} = V_{1}\times \ldots \times V_{d}\), with \(V_i \in \mathbb{R}\, \forall i\).

Fd is also defined by the tensor product of one-dimensional function space \(F_i(V_i)\).

__init__(*args, **kwargs)

Init a multivariate function space as a list of univariate function spaces. Uniqueness of the components of a Fd instance is ensured.

dims

Return the dimension of the multivariate space.

a
b
class pppack.PP(k, xi, nu=None, name='')

Bases: pppack.Fd

Class representing a Piecewise Polynomial function space of polynomial order \(k\), breakpoints \(\vec{\xi}\) and continuities of derivativies \(\vec{\nu}\), \(PP_{k,\vec{\xi}(,\vec{\nu})}\). Simple polynomial space \(P_k \subseteq PP_{k,\xi}\), with equality in case of \(\xi = [a,b]\). In this case, the data points \(\tau\) are expected in \([a,b]\).

Example:
>>> P0 = PP(4,[-1., 0., .5, 1.])
>>> print P0
PP_{ k=4, xi, nu }, with
 xi = [-1.000,0.000,0.500,1.000],  nu = [-,3,3,-]
__init__(k, xi, nu=None, name='')

Init \(PP_{k,\xi[,\nu]}\), with default \(\nu_i=k-1, \,\forall i\) (inside breakpoints) if \(\nu=\mbox{None}\).

l
a
b
PP2S()
Get \(S_{k,t}\) by the theorem of Curry and Schoenberg (1966)
\(S_{k,t} = PP_{k,\vec{\xi},\vec{\nu}} \mbox{ on } [t_k, t_{n+1}]\).
cmpPPtau()

Compute the data points from \(P_{k,\vec{\xi},\vec{\nu}}\) (osculatory interpolation as default).

cmptau()

General interface, here alias to cmpPPtau.

class pppack.S(k, t, name='')

Bases: pppack.Fd

Class representing the function space populated by Bsplines of polynomial order k and knot sequence \(\vec{t}\).

Example:
>>> S0 = S(4,[1., 1., 2., 3., 4., 4.])
>>> print S0
S_{ k=4, t }, with
 t = [1.000,1.000,2.000,3.000,4.000,4.000]
__init__(k, t, name='')

Initialize \(S(k,\vec{t})\).

n
a
b
tstar

Compute the Greville control points \(t^*\).

tau4Ik(k_is_even=True)

Even order interpolation at knots, say \(k=2m\), reproducing \(I_k\), that is spline interpolation of order k with the not-a-knot end condition.

cmptau()

General interface, here alias to tau4Ik.

class pppack.fd(*args, **kwargs)

Bases: pppack.Fd

Class representing a multivariate function f in Fd as \(f: V^{(d)} \rightarrow F^{(d)} \ in \mathbb{R}\), with \(V^{(d)} = V_1 \times \ldots \times V_d\), \(V_i \in \mathbb{R},\, \forall i\) and \(F^{(d)} = F_1(V_1) \times \ldots \times F_d(V_d)\). In virtue of the Cartesian compositions and provided that one-dimensional basis functions :math:` mathcal{B}(F_i)={psi_i,, i=1,ldots}` are available, it is:

\[\begin{split}f&= \sum_{i_1} C_{i_1} \psi_{i_1}(x_{i_1}) \times \ldots \times \sum_{i_d} C_{i_d} \psi_{i_d}(x_{i_d}) \\ &= f_{i_1} \times \ldots \times f_{i_d} = \sum_{\vec{i}} C_{\vec{i}} \psi_{\vec{i}}, \mbox{ with } \vec{i}=[i_1, \ldots, i_d] \forall i_j.\end{split}\]

The coefficients \(C_{\vec{i}}\) are d-dimensional FORTRAN array, stored as equivalent one-dimensional array:

\[C_{\vec{i}} = C(i_1 + n_1(i_2 - 1 + n_2(i_3 - 1 + \ldots + n_{d-1}(i_d - 1) \ldots ))).\]

The C version with zero-based numbering is:

\[C_{\vec{i}} = C(i_1 + n_1(i_2 + n_2(i_3 + \ldots + n_{d-1}(i_d) \ldots ))).\]

The approximant function f to g is determined by applying the linear functional \(\lambda_{\vec{j}}\) to g, and so to \(\psi_{\vec{i}}\). The inversion of the associated directional Gramian matrices is provided by the specific class to which the function \(f_{i_j}\) belongs. Currently, only \(\lambda_{j}g_j = [\tau_j]g(x_j,\dot)\) is available in the module.

\(C_{\vec{i}}\) and \(g_{\vec{i}}\) (gtau in the following) are equivalent one-dimensional FORTRAN arrays, whereas data points follow as lists \((\tau_{i_j}, i_j=1,I_j,\; \forall j)\).

Note

(tau, gtau) is to be considered as private to ensure the correspondence with the fitting coefficients C.

coef = None
tau
gtau
classmethod inFd(Fdin)

Init from the space Fd to which the function belongs.

cmpcoef(tau, gtau)

Compute the tensor coefficients of the d-dimensional function fd, with input values \(gtau=fd(x_\vec{j})\) as one-dimensional FORTRAN array and data points tau in a list as \([ [x_{j_i=1}^{J_i}], \forall j_i ]\). The caller must ensure the correspondence between the d-tuples x with the gtau values according to the definition of the equivalent one-dimensional array.

The output array of an inner product applies an index shift w.r.t. the input array, according to De Boor’s intuition, thus always performing efficient operations on contiguous data in memory [3]. Methods for vectorize and matricize are here needed because the C-wrapper f2py breaks the useful internal FORTRAN array management. This drawback will hopefully be removed in future versions, after f2py upgrading.

__call__(x, j=0)

Evaluate \(D^j f^{(d)}\) at \(\vec{x}=[x_1, \ldots, x_d]\).

class pppack.pp(k, xi, nu=None, name='')

Bases: pppack.fd, pppack.PP

Class representing a functional element pp in PP as:

\[f(x) = \sum_{j=1}^k C_{j,i} P_{j,i}(x), \mbox{ with }\xi_i \le x < \xi_{i+1}\]

The function and its derivatives are represented (and evaluated) as (de Boor 1987, ch. 7 pp. 89):

\[D^j f(x) = \sum_{m=j}^{k-1} C_{m+1,i}(x-\xi_i)^{m-j} / (m-j)!\]

where either

\[\begin{split}\begin{align*} i = 1 \mbox{ and }&~~~~~~~~ x < \xi_2,\mbox{ or} \\ 1<i<l \mbox{ and }&\xi_i \leq x < \xi_{i+1},\mbox{ or}\\ i = l \mbox{ and }&\xi_l \leq x. \end{align*}\end{split}\]

Note

(tau, gtau) is to be considered as private to ensure the correspondence with the fitting coefficients.

basefncs = None
classmethod inPP(Pkxi)

init from the space PP the function belongs to.

cmpcoef(tau=None, gtau=None, dgtau1=0.0, dgtauN=0.0, ibcbeg=0, ibcend=0, method='newton')

Compute the coefficients of the piecewise polynomial stored in coef. Available methods are:

  • CUBSPL for cubic splines + b.c. (see below),
  • NEWTON for simple polynomials in Newton form by divided differences (default by method input arg in case of \(P_k\)) or CHEBYSHEV polynomial interpolation.

Output are the fitting coefficients, -> coef(k,L=N-1). ibcbeg/ibcend:

  1. no b.c., so use the not-a-knot condition (\(jump D^3f(\xi_1)=0\))
  2. complete cubspl with \(f'(\tau_1)=\mbox{coef(2,1)}\)
  3. \(f''(\tau_1)=\mbox{coef(2,1)}\) for natural condition

(replace \(\tau_1\) with \(\tau_N\) above for the corresponding b.c. of ibcend in the input dgtau1/N).

Note

Input derivatives are expected in dgtau1/N. They will be inserted in coef (a.k.a. C in the fortran subroutine CUBSPL).

Note

The ‘private’ (tau, gtau) couple is stored after the calculation of the fitting coefficients.

pp2s(tau=None, gtau=None)

Converts from piecewise polynomial to B-spline form. Data points follow by default the even order interpolation at knots to build the interpolant \(I_k(g)\).

__call__(x, j=0)

Evaluate \(D^j pp\) by PPVALU at \(x\).

class pppack.s(k, t, name='')

Bases: pppack.fd, pppack.S

Class representing a functional element s in S as:

\[f(x) = \sum_{i=1}^n \alpha_i B_{i,k,t}(x)\]

if \(t_j \leq x \leq t_{j+1}\) for some \(j \in [k,n]\), then by the compact support of B-splines it is

\[f(x) = \sum_{i=j-k+1}^j \alpha_i B_{i,k,t}(x).\]

Note

(tau, gtau) is to be considered as private to ensure the correspondence with the fitting coefficients.

classmethod inS(Skt)

Init from the space S to which the function belongs.

cmpcoef(tau, gtau, VDS=False)

Compute the coefficients of the spline of order K with knots t(1:n+k), which takes on the value gtau(i) at tau(i), for i = 1 to n. The i-th equation of the linear system A * BCOEF = B for the B-spline coefficients of the interpolant enforces interpolation at tau(1:n). Hence, B(i) = gtau(i), for all i, and A is a band matrix with 2*k-1 bands, if it is invertible.

If VDS==True, the Schoenberg’s Variational Diminishing Spline approximation is used (BCOEF(i) = gtau( tau_i^star ) for all i).

singularBij(tau)

Check non-singularity of the matrix \(B_i(\tau_j), i,j=1, \ldots,n\) by applying the theorem of Schoenberg and Whitney (1953).

s2pp()

Converts from B-spline to piecewise polynomial form.

__call__(x, j=0)

Evaluate \(D^j s\) by BVALUE at \(x\).

pppack.getidx(i, Ni)

Get the position of the tuple i in the equivalent one-dimensional vector. The list Ni contains the maximum values of the indices, which start all from 0.