Add Noise Plugin

Add some noise

1.1 Introduction

The purpose of the AddNoise plugin is to introduce random noise to Tellurium data.

Noise generation uses the fact that a Rayleigh-distributed random variable R, with the probability distribution F(R) = 0 if R < 0 and F(R) = 1 - exp(-R22 * σ2) if R >= 0, is related to a pair of Gaussian variables C and D through the transformation C = R * cos(θ) and D = R * sin(θ), where θ is a uniformly distributed variable in the interval (0, 2 * π()) 1

Currently only Gaussian noise is implemented.

1.2 Plugin Parameters

Table 1.1 lists available plugin property names, along with their data type and purpose.


Parameter NameData Type

Purpose




   
InputData TelluriumData

Data on which noise will be applied to.

Sigma,(σ) double

Size of applied noise. Noise is generated for each single data value, with a probability corresponding to a Gaussian distribution, centered around the value, and with a variance equal to σ2 .

NoiseType int

Type of noise applied on data. Only Gaussian noise is currently supported.

Progress double

The progress property communicates the progress (in percent) of Noise application.





Table 1.1: Add noise Plugin Parameters

1.3 Plugin Events

The AddNoiseplugin uses all of the available plugin events, i.e. the PluginStarted, PluginProgress and the PluginFinished events.

The available data variables for each event are internally treated as pass trough variables, so any data, for any of the events, assigned prior to the plugin’s execute function (in the assignOn() family of functions), can be retrieved unmodified in the corresponding event function.


Event Arguments

Purpose







   
PluginStarted void*, void*

Signals to application that the plugin has started applying noise on data. Both parameters are pass through parameters and are unused internally by the plugin.

   
PluginProgressvoid*, void*

Communicates progress of noise generation. Both parameters are pass through parameters and are unused internally by the plugin.

   
PluginFinishedvoid*, void*

Signals to application that execution of the plugin has finished. Both parameters are pass through parameters and are unused internally by the plugin.





Table 1.2: AddNoise Plugin Events

1.4 The execute(bool inThread) function

The execute() function will apply noise to all rows and columns of the assigned data, with one exception. Data not affected are data in the first column, and if, and only if, its column header equals ”time” (case insensitive).

The execute(bool inThread) method supports a boolean argument indicating if the execution of the plugin work will be done in a thread, or not. Threading is fully implemented in the AddNoise plugin.

The inThread argument defaults to false.

1.5 Python examples

1.5.1 Add noise to data acquired from RoadRunner

The python script below shows how to acquire simulation data from RoadRunner and pass it to the noise plugin. The format of this data, which is obtained from the simulate() function (line 8), is not directly compatible with the Noise plugin’s InputData property. This incompatibility is handled by an intermediate data structure in Python, called DataSeries (line 14).

The plugin’s properties, InputData and Sigma, are assigned on line 17 and 20 respectively.

Line 23 denotes the execution of the noise plugin, and after that has finished, data can be visualized by using the plot function (line 26). The output is shown below the script.

 
1import roadrunner 
2import teplugins as tel 
3 
4try: 
5    # Create a roadrunner instance and create some data 
6    rr = roadrunner.RoadRunner() 
7    rr.load("sbml_test_0001.xml") 
8    data = rr.simulate(0, 10, 511) # Want 512 points 
9 
10    #Add noise to the data 
11    noisePlugin = tel.Plugin ("tel_add_noise") 
12 
13    # Get the dataseries from data returned by roadrunner 
14    d = tel.getDataSeries (data) 
15 
16    # Assign the dataseries to the plugin inputdata 
17    noisePlugin.InputData = d 
18 
19    # Set parameter for the size of the noise 
20    noisePlugin.Sigma = 3.e-6 
21 
22    # Add the noise 
23    noisePlugin.execute() 
24 
25    # Get the data to plot 
26    noisePlugin.InputData.plot() 
27 
28except Exception as e: 
29    print Problem:  + e
Listing 1.1: Add noise example.


PIC

Figure 1.1: Output for the AddNoise python example script discussed above


1.5.2 Visualization of the noise distribution used in the AddNoise plugin

The Python script below demonstrates how to obtain and visualize the actual distribution (Gaussian) of noise that is applied on data.

 
1# Show that add noise plugin correctly computes Sigma (standard deviation) 
2import matplotlib.pyplot as plt 
3import scipy.stats as stats 
4import teplugins as tel 
5import numpy as np 
6 
7p = tel.Plugin ("tel_add_noise") 
8 
9value = 2.34    #This will be the mean 
10n = 80000 
11inputData  = np.zeros (shape=(1,2)) 
12inputData[0] = [0, value] 
13 
14data = tel.DataSeries.fromNumPy (inputData) 
15p.Sigma = 0.25 
16 
17outArray = [] 
18for i in range(n): 
19    p.InputData = data 
20    p.execute() 
21    outValues = p.InputData.toNumpy 
22    outArray.append(outValues[0][1]) 
23 
24plt.hist(outArray, 200, normed=True) 
25 
26# Overlay analytical solution 
27aRange = np.arange(min(outArray), max(outArray), 0.001) 
28plt.plot(aRange, stats.norm.pdf(aRange, value, p.Sigma), linestyle=--, linewidth=2, color=red) 
29 
30plt.show()
Listing 1.2: Noise distribution example.


PIC

Figure 1.2: Output for the AddNoise python example script discussed above