postprocessor.core.processes.autoreg.autoreg

class autoreg(parameters)[source]

Bases: PostProcessABC

Process to estimate power spectral density (autoregressive model).

Attributes
parameters

Methods

fit_autoreg(timeseries: array_like, ar_order: int)

Computes linear algebra parameters used to fit an autoregressive model to a time series

optimise_ar_order(timeseries: array_like, ar_order_upper_limit: int)

Optimise autoregressive model order to fit a time series

autoreg_periodogram(timeseries: array_like, sampling_period: float,

freq_npoints: int, ar_order: int) Estimates the closed-form solution of the sample power spectrum of a timeseries, based on fitting an autoregressive model.

run(signal: pd.DataFrame)

Estimates the power spectral densities of a dataframe of time series, using autoregressive model

Attributes
parameters

Methods

autoreg_periodogram(timeseries, ...)

Estimates the power spectrum of a timeseries, based on an AR model

fit_autoreg(timeseries, ar_order)

Computes linear algebra parameters to fit an AR model to a timeseries

optimise_ar_order(timeseries, ...)

Optimise autoregressive model order to fit a time series

run(signal)

Estimates the power spectra of a dataframe of time series, using AR

as_function

default_parameters

__init__(parameters)[source]

Methods

__init__(parameters)

as_function(data, *extra_data, **kwargs)

autoreg_periodogram(timeseries, ...)

Estimates the power spectrum of a timeseries, based on an AR model

default_parameters(*args, **kwargs)

fit_autoreg(timeseries, ar_order)

Computes linear algebra parameters to fit an AR model to a timeseries

optimise_ar_order(timeseries, ...)

Optimise autoregressive model order to fit a time series

run(signal)

Estimates the power spectra of a dataframe of time series, using AR

Attributes

parameters

autoreg_periodogram(timeseries, sampling_period, freq_npoints, ar_order)[source]

Estimates the power spectrum of a timeseries, based on an AR model

Estimates the closed-form solution of the sample power spectrum of a time series. This estimation is based on fitting an autoregressive model of an optimised order to the time series, and using computed linear algebra parameters to compute the closed-form solution.

This implementation is based on the supplementary information of: * Jia & Grima (2020). BioRxiv [https://doi.org/10.1101/2020.09.23.309724]

Parameters

timeseriesarray_like

Time series of measurement values.

sampling_periodfloat

Sampling period of measurement values, in unit time.

freq_npointsint

Number of points for the frequency axis of the closed-form solution of the estimated periodogram. Defines the resolution for use in, for example, plots.

ar_orderint

Order of the autoregressive model. The order defines the complexity of the model; if the order is P, then each time point is modelled as a linear combination of P time points preceding it.

Returns
freqs: ndarray

Array of sample frequencies, unit time-1.

power: ndarray

Power spectral density or power spectrum of the time series, arbitrary units.

Examples

FIXME: Add docs.

fit_autoreg(timeseries, ar_order)[source]

Computes linear algebra parameters to fit an AR model to a timeseries

Computes linear algebra parameters used to fit an autoregressive model of a specified order to a time series. Ultimately computes the Akaike information criterion of the model with the specified order.

This model-fitting implementation is based on the supplementary information of: * Jia & Grima (2020). BioRxiv [https://doi.org/10.1101/2020.09.23.309724]

Parameters
timeseriesarray_like

Time series of measurement values.

ar_orderint

Order of the autoregressive model. The order defines the complexity of the model; if the order is P, then each time point is modelled as a linear combination of P time points preceding it.

Returns
This function returns a dictionary, whose values are defined by these
keys:
sample_acfs1d array of floats

Sample autocorrelation function; element indices go from 0 to ar_order.

ar_coeffs1d array of floats

Coefficients for the autoregressive model; defines the linear combination that defines the model.

noise_paramfloat

Noise parameter.

aicfloat

Akaike information criterion of the autoregressive model.

rtype

dict ..

optimise_ar_order(timeseries, ar_order_upper_limit)[source]

Optimise autoregressive model order to fit a time series

Optimise the autoregressive model order to fit a time series. Model selection relies on minimising the Akaike information criterion, sweeping over a range of possible orders.

This implementation is based on the supplementary information of: * Jia & Grima (2020). BioRxiv [https://doi.org/10.1101/2020.09.23.309724]

Parameters
timeseriesarray_like

Time series of measurement values.

ar_order_upper_limitint

Upper bound for autoregressive model order; recommended to be the square root of the length of the time series.

Returns
int

Optimal order for an autoregressive model that fits the time series.

rtype

int ..

run(signal)[source]

Estimates the power spectra of a dataframe of time series, using AR

Estimates the power spectral densities of a dataframe of time series. This estimation is based on fitting an autoregressive model of an optimised order to the time series, and using computed linear algebra parameters to compute the closed-form solution.

This implementation is based on the supplementary information of: * Jia & Grima (2020). BioRxiv [https://doi.org/10.1101/2020.09.23.309724]

Parameters
signal: pandas.DataFrame

Time series, with rows indicating individiual time series (e.g. from each cell), and columns indicating time points.

Returns
freqs_df: pandas.DataFrame

Sample frequencies from each time series, with labels preserved from ‘signal’.

power_df: pandas.DataFrame

Power spectrum from each time series, with labels preserved from ‘signal’.

order_df: pandas.DataFrame

Optimised order of the autoregressive model fitted to each time series, with labels preserved from ‘signal’.

Examples

FIXME: Add docs.