qNoise: A generator of non-Gaussian colored noise

We introduce a software generator for a class of colored (self-correlated) and non-Gaussian noise, whose statistics and spectrum depend on two parameters, $q$ and $\tau$. Inspired by Tsallis' nonextensive formulation of statistical physics, the so-called $q$-distribution is a handy source of self-correlated noise for a large range of applications. The $q$-noise -- which tends smoothly for $q=1$ to Ornstein--Uhlenbeck noise with autocorrelation $\tau$ -- is generated via a stochastic differential equation, using the Heun method (a second order Runge--Kutta type integration scheme). The algorithm is implemented as a stand-alone library in C++, and is made available as open source in the Github repository. Noise' statistics can be specified handily; by only varying parameter $q$: it has compact support for $q<1$ (sub-Gaussian regime) and finite variance up to $q=5/3$ (supra-Gaussian regime). Once $q$ is fixed, noise' autocorrelation can be tuned independently by means of parameter $\tau$. The presented qNoise generator provides a readily tool to modeling wide range of real-world noise types, and is suitable to study the effects of correlation and deviations from the normal distribution in systems of stochastic differential equations, key to understand system dynamics in numerous applications. The effect of noises' statistics on the response of a range of nonlinear systems is briefly discussed. In many of these examples, the systems' response turns optimal for some $q\neq1$. Hence, this paper aims to introduce qNoise generator for C++ at the class level and evaluate the kind of noise it generates, alongside their use in a range of applications.


Motivation
Most studies on noise-induced phenomena [1,2] have assumed the noise source to have Gaussian distribution, either "white" (memoryless) or "colored" (red, pink, etc . . . ). Although customarily accepted without criticism on the basis of the central limit theorem, the true rationale behind this assumption lies in the possibility of obtaining some analytical results, and avoiding many difficulties arising in generating and handling non-Gaussian noise. There is however experimental evidence that at least in some cases (particularly in sensory and biological systems) non-Gaussian noise sources may add desirable features to noise-induced phenomena (e.g. robustness, fault tolerance [3]). These findings add practical interest to the task of finding viable ways to deal with non-Gaussian noise.
Here we introduce a lightweight (generic C++ class) generator for non-Gaussian, colored stochastic processes. The expected applications of this algorithm are as diverse as the modeling of some types of vibration or fluctuation which are typically non-Gaussian, the generation of noise which is naturally confined to a domain, or the investigation of the response of many dynamical systems embedded in noise, as the latter deviates from being Gaussian.
The main features of noise obeying Tsallis' statistics are summarized in Sec. 2; section 3 is devoted to the description of the software architecture and properties; section 4, provides statistical analysis of the generated noise in the qualitatively different cases, alongside a discussion on the q-dependence of the variance and effective self-correlation time. The measured self-correlation times of the obtained series are compared with a fitting expression [4]. In Sec. 5, a brief review is provided on related work, namely where non-Gaussian noise-induced phenomena have been studied.

q-noise with Tsallis' statistics
The exponentially self-correlated Gaussian noise η(t) named after Ornstein and Uhlenbeck (OU noise, or "colored" Gaussian noise) can be dynamically generated through the differential equation where ξ(t) is centered Gaussian white noise with variance D, namely This way, η's self-correlation time is τ .
A straightforward generalization of Eq. (1) was proposed by Borland some time ago [5] as a model for correlated diffusion: where the potential V q is given by: As much as the OU noise allows to explore spectral effects within the class of exponentially correlated noise, this generalization provides moreover a device to explore statistics effects by varying just one parameter (namely q, at constant τ and D).
The stationary properties of η (including its autocorrelation function) are thoroughly described elsewhere [4,6,7,8,9], we here summarize the main results. Using the Fokker-Planck formalism, one obtains the stationary probability distribution which can be normalized only for q < 3 (Z q is a normalization factor). The first moment η always vanishes [4,6,7,8,9] and the second moment, is finite only for q < 5/3. Some properties of the noise are summarized in Fig. 1. The bold line depicts the Gaussian limit (q = 1). Curves of weaker full lines show that for q > 1, the second moment is larger than the Gaussian limit D/τ . For q < 1 (dotted lines) the distribution has a cut-off and is only defined for Same distributions are shown in linear and semilogarithmic scales (Fig. 1, left and right panels respectively). The autocorrelation time τ q of the process η(t) in its stationary regime, also diverges for → 5/3 ≈ 1.66. Far from its divergence point, it can be approximated as in [4]: PDF(x) q < 1 q = 1 q > 1 Figure 1: Stationary q-noise pdf for 0 < q < 1 (dotted line), q = 1 (bold line) and 1 < q < 1.6 (single line). The right panel show the same plot in semilogarithmic scale. Notice the pdf is compact-supported for q < 1, Gaussian for q = 1 and fat-tailed for q > 1.
When q → 1, η becomes a Gaussian colored noise, namely the Ornstein-Uhlenbeck process ξ OU (t), with correlations and probability distribution 2.1. τ and η 2 dependence on q Equations Eqs. (5) and (7) tell us that for q = 1, η 2 and τ q do not attain their values (D and τ respectively) in a normal distribution. Rather, they both diverge at q = 5/3 (white squares in both panels of Fig. 2). It is however desirable to have a generator able to approximately keep constant the characteristics of these properties with respect of q, at least sufficiently far away from the divergence point. This can be very useful to study the effects of the statistics due to changes in q keeping τ and variance constant.
This way an effective τ q and η 2 can be defined by dividing τ by Eq. (7) before integration and η 2 by Eq. (5) after integration. The filled circles in both panels of Figure 2 show this dependence for both τ and η 2 , and how the system becomes independent of q for the range 0 < q < 1.5 approximately. For q > 1.5, the proximity to the divergence point q = 5/3 (shown with a dotted line) makes this approximation fail.

