Generate stationary correlated time-series
Summary
This Python function creates a time-series (discrete-time random process) with a specific autocorrelation function (ACF) and continuous probability distribution, e.g with predefined probability density function (PDF).
Usage:
from generate_corr_sequence import gen_corr_sequence
gen_corr_sequence(dist_obj=uniform,
target_acf=1 - np.minimum(np.arange(0, 100), 100) / 100,
L: int = 2 ** 20,
seed=None,
debug: bool = False,
plot_figures_name: str = None)
Arguments
dist_obj- A continuous distribution object from scipy.stats, default isuniformtarget_acf- A required ACF function, default is a linear functionL- Number of required samplesseed- Seed of the random number generatordebug- Plots PDF and ACF graphsplot_figures_name- Filename of the debug figure to be saved, only whendebugisTrue. In no extension is provided, the default ispng.
Returns:
- A random sequence with pre-defined ACF and distribution with type
numpy.ndarray.
Examples
Default settings with uniform distribution and linear ACF
The example below shows the default settings of the function from the examples/default_settings_example.ipynb file.
# Example usage of the function with default settings
sequence = generate_corr_sequence(debug=True)
Nakagami distribution with Bessel function ACF
The example below is from the examples/nakagami_example.ipynb file.
# Example usage of the function with Nakagami distribution and an autocorrelation function
from generate_corr_sequence import gen_corr_sequence
import numpy as np
from scipy.stats import nakagami
from scipy.special import j0
# %%
m = np.arange(0, 100)
signal = gen_corr_sequence(
dist_obj=nakagami(nu=1),
target_acf=np.array(j0(0.1 * np.pi * abs(m))),
debug=True)
Notes
- There is no responsibility for the correctness of the results. It may work and it may not - use debug option to check the results.
- Examples for different distributions (uniform, exponential, Laplace, Rayleigh, triangle,
gamma, lognormal, Nakagami) and four different ACFs are provided in the
examples/evaluation/folder. Theevaluate_PDFs.ipynbfile used for generation of all the ACF figures in the directory. - It takes about 2-3 seconds to generate a single default-length sequence.
- The example of code repeatability is provided in the
examples/nakagami_example.ipynbnotebook as extension of Nakagami distribution example. The sequence is generated 20 times with ACFs as follows.
References
The algorithm is mainly based on the following papers:
- Filho, José Cândido Silveira Santos, and Michael Daoud Yacoub. "Coloring Non-Gaussian Sequences." IEEE Transactions on Signal Processing, vol. 56, no. 12, 2008, p. 6.
- Liu, Bede, et al. "Generation of a Random Sequence Having a Jointly Specified Marginal Distribution and Autocovariance." IEEE Transactions on Acoustics, Speech, and Signal Processing, vol. ASSP-30, no. 6, 1982, p. 11.
Contributors
Dima Bykhovsky, Netanel Tochilovsky, Alexander Rudyak
License
This project is licensed under the MIT license.
Todo
- custom (non-scipy) distributions support
- higher-speed algorithm for Gaussian distributions
- fix lognormal distribution problem for oscillatory ACFs
Metadata
Release files for generate-corr-sequence 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| generate_corr_sequence-0.1.1.tar.gz | 10.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| generate_corr_sequence-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.5 kB
Release files / generate_corr_sequence-0.1.1.tar.gz
| Download URL | generate_corr_sequence-0.1.1.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c66a8701c55e69ce04974f13baa4dec89f04745ccf00af8841de3958d09daab6
|
|
BLAKE2b-256 checksum How to use checksums |
6256fc8764746a6362d7f221d963fc55403ed2c2456d55d42a88a0ff7ca43bb7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.4
|
Release files / generate_corr_sequence-0.1.1-py3-none-any.whl
| Download URL | generate_corr_sequence-0.1.1-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84fefeda13e2e5311e77e1d579fd4630193e384defd218b07eb653e1f3ce9847
|
|
BLAKE2b-256 checksum How to use checksums |
b12acfdc00810a2a4fcc3e9219a3afa8a0a0c69bfae0870714a5ec5c313d8fef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.4
|