Continuous TimeSeries

Using Continuous TimeSeries

If you have a list of InterPausalUnits with some feature of interest already calculated, you can create a TimeSeries object for such a feature. Here is an example that uses k-Nearest-Neighbors (kNN) regressor, as explained in Gálvez et al. (2020).

from entrainment_metrics.continuous import TimeSeries

time_series: TimeSeries = TimeSeries(
    interpausal_units=ipus,
    feature="FEATURE_CALCULATED",
    method='knn',
    k=8,
)

Once the TimeSeries object has been constructed, you can use it predict the feature value for specific time points (a float, or an np.ndarray), or for the points in a given interval (with a specified granularity degree).

import numpy as np

time_series_values: np.ndarray = time_series.predict_interval(
    start=0.5,
    end=44.4,
    granularity=0.0001,
)

another_time_series_values: np.ndarray = time_series.predict(
    np.arange(10, 20, 0.02)
)

Calculating Metrics

When you already have some TimeSeries is when fun starts. Now you are able to calculate some metrics over them. The metrics available are ‘proximity’, ‘convergence’, and ‘synchrony’. Calculating any of these metrics is as easy as running the following code:

from entrainment_metrics.continuous import calculate_metric
metric_result: float = calculate_metric(
    "synchrony",
    time_series_a,
    time_series_b,
)