Generator <class> Description
The noise generator [10] is implemented in C++ as class, with dependencies on standard libraries only. It generates random numbers using functions in the built-in <random> class. The generator provides functions for Gaussian white noise, Gaussian colored noise (Orstein-Uhlenbeck), and two versions of non-Gaussian non-white noise. One where τ and η 2 depend on q (as in Eqs. 5 and 7) and a normalized version where this effect has been counterbalanced to the first order, sufficiently far away from q = 5/3 (as shown as black dots in figure 2). This batch of functions would facilitate modeling a wide variety of scenarios and is suitable for many applications, some of which are detailed in the last section of this paper. By default, the tool uses the Mersenne-Twister generator [11] which provides a very long (2 19937 − 1) pseudo-random number cycle. Hence it is advised to seed the generator only once to avoid spurious correlations.

Functions
The class implements four public member functions as shown in Fig. 3. The first function is a wrapper for the normal distribution, implemented in the <random> standard library. It is presented as a function of this class for convenience.
The second function is an implementation of the Orstein-Uhlenbeck noise. It accepts three parameters. The previous value of the noise (since it is a Markov process), the autocorrelation time τ of the noise and the integration time H (necessary for setting the adequate timescale of the noise). The third function implements the q-noise distribution. It accepts the same variables as the orsUhl function in addition to q (the noise statistics), and sqrt H as an optional variable. If H is constant, explicitly setting sqrt H = H 1/2 will avoid its calculation every time the function is called. A snippet of the function is shown in Listing 1 below.
Finally, the fourth function is a wrapper for the third function. Here τ is given by Equation (7) and the resulting noise is divided using Eq. (5) in order to counterbalance the dependence of both τ and the variance of the noise on q. See section 2.1 for an analysis of this effect and a discussion about its range of validity.  Method. For q = 1, returned noise behaves like OU noise, for q < 1, noise not defined outside (+/-etaCut) and for q > 1, noise statistics become supra-Gaussian. Access to complete code and documentation [10].
A generic unit test results are shown in Fig. 4. The test compares the generated average noise, of an ensemble of 10 qNoise runs for each set of q, ⌧ and N , with the expected distribution of noise. As expected, only when N is relatively small does the generated noise deviate from its theoretical distribution, particularly for high ⌧ . That is, it takes longer (higher N ) for a highly correlated noise (high ⌧ ) to explore the support and approximate the PDF.

Seeding
The presented class enables seeding the random number generator in two functions: Listing 1: qNoise() pseudocode: integrates a differential equation using the Heun Method. For q = 1, returned noise behaves like OU noise, for q < 1, noise not defined outside (+/-etaCut) and for q > 1, noise statistics become supra-Gaussian. Code and documentation are available in [10].
A generic unit test results are shown in Fig. 4. The test compares the generated average noise, of an ensemble of 10 qNoise runs for each set of q, τ and N , with the expected distribution of noise. As expected, only when N is relatively small does the generated noise deviate from its theoretical distribution, particularly for high τ . That is, it takes longer (higher N ) for a highly correlated noise (high τ ) to explore the support and approximate the PDF.
. This shows the accuracy of the generated noise -note its dependency of N and its relative independence of q.

