Fractional Brownian motion and related processes in PyTorch
Project description
torchfbm
Fractional Brownian motion (fBm) and fractional Gaussian noise (fGn) generators, layers, and processes in PyTorch.
Features
- Fast Davies–Harte and exact Cholesky fGn generators: see
torchfbm/generators.generate_davies_harteandtorchfbm/generators.generate_cholesky. - fBm paths via cumulative sum:
torchfbm/generators.fbm. - Fractional OU and Geometric fBm processes:
torchfbm/processes.fractional_ou_process,torchfbm/processes.geometric_fbm. - Noisy linear layer and positional embeddings using fBm:
torchfbm/layers.FBMNoisyLinear,torchfbm/layers.FractionalPositionalEmbedding. - Hurst exponent estimator:
torchfbm/estimators.estimate_hurst. - RL action noise stream:
torchfbm/rl.FBMActionNoise.
Install
- Editable install:
- In VS Code terminal:
pip install -e .
- In VS Code terminal:
Quick Usage
- Generate fBm (torch-only):
- Python:
import torchfrom torchfbm import fbm, get_default_device, set_seeddevice = get_default_device(); set_seed(42)path = fbm(n=1024, H=0.7, size=(4,), method='davies_harte', device=device, dtype=torch.float32)
- Python:
- Noisy Linear:
- Python:
from torchfbm import FBMNoisyLinearlayer = FBMNoisyLinear(32, 10, H=0.5, method='davies_harte', device=device, dtype=torch.float32, seed=123)x = torch.randn(8, 32, device=device)layer.train(); y1 = layer(x); y2 = layer(x)layer.eval(); y3 = layer(x)
- Python:
- Processes:
- Python:
from torchfbm import geometric_fbm, fractional_ou_processs = geometric_fbm(n=1000, H=0.7, mu=0.05, sigma=0.2, t_max=1.0, s0=100.0, device=device, dtype=torch.float32)x = fractional_ou_process(n=2048, H=0.6, theta=0.2, mu=0.0, sigma=0.5, dt=1/256, device=device, dtype=torch.float32)
- Python:
Hurst Estimation
from torchfbm import estimate_hurstH = estimate_hurst(path.unsqueeze(0), min_lag=4, max_lag=64, assume_path=True)
RL Action Noise
from torchfbm import FBMActionNoisenoise = FBMActionNoise(mean=0.0, sigma=0.2, H=0.7, size=(1,), buffer_size=10000, method='davies_harte', device=device, return_torch=True, dtype=torch.float32, seed=7)a = noise()
Notes
- Choose
method='davies_harte'for speed ($O(N \log N)$),choleskyfor validation ($O(N^3)$). His clamped to $[0.01, 0.99]$ for stability.- Set
dtypeandseedin generators for reproducibility. - Torch-only: examples avoid
.numpy()to work even if NumPy isn't available.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
torchfbm-0.1.0.tar.gz
(17.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
torchfbm-0.1.0-py3-none-any.whl
(20.1 kB
view details)
File details
Details for the file torchfbm-0.1.0.tar.gz.
File metadata
- Download URL: torchfbm-0.1.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6ca97bfa18f8d445b1817cb4f0c2a00bd333a673dd19e2e4524d5d773d71c7d
|
|
| MD5 |
1f0c1dce14287fff3c97b0c7e2c6888b
|
|
| BLAKE2b-256 |
2ff4c9da844028a1d73632ccb5c4a90d263b6bdeebc996078274a6289fceea33
|
File details
Details for the file torchfbm-0.1.0-py3-none-any.whl.
File metadata
- Download URL: torchfbm-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76ceba426c502566543c5b4669d334ac931792462482fbbead2ab3b9da0c1798
|
|
| MD5 |
c073e60803d877ff3ee8aa9684bff611
|
|
| BLAKE2b-256 |
e2030569c8263e2fbdbb81b2024c9f6da0e1f4d5999095c6a4e87025715cee0d
|