generators.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:tslearn 作者: rtavenar 项目源码 文件源码
def random_walk_blobs(n_ts_per_blob=100, sz=256, d=1, n_blobs=2, noise_level=1., random_state=None):
    """Blob-based random walk time series generator.

    Generate n_ts_per_blobs * n_blobs time series of size sz and dimensionality d.
    Generated time series follow the model:
    $$ts[t] = ts[t - 1] + a$$
    where :math:`a` is drawn from a normal distribution of mean mu and standard deviation std.

    Each blob contains time series derived from a same seed time series with added white noise.

    Parameters
    ----------
    n_ts_per_blob : int (default: 100)
        Number of time series in each blob
    sz : int (default: 256)
        Length of time series (number of time instants)
    d : int (default: 1)
        Dimensionality of time series
    n_blobs : int (default: 2)
        Number of blobs
    noise_level : float (default: 1.)
        Standard deviation of white noise added to time series in each blob
    random_state : integer or numpy.RandomState or None (default: None)
        Generator used to draw the time series. If an integer is given, it fixes the seed. Defaults to the global
        numpy random number generator.

    Returns
    -------
    numpy.ndarray
        A dataset of random walk time series

    Examples
    --------
    >>> X, y = random_walk_blobs(n_ts_per_blob=100, sz=256, d=5, n_blobs=3)
    >>> X.shape
    (300, 256, 5)
    >>> y.shape
    (300,)
    """
    rs = check_random_state(random_state)
    base_ts = random_walks(n_ts=n_blobs, sz=sz, d=d, std=1.0, random_state=rs)
    rnd = rs.randn(n_ts_per_blob * n_blobs, sz, d) * noise_level
    ts = numpy.repeat(base_ts, repeats=n_ts_per_blob, axis=0)
    y = numpy.repeat(range(n_blobs), repeats=n_ts_per_blob)
    return ts + rnd, y
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号