Seeding
The presented class enables seeding the random number generator in two functions:  Method. For q = 1, returned noise behaves like OU noise, for q < 1, noise not defined outside (+/-etaCut) and for q > 1, noise statistics become supra-Gaussian. Access to complete code and documentation [10].
A generic unit test results are shown in Fig. 3. The test compares the generated average noise, of an ensemble of 10 qNoise runs for each set of q, ⌧ and N , with the expected distribution of noise. As expected, only when N is relatively small does the generated noise deviate from its theoretical distribution, particularly for high ⌧ . That is, it takes longer (higher N ) for a highly correlated noise (high ⌧ ) to explore the support and approximate the PDF.

Seeding
The presented class enables seeding the random number generator in two functions: Timer seeding is provided as the default setting for random number generator, and it is done automatically. For lightweight single-threaded runs, manual seeding is not required. However, in multi-threading settings manual seeding (call seedManual) for each thread is recommended.

Properties of the generated noise
Bounded domain (q < 1) Bounded-domain noise is widespread in nature, and has multiple applications for modeling and control [9] 1 . The infra-Gaussian noise considered here can be addressed as a small deviation from Gaussianity, allowing a perturbative approach (Fig 5). In Sec. 5.1, an example of a infra-Gaussian noise is shown, in a resonant trap. Another use is as a source of noise whose distribution is quasi-normal but identically zero outside a boundary.
The noise generator algorithm does also ensure that noise domain is bounded, checking for out-of-bound values. This necessary test (especially for highly correlated noise) is implemented and documented accordingly in the provided source code.
Gaussian case (q = 1) The Gaussian case behaves exactly as an Orstein-Uhlenbeck noise, concurring perfectly with it for the whole range of τ (Fig 6). As shown in the introduction, the limit q → 1 recovers the Gaussian noise, and all limits converge to it, see Eqs. (5)-(9). This limit allows to explore regions arbitrarily near the normal distribution. It can be used to model small deviations from it due to some underlying physical phenomenon. As the value of q can be changed continuously and dynamically, this scheme also allows to model departures from the normal distribution due to long time-scale fluctuations, by slowly varying 1 − < q < 1 + as a more realistic model for a small noisy system.
It is not generally recommended to compute the purely Gaussian case from the general case and set q = 1, particularly due to potential computational complexity. An extensive batch of tests has been run in order to compare it to the Orstein-Uhlenbeck noise. All of the results were successfully recovered. As presented above, orsUhl, a function for generating Orstein-Uhlenbeck noise for a variable τ is included in this package and its results are equivalent to using the non-normalized qNoise function for q = 1 at a fraction of the computation time.

Supra-Gaussian noise (1 < q < 5/3)
The supra-Gaussian (also called fat-tail) noise presented here is of the class of finite variance. This is usually an overlooked, modestly studied, class Although in the linear histogram on the left it cannot be clearly seen, the semi-logarithmic plot on the right clearly show the bounded domain. The curve of dotted points shows the theoretical distribution as in Fig. 1 for the same parameters, which perfectly concurs with the histogram of the data. of noise. The Supra-Gaussian noise, generally considered in literature, tends to be Lévy-like, where the variance is infinite 2 .
The noise presented here (Fig 7) is of a finite variance. The long excursions are however much longer and much more frequent than in the Gaussian case. This case is the most commonly used in the applications of non-Gaussian noise presented below, as it allows to model many realistic systems outside of equilibrium . Notice that in the right figure the noise is not centered around zero as it is performing a very long excursion (larger than the sample) given its very high autocorrelation (τ ). Both histograms in the bottom panels show the same data, concurring with the sample on top-left. (τ = 1s). Although the linear histogram on the left shows a bell-shaped distribution, this is not enough to demonstrate Gaussianity. However that is possible to observe on the semi-logarithmic, parabolic, plot on the right. The dotted points show the theoretical distribution as in Fig. 1 for the same parameters, which perfectly concurs with the histogram of the data.

Applications
Some applications of the generated noise are shown below, both as an illustration and to show the potential of the generator both for research as well as a source of high quality noise for simulations or experiments (e.g. in electronics, optics, photosensitive chemical reactions etc. . . ).

