Fourier#

class skfda.representation.basis.Fourier(domain_range=None, n_basis=3, period=None)[source]#

Fourier basis.

Defines a functional basis for representing functions on a fourier series expansion of period \(T\). The number of basis is always odd. If instantiated with an even number of basis, they will be incremented automatically by one.

\[\phi_0(t) = \frac{1}{\sqrt{2}}\]
\[\phi_{2n -1}(t) = \frac{sin\left(\frac{2 \pi n}{T} t\right)} {\sqrt{\frac{T}{2}}}\]
\[\phi_{2n}(t) = \frac{cos\left(\frac{2 \pi n}{T} t\right)} {\sqrt{\frac{T}{2}}}\]

This basis will be orthonormal if the period coincides with the length of the interval in which it is defined.

Deprecated since version 0.8: Use FourierBasis instead.

Parameters:
  • domain_range (Tuple[Tuple[float, float], ...] | Sequence[float] | Sequence[Sequence[float]] | None) – A tuple of length 2 containing the initial and end values of the interval over which the basis can be evaluated.

  • n_basis (int) – Number of functions in the basis.

  • period (float | None) – Period (\(T\)).

Examples

Constructs specifying number of basis, definition interval and period.

>>> fb = Fourier((0, np.pi), n_basis=3, period=1)
>>> fb([0, np.pi / 4, np.pi / 2, np.pi]).round(2)
array([[[ 1.  ],
        [ 1.  ],
        [ 1.  ],
        [ 1.  ]],
       [[ 0.  ],
        [-1.38],
        [-0.61],
        [ 1.1 ]],
       [[ 1.41],
        [ 0.31],
        [-1.28],
        [ 0.89]]])

And evaluate second derivative

>>> deriv2 = fb.derivative(order=2)
>>> deriv2([0, np.pi / 4, np.pi / 2, np.pi]).round(2)
array([[[  0.  ],
        [  0.  ],
        [  0.  ],
        [  0.  ]],
       [[  0.  ],
        [ 54.46],
        [ 24.02],
        [-43.37]],
       [[-55.83],
        [-12.32],
        [ 50.4 ],
        [-35.16]]])

Methods

coordinate_basis_and_coefs(coefs, key)

Return a fdatabasis for the coordinate functions indexed by key.

copy([domain_range])

Basis copy.

derivative(*[, order])

Construct a FDataBasis object containing the derivative.

derivative_basis_and_coefs(coefs[, order])

Return basis and coefficients of the derivative.

evaluate(eval_points, *[, derivative])

Evaluate Basis objects and its derivatives.

gram_matrix()

Return the Gram Matrix of a basis.

inner_product_matrix([other])

Return the Inner Product Matrix of a pair of basis.

is_domain_range_fixed()

Return wether the domain range has been set explicitly.

plot(*args, **kwargs)

Plot the basis object or its derivatives.

rescale([domain_range, rescale_period])

Return a copy of the basis with a new domain range.

to_basis()

Convert the Basis to FDatabasis.

coordinate_basis_and_coefs(coefs, key)[source]#

Return a fdatabasis for the coordinate functions indexed by key.

Parameters:
  • coefs (NDArrayFloat) –

  • key (int | slice) –

Return type:

Tuple[Basis, NDArrayFloat]

copy(domain_range=None)[source]#

Basis copy.

Parameters:
  • self (T) –

  • domain_range (DomainRangeLike | None) –

Return type:

T

derivative(*, order=1)[source]#

Construct a FDataBasis object containing the derivative.

Parameters:

order (int) – Order of the derivative. Defaults to 1.

Returns:

Derivative object.

Return type:

FDataBasis

derivative_basis_and_coefs(coefs, order=1)[source]#

Return basis and coefficients of the derivative.

Parameters:
  • coefs (ndarray[Any, dtype[float64]]) – Coefficients of a vector expressed in this basis.

  • order (int) – Order of the derivative.

  • self (T) –

Returns:

Tuple with the basis of the derivative and its coefficients.

Return type:

Tuple[T, ndarray[Any, dtype[float64]]]

evaluate(eval_points, *, derivative=0)[source]#

Evaluate Basis objects and its derivatives.

Evaluates the basis functions at a list of given values.

Deprecated since version 0.8: Use normal calling notation instead.

Parameters:
  • eval_points (ArrayLike) – List of points where the basis is evaluated.

  • derivative (int) –

    order of the derivative.

    Deprecated since version 0.4: Use derivative method instead.

Returns:

Matrix whose rows are the values of the each basis function or its derivatives at the values specified in eval_points.

Return type:

ndarray[Any, dtype[float64]]

gram_matrix()[source]#

Return the Gram Matrix of a basis.

The Gram Matrix is defined as

\[G_{ij} = \langle\phi_i, \phi_j\rangle\]

where \(\phi_i\) is the ith element of the basis. This is a symmetric matrix and positive-semidefinite.

Returns:

Gram Matrix of the basis.

Return type:

ndarray[Any, dtype[float64]]

inner_product_matrix(other=None)[source]#

Return the Inner Product Matrix of a pair of basis.

The Inner Product Matrix is defined as

\[I_{ij} = \langle\phi_i, \theta_j\rangle\]

where \(\phi_i\) is the ith element of the basis and \(\theta_j\) is the jth element of the second basis. This matrix helps on the calculation of the inner product between objects on two basis and for the change of basis.

Parameters:

other (Basis | None) – Basis to compute the inner product matrix. If not basis is given, it computes the matrix with itself returning the Gram Matrix

Returns:

Inner Product Matrix of two basis

Return type:

NDArrayFloat

is_domain_range_fixed()[source]#

Return wether the domain range has been set explicitly.

This is useful when using a basis for converting a dataset, since if this is not explicitly assigned it can be changed to the domain of the data.

Returns:

True if the domain range has been fixed. False otherwise.

Return type:

bool

plot(*args, **kwargs)[source]#

Plot the basis object or its derivatives.

Parameters:
  • args (Any) – arguments to be passed to the fdata.plot function.

  • kwargs (Any) – keyword arguments to be passed to the fdata.plot function.

Returns:

Figure object in which the graphs are plotted.

Return type:

Figure

rescale(domain_range=None, *, rescale_period=False)[source]#

Return a copy of the basis with a new domain range.

Parameters:
Returns:

Rescaled copy.

Return type:

T

to_basis()[source]#

Convert the Basis to FDatabasis.

Returns:

FDataBasis with this basis as its basis, and all basis functions as observations.

Return type:

FDataBasis

Examples using skfda.representation.basis.Fourier#

Basis representation

Basis representation