generators.py 文件源码

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

项目:tslearn 作者: rtavenar 项目源码 文件源码
def random_walks(n_ts=100, sz=256, d=1, mu=0., std=1., random_state=None):
    """Random walk time series generator.

    Generate n_ts 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.

    Parameters
    ----------
    n_ts : int (default: 100)
        Number of time series.
    sz : int (default: 256)
        Length of time series (number of time instants).
    d : int (default: 1)
        Dimensionality of time series.
    mu : float (default: 0.)
        Mean of the normal distribution from which random walk steps are drawn.
    std : float (default: 1.)
        Standard deviation of the normal distribution from which random walk steps are drawn.
    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
    --------
    >>> random_walks(n_ts=100, sz=256, d=5, mu=0., std=1.).shape
    (100, 256, 5)
    """
    rs = check_random_state(random_state)
    ts = numpy.empty((n_ts, sz, d))
    rnd = rs.randn(n_ts, sz, d) * std + mu
    ts[:, 0, :] = rnd[:, 0, :]
    for t in range(1, sz):
        ts[:, t, :] = ts[:, t - 1, :] + rnd[:, t, :]
    return ts
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号