Skip to content

Linear

timecave.data_generation.time_series_functions.linear_ts(number_samples, max_interval_size, slope=1, intercept=0)

Generate a linear time series array.

This function creates a time series array of given length where the values follow a linear pattern determined by the slope and intercept parameters.

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
slope float

The slope of the linear pattern.

1
intercept float

The intercept of the linear pattern.

0

Returns:

Type Description
ndarray

A time series array following a linear pattern determined by the slope and intercept parameters.

Examples:

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

linear

Source code in timecave/data_generation/time_series_functions.py
def linear_ts(
    number_samples: int,
    max_interval_size: float,
    slope: float = 1,
    intercept: float = 0,
) -> np.ndarray:
    """
    Generate a linear time series array.

    This function creates a time series array of given length where the values
    follow a linear pattern determined by the slope and intercept parameters.

    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.

    slope : float, default=1
        The slope of the linear pattern.

    intercept : float, default=0
        The intercept of the linear pattern.

    Returns
    -------
    np.ndarray
        A time series array following a linear pattern determined by the slope and intercept parameters.

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

    ![linear](../../../images/Linear.png)
    """
    _check_number_samples(number_samples)
    time = np.linspace(0, max_interval_size, number_samples)
    linear_series = slope * time + intercept
    return linear_series