Giter VIP home page Giter VIP logo

generate_corr_sequence's Introduction

drawing

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 is uniform
  • target_acf - A required ACF function, default is a linear function
  • L - Number of required samples
  • seed - Seed of the random number generator
  • debug - Plots PDF and ACF graphs
  • plot_figures_name - Filename of the debug figure to be saved, only when debug is True. In no extension is provided, the default is png.

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 = gen_corr_sequence(debug=True)

Debug figure

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)

Debug figure

Autocorrelation function

Notes

  1. There is no responsibility for the correctness of the results. It may work and it may not - use debug option to check the results.
  2. Examples for different distributions (uniform, exponential, Laplace, Rayleigh, triangle, gamma, lognormal, Nakagami) and four different ACFs are provided in the examples/evaluation/ folder. The evaluate_PDFs.ipynb file used for generation of all the ACF figures in the directory.
  3. It takes about 2-3 seconds to generate a single default-length sequence.
  4. The example of code repeatability is provided in the examples/nakagami_example.ipynb notebook as extension of Nakagami distribution example. The sequence is generated 20 times with ACFs as follows.

Autocorrelation function

Installation

Use: pip install generate_corr_sequence

References

The algorithm is mainly based on the following papers:

  1. 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.
  2. 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

generate_corr_sequence's People

Contributors

alexrudyak avatar bykhov avatar nati-toch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.