Non-Gaussian colored noise generator
Project description
qNoise - Python Package
Non-Gaussian colored noise generator for Python.
Installation
pip install qnoise
Requirements
- Python ≥ 3.8
- NumPy ≥ 1.20
- C++11 compatible compiler
Platform-specific compiler setup:
- macOS:
xcode-select --install - Linux:
sudo apt-get install build-essential(Debian/Ubuntu) - Windows: Visual Studio Build Tools
Quick Start
import qnoise
import numpy as np
import matplotlib.pyplot as plt
# Seed for reproducibility
qnoise.seed_manual(42)
# Generate non-Gaussian colored noise
noise = qnoise.generate(tau=1.0, q=1.5, N=10000)
# Generate Gaussian colored noise (Ornstein-Uhlenbeck)
gauss_noise = qnoise.ornstein_uhlenbeck(tau=1.0, N=10000)
# Plot
plt.plot(noise[:1000])
plt.title('Non-Gaussian Colored Noise (q=1.5)')
plt.show()
Parameters
tau (autocorrelation time)
Controls temporal correlation:
tau = 0: White noise (uncorrelated)tau > 0: Colored noise with correlation time tau
q (statistics parameter)
Controls distribution shape:
q = 1: Gaussian (Ornstein-Uhlenbeck)q < 1: Sub-Gaussian (bounded support)q > 1: Supra-Gaussian (heavy tails)
Other parameters
N: Number of samples to generateH: Integration time step (default: 0.01)temp_N: Transient samples to discard (default: auto-computed)
Functions
High-Level Interface
# Generate qNoise array
qnoise.generate(tau, q, N=1000, H=0.01, temp_N=-1, norm=False)
# Generate Ornstein-Uhlenbeck (Gaussian colored) noise
qnoise.ornstein_uhlenbeck(tau, N=1000, H=0.01, temp_N=-1,
white_noise=False, ini_cond=0.0)
Low-Level Interface (Advanced)
For custom integration loops:
# Single integration steps
qnoise.qnoise_step(x, tau, q, H, sqrt_H)
qnoise.qnoise_norm_step(x, tau, q, H, sqrt_H)
qnoise.ornstein_uhlenbeck_step(x, tau, H)
# White noise
qnoise.gauss_white_noise()
# Random seed control
qnoise.seed_manual(seed)
qnoise.seed_timer()
Applications
- Algorithm robustness testing: Test ML models against realistic non-Gaussian noise
- Monte Carlo simulations: Financial risk models, reliability analysis
- Rare event simulation: Heavy-tailed noise for stress-testing
- Signal processing: Benchmark denoising algorithms
- Stochastic modeling: Complex systems with non-Gaussian dynamics
Examples
Compare Different Statistics
import qnoise
import matplotlib.pyplot as plt
qnoise.seed_manual(42)
fig, axes = plt.subplots(3, 2, figsize=(12, 10))
for i, q in enumerate([0.5, 1.0, 1.5]):
# Time series
noise = qnoise.generate(tau=1.0, q=q, N=10000)
axes[i, 0].plot(noise[:1000])
axes[i, 0].set_title(f'q={q} Time Series')
# Distribution
axes[i, 1].hist(noise, bins=50, density=True, alpha=0.7)
axes[i, 1].set_title(f'q={q} Distribution')
plt.tight_layout()
plt.show()
Autocorrelation Analysis
import qnoise
import numpy as np
import matplotlib.pyplot as plt
qnoise.seed_manual(42)
# Generate noise with different correlation times
for tau in [0.1, 1.0, 10.0]:
noise = qnoise.generate(tau=tau, q=1.0, N=50000)
# Compute autocorrelation
autocorr = np.correlate(noise - np.mean(noise),
noise - np.mean(noise),
mode='full')
autocorr = autocorr[len(autocorr)//2:]
autocorr /= autocorr[0]
plt.plot(autocorr[:200], label=f'tau={tau}')
plt.xlabel('Lag')
plt.ylabel('Autocorrelation')
plt.legend()
plt.show()
Citation
If you use qNoise in your research, please cite:
@article{deza2022qnoise,
title={qNoise: A generator of non-Gaussian colored noise},
author={Deza, J. Ignacio and Ihshaish, Hisham},
journal={SoftwareX},
volume={18},
pages={101034},
year={2022},
publisher={Elsevier},
doi={10.1016/j.softx.2022.101034}
}
Links
- Paper: https://doi.org/10.1016/j.softx.2022.101034
- Demo: https://ignaciodeza.github.io/qNoise/
- GitHub: https://github.com/ignaciodeza/qNoise
- C++ Version: cpp/
- Go Version: go/
License
MIT License - see LICENSE file.
Author
J. Ignacio Deza
Senior Lecturer in Data Science
University of the West of England, Bristol
ignacio.deza@uwe.ac.uk
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
qnoise-1.0.1.tar.gz
(10.6 kB
view details)
File details
Details for the file qnoise-1.0.1.tar.gz.
File metadata
- Download URL: qnoise-1.0.1.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cb31631b905319cf75d01d19afe6af563b8bb1ac86e7d8a2ac9778cbc441c0b
|
|
| MD5 |
1336fe15ae7276defbda9586e48a720b
|
|
| BLAKE2b-256 |
7d6a7aaf64d7cd44d4c62e2e69b62ce03ce130a6d32491c5e20558df465b867f
|