Skip to content

Exponential

timecave.data_generation.time_series_functions.exponential_ts(number_samples, max_interval_size, decay_rate=1, initial_value=1)

Generates a time series based on a exponential function.

This function creates a time series array of given length where the values decay exponentially over time based on the specified decay rate and initial value.

Parameters:

Name Type Description Default
number_samples int

The total number of samples in the time series array.

required
max_interval_size float

The maximum interval size for generating the time series array.

required
decay_rate float

The rate at which the values decay over time.

1
initial_value float

The initial value of the time series array.

1

Returns:

Type Description
ndarray

An exponential decay time series array where values decay exponentially over time based on the specified decay rate and initial value.

Examples:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from timecave.data_generation.time_series_functions import exponential_ts
>>> ts = exponential_ts(1000, 10, initial_value=10);
>>> _ = plt.plot(np.arange(0, ts.shape[0]), ts);
>>> plt.show();

exponential

Source code in timecave/data_generation/time_series_functions.py
def exponential_ts(
    number_samples: int,
    max_interval_size: float,
    decay_rate: float = 1,
    initial_value: float = 1,
) -> np.ndarray:
    """
    Generates a time series based on a exponential function.

    This function creates a time series array of given length where the values
    decay exponentially over time based on the specified decay rate and initial value.

    Parameters
    ----------
    number_samples : int
        The total number of samples in the time series array.

    max_interval_size : float
        The maximum interval size for generating the time series array.

    decay_rate : float, default=1
        The rate at which the values decay over time.

    initial_value : float, default=1
        The initial value of the time series array.

    Returns
    -------
    np.ndarray
        An exponential decay time series array where values decay exponentially over time based on the specified decay rate and initial value.

    Examples
    --------
    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from timecave.data_generation.time_series_functions import exponential_ts
    >>> ts = exponential_ts(1000, 10, initial_value=10);
    >>> _ = plt.plot(np.arange(0, ts.shape[0]), ts);
    >>> plt.show();

    ![exponential](../../../images/Exponential.png)
    """
    _check_number_samples(number_samples)
    time = np.linspace(0, max_interval_size, number_samples)
    exponential_series = initial_value * np.exp(-decay_rate * time)
    return exponential_series