Stochastic resonance
This is a phenomenon occurring in some nonlinear systems, whereby enhancing the response to a weak external signal may require increasing the noise intensity. An often resorted-to measure is the signal-to-noise ratio at the input frequency ω (denoted by R). Notice that in the right figure the noise is not centered around zero as it is performing a very long excursion (larger than the sample) given its very high autocorrelation. Both histograms in the bottom panels show the same data, concurring with the sample on top-left. (τ = 1s). Although the linear histogram on the left, showing a bell-shaped distribution, could lead to suggest Gaussianity, the semi-logarithmic plot on the right, however, show a supra-Gaussian behavior. The dotted points curve shows the theoretical distribution as in Fig. 1 for the same parameters concurring perfectly with the histogram of the data.
The main numerical and theoretical results are [12,13]: (1) for fixed τ , the maximum R increases with decreasing q; (2) for given q, the optimal noise intensity (the one maximizing R) decreases with q and its value is approximately independent of τ ; (3) for fixed noise intensity, the optimal value of q is independent of τ and in general turns out to be q op = 1. A simple stochastic resonance experiment with a non-Gaussian white noise [3] confirmed most of these predictions.

Brownian motors
A class of non-equilibrium systems with both potential technological applications and biological interest are the so called "ratchets", in which the breakdown of spatial and/or temporal symmetry induces directional transport. Their transport properties can be studied by means of the Langevin equation with m the particle's mass, γ the friction constant, V (x) the (sawtooth-like) ratchet potential, F a constant "load" force, and ξ(t) the thermal noise, satisfying ξ(t)ξ(t ) = 2γT δ(t − t ).
The system is kept out of thermal equilibrium by the time-correlated forcing η(t) (with zero mean), allowing to rectify the motion. The q-dependence of the usual measures of performance has been studied: the mean current J ≡ dx/dt and the efficiency ε (the ratio of the work per unit time done against F , to the mean power injected by η).
In the overdamped regime (m = 0, γ = 1), J is found to grow monotonically with q whereas ε is maximized for some 1 < q < 5/3. For m = 0, ratchets exhibit mass-separation capabilities which are enhanced by non-Gaussian noise [14,15]. In [16], effects of biological and technological relevance have been found in a model for the transport properties of motor proteins when departing from Gaussian behavior: J is maximized not only by an optimal noise intensity but also by an optimal q = 1.

Resonant gated trapping
Stochastic resonance, which is essentially a threshold phenomenon, plays also a relevant role in ionic transport through cell membranes. In [17], a "toy model" considering the simultaneous action of a deterministic and a stochastic external field on the trapping rate of a gated imperfect trap, was studied by assuming Tsallis' noise with q < 1: the bounded character of the PDF contributed positively to the rate of overcoming the threshold, and such rate remained at about the same order within a larger range of values than if η had been a white noise.

Noise-induced transition
A genetic model exhibiting a re-entrance from a disordered state to an ordered one, and again to a disordered state as τ varies from 0 to ∞ showed moreover a strong shift in the transition line, as q departed from q = 1. The transition was anticipated for q > 1, while it was retarded for q < 1 [18].

Noise-induced phase transition
In fact fat-tail noise distributions (q > 1) counteract the effect of selfcorrelation (namely, they advance the ordering boundary as D is increased at constant coupling), and compact-support ones (q < 1) enhance it (they retard the ordering boundary). Particular interest rises the effect of (q < 1) multiplicative noise on the susceptibility: it shifts from being larger on the ordering boundary to being larger on the disordering boundary [19,20].
An example of this phenomenon can be found in climate change. Many climatic "Tipping points" are are, in fact, noise-induced phase transitions whose forcing them (including astronomic, natural and antropogenic noise) are not necessarily Gaussian. An "Early Warning"[? ] system of tipping points should include simulation considering the non-gaussianity of the stochastic forcing.

Broad-spectrum energy harvesting
In piezoelectric energy harvesting from noise, a system obeying a squarewell potential can strongly profit from the large correlated excursion occurring for q > 1 [21].

Conclusions
A lightweight software is presented that generates a class of non-Gaussian, colored noise. This noise can be handily generated during numerical experiments, or fed to experiments via an interface. The software, alongside documentation, is provided on the online repository Github including examples and unit test results, with an open source license. Instances of noiseinduced phenomena arising when the system is submitted to (colored and non-Gaussian) noise sources with Tsallis' q-statistics, as applications, have been briefly explored. The above discussed results show that non-Gaussian noise can significantly change the system's response in many noise-induced phenomena, as compared with the Gaussian case. Moreover, in all the cases presented here, the system's response was either enhanced or altered in a relevant way for values of q departing from Gaussian behavior. In other words, the optimum response occurred for q = 1. Clearly, the study of the change in the response of other related noise-induced phenomena when subjected to such kind of non-Gaussian noise will be of great interest.