File size: 743 Bytes
5111d13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from __future__ import annotations

import numpy as np
import torch


def multiscale_batch(batch: int, length: int, seed: int) -> torch.Tensor:
    rng = np.random.default_rng(seed)
    time = np.arange(length, dtype=np.float32)[None]
    values = np.zeros((batch, length), dtype=np.float32)
    for low, high, scale in [(6, 12, 0.45), (20, 40, 0.35), (70, 110, 0.55)]:
        periods = rng.uniform(low, high, size=(batch, 1))
        phases = rng.uniform(0, 2 * np.pi, size=(batch, 1))
        amplitudes = rng.uniform(0.5, 1.0, size=(batch, 1)) * scale
        values += amplitudes * np.sin(2 * np.pi * time / periods + phases)
    values += rng.normal(0, 0.015, size=values.shape)
    return torch.from_numpy(values).float().unsqueeze(2)