number_crossings#
- skfda.preprocessing.feature_construction.number_crossings(fd, *, levels=0, direction='all')[source]#
Calculate the number of crossings to a level of a FDataGrid.
Let f_1(X) = N_i, where N_i is the number of up crossings of X to a level c_i in mathbb{R}, i = 1,dots,p.
Recall that the process X(t) is said to have an up crossing of c at \(t_0 > 0\) if for some \(\epsilon >0\), X(t) $leq$ c if t :math:’in (t_0 - epsilon, t_0) and X(t) $geq$ c if \(t\in (t_0, t_0+\epsilon)\).
If the trajectories are differentiable, then \(N_i = card\{t \in[a,b]: X(t) = c_i, X' (t) > 0\}.\)
- Args:
- fd: FDataGrid where we want to calculate
the number of up crossings.
- levels: Sequence of numbers including the levels
we want to consider for the crossings. By default it calculates zero-crossings.
- direction: Whether to consider only up-crossings,
down-crossings or both.
- Returns:
ndarray of shape (n_samples, len(levels))with the values of the counters.
Examples
For this example we will use a well known function so the correct functioning of this method can be checked. We will create and use a DataFrame with a sample extracted from the Bessel Function of first type and order 0. First of all we import the Bessel Function and create the X axis data grid. Then we create the FdataGrid.
>>> from skfda.preprocessing.feature_construction import ( ... number_crossings, ... ) >>> from scipy.special import jv >>> import numpy as np >>> x_grid = np.linspace(0, 14, 14) >>> fd_grid = FDataGrid( ... data_matrix=[jv([0], x_grid)], ... grid_points=x_grid, ... ) >>> fd_grid.data_matrix array([[[ 1. ], [ 0.73041066], [ 0.13616752], [-0.32803875], [-0.35967936], [-0.04652559], [ 0.25396879], [ 0.26095573], [ 0.01042895], [-0.22089135], [-0.2074856 ], [ 0.0126612 ], [ 0.20089319], [ 0.17107348]]])
Finally we evaluate the number of up crossings method with the FDataGrid created.
>>> number_crossings(fd_grid, levels=0, direction="up") array([[2]])