Skip to content

N-Valid Function

Compute the number of valid measurements in a sliding window. A valid measurement by default is defined as a measurement that is not np.nan, however this can be altered by passing a validity function to the argument where. The validity function should take a single argument, the measurement, and return True if the measurement is valid, and False otherwise. The function can be defined as:

\[ \mathbb{1}_{\text{valid}}(x_i) = \begin{cases} 1 & \text{if } x_i \text{ is valid} \\ 0 & \text{otherwise} \end{cases} \]

where \(x_i\) is the \(i\)-th measurement in the sliding window.

\[ \text{NValid} = \sum_{i=1}^n \mathbb{1}_{\text{valid}}(x_i) \]

where \(n\) is the number of measurements in the sliding window.

Compute the number of valid measurements in x where where is True for valid measurements.

Parameters:

Name Type Description Default
x ndarray

The array to compute the number of valid measurements in.

required
where Callable[[Union[int, float, int_, float_]], Union[bool, bool_]]

A function that takes a value and returns True or False. Default is lambda x: not np.isnan(x) i.e. a measurement is valid if it is not a NaN value.

lambda : not numpy.isnan(x)

Returns:

Type Description
Union[float, float_]

The number of valid measurements in x.

Examples

import numpy as np
import autonfeat as aft
import autonfeat.functional as F

# Random data
n_samples = 100
x = np.random.rand(n_samples)

# Create sliding window
ws = 10
ss = 10
window = aft.SlidingWindow(window_size=ws, step_size=ss)

# Get featurizer
featurizer = window.use(F.n_valid_tf)

# Get features
features = featurizer(x)

# Print features
print(features)

If you enjoy using AutonFeat, please consider starring the repository ⭐️.