Skip to content

Indicator function

timecave.data_generation.time_series_functions.indicator_ts(number_samples, start_index, end_index)

Generate time series array based on a binary indicator function with specified start and end indices.

This function creates a time series array based on a binary indicator function of given length. The specified segment is marked as 1 and the rest as 0.

Parameters:

Name Type Description Default
number_samples int

The total number of samples in the time series array.

required
start_index int

The start index of the segment to be marked as 1.

required
end_index int

The end index of the segment to be marked as 1.

required

Returns:

Type Description
ndarray

A time series array where the specified segment is marked as 1 and the rest as 0.

See also

scaled_right_indicator_ts: Scaled right indicator time series. Needs only a start index.

Examples:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from timecave.data_generation.time_series_functions import indicator_ts
>>> ts = indicator_ts(100, 20, 60);
>>> _ = plt.plot(np.arange(0, ts.shape[0]), ts);
>>> plt.show();

indicator

Source code in timecave/data_generation/time_series_functions.py
def indicator_ts(number_samples: int, start_index: int, end_index: int) -> np.ndarray:
    """
    Generate time series array based on a binary indicator function with specified start and end indices.

    This function creates a time series array based on a binary indicator function of given length. The specified segment is marked as 1 and the rest as 0.

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

    start_index : int
        The start index of the segment to be marked as 1.

    end_index : int
        The end index of the segment to be marked as 1.

    Returns
    -------
    np.ndarray
        A time series array where the specified segment is marked as 1 and the rest as 0.

    See also
    --------
    [scaled_right_indicator_ts](scaled_indicator.md): Scaled right indicator time series. Needs only a start index.

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

    ![indicator](../../../images/Indicator.png)
    """
    _check_number_samples(number_samples)
    _check_index(start_index)
    _check_index(end_index)
    indicator = np.zeros(number_samples)
    indicator[start_index : end_index + 1] = 1
    return indicator