Download source/data.py from ARotting/clockwork-rnn-pocket: direct link, hf CLI and curl.
- Browser
- Download file 743 Bytes
-
https://huggingface.co/ARotting/clockwork-rnn-pocket/resolve/main/source/data.py
- Command line
-
hf download hf://ARotting/clockwork-rnn-pocket/source/data.py
-
curl -L -o data.py https://huggingface.co/ARotting/clockwork-rnn-pocket/resolve/main/source/data.py
743 Bytes
| 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) | |