nemos.basis.MSplineConv.evaluate_on_grid#
- MSplineConv.evaluate_on_grid(n_samples)[source]#
Evaluate the M-spline basis functions on a uniformly spaced grid.
This method creates a uniformly spaced grid of sample points within the domain [0, 1] and evaluates all the M-spline basis functions at these points. It is particularly useful for visualizing the shape and distribution of the basis functions across their domain.
- Parameters:
n_samples (
int
) – The number of points in the uniformly spaced grid. A higher number of samples will result in a more detailed visualization of the basis functions.- Return type:
Tuple
[NDArray, NDArray]- Returns:
X (NDArray) – A 1D array of uniformly spaced sample points within the domain [0, 1]. Shape:
(n_samples,)
.Y (NDArray) – A 2D array where each row corresponds to the evaluated M-spline basis function values at the points in X. Shape:
(n_samples, n_basis_funcs)
.
Examples
Evaluate and visualize 4 M-spline basis functions of order 3:
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from nemos.basis import MSplineConv >>> mspline_basis = MSplineConv(n_basis_funcs=4, order=3, window_size=10) >>> sample_points, basis_values = mspline_basis.evaluate_on_grid(100) >>> for i in range(4): ... p = plt.plot(sample_points, basis_values[:, i], label=f'Function {i+1}') >>> plt.title('M-Spline Basis Functions') Text(0.5, 1.0, 'M-Spline Basis Functions') >>> plt.xlabel('Domain') Text(0.5, 0, 'Domain') >>> plt.ylabel('Basis Function Value') Text(0, 0.5, 'Basis Function Value') >>> l = plt.legend()