maths.autocorrelation ===================== .. py:module:: maths.autocorrelation .. autoapi-nested-parse:: Autocorrelation measures the correlation of a signal with a delayed copy of itself. It is widely used in time series analysis, signal processing, and statistics. Reference: https://en.wikipedia.org/wiki/Autocorrelation Attributes ---------- .. autoapisummary:: maths.autocorrelation.data Functions --------- .. autoapisummary:: maths.autocorrelation.autocorrelation Module Contents --------------- .. py:function:: autocorrelation(data: list[float], lag: int) -> float Calculate the autocorrelation of a time series at a given lag. :param data: A list of numerical values representing the time series. :param lag: The number of time steps to shift the series. :return: The autocorrelation coefficient at the given lag. >>> round(autocorrelation([1, 2, 3, 4, 5], 1), 4) 0.4 >>> round(autocorrelation([1, 2, 3, 4, 5], 0), 4) 1.0 >>> autocorrelation([1, 2, 3], 5) Traceback (most recent call last): ... ValueError: Lag must be less than the length of the data. .. py:data:: data :value: [1, 2, 3, 4, 5, 4, 3, 2, 1]