r This module provides several tools involving correlated noise.
There is a function for calculating auto-correlation coefficients and a class for use in generating random noise with specified auto-correlation characteristics.
>>> noise_gen = CorrelatedNoiseGenerator(acfcoeffs=[1.0, 0.5, 0.3, 0.1]) >>> test_noise = noise_gen.corr_normal(num_values=100000) >>> autocorr(test_noise, lastlag=6) [1.0, 0.50094352543708198, 0.30158412855919509, 0.10104967953428118, 0.002665198305403594, 0.0024066568197502591, 0.0012079072002819918]
computes the self-correlation of a vector for a specified lag. This is a support function for autocorr.
- x (float array): array to be correlated lag (int): specifies the lag for the correlation calculation
- a single correlation coefficient at the specified lag.
computes the self-correlation coefficients of x from lag = 0 to lag = lastlag
- x (float array): array to be correlated lastlag (int): the final lag value to be calculated
builds a normalized auto-correlation matrix that has dimensions of size*size.
- acfcoeffs (float array): the desired auto-correlation coefficients size (int): the size of the ultimate noise array
This correlated noise generator class takes advantage of the fact that the entries in the cholesky decomposition of the acf matrix rapidly approach limiting values. This means that we do not need to build a large acf matrix: instead we make it large enough that the entries in the cholesky matrix have reached limiting values. We extract those limiting values along with a matching set of initial random numbers.
Uses acfcoeffs and cholesky decomposition to calculate final_coeffs, the limiting values in the cholesky matrix columns. There will be as many such values as there are entries in acfcoeffs.
An initial set of N[0,1] random numbers are generated and stored in r. With this setup completed, correlated random number can be generated by:r dot final_coeffs
Calculates and returns a NumPy ndarray of length num_values. The values are normally distributed with a mean of zero, a standard deviation of 1, and an auto-correlation that closely approximates the values given by acfcoeffs when this object was instantiated.
- num_values (int): the desired length of the output array