Skip to content

Variance Function

The variance function computes the variance of a window. When combined with the SlidingWindow abstraction, the variance function can be used to compute the var feature of a time series. The variance is defined as:

\[ \sigma^2 = \frac{1}{n} \sum_{i=1}^{n} (x_i - \mu)^2 \]

where \(x_i\) is the \(i\)-th element of the window, \(n\) is the number of elements in the window, and \(\mu\) is the mean of the window.

Compute the variance of the values in x.

Parameters:

Name Type Description Default
x ndarray

The array to compute the variance of.

required
ddof Union[int, int_]

The delta degrees of freedom. Default is 0. See numpy.var for more information.

0
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 variance of the values 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.var_tf)

# Get features
features = featurizer(x)

# Print features
print(features)

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