Noise Class
Navigation: PGMs ➔ Classes ➔ Noise Class
Global Pre-Defined Class Instances | SysCAD Pre-Defined Classes | |||||||
---|---|---|---|---|---|---|---|---|
Sp Database SDB Class | Particle Size Defn PSD Class | Plant Model PM Class | Array Class | StrArray Class | Matrix Class | TagSelect Class | Time Class | Noise Class |
Latest SysCAD Version: 25 October 2024 - SysCAD 9.3 Build 139.36522
Related Links: Defining a Class, Example PGM Files
Related Links: Noise Controller
Description
The Noise class can be used to add noise to a value.
- All random number distributions use a single random number generator.
- If Init or SetType are not called, it is assumed that type 0 is required (Gaussian). If Init or SetGlobal are not called, it is assumed that a global random generator must be used.
- If the NoiseType specified is outside the specified range of methods available, then the nearest number will be used. e.g. if a large number is specified, then the last method available (highest method number) will be used.
NOTE: The Controller -- Noise model, is superseding this topic. However, this form is still available for users familiar with the PGM coding style.
Data Members
NOTE: The meaning of the data members Mean and StdDev depend on the Noise class Type! See table below.
Mean: For Gaussiana nd Flat Distributions, this is the value around which the random number must be generated. See table below for its meaning in other distributions. The default is 0.0.
StdDev: The Standard Deviation for Gaussian distribution (68.27% of the numbers generated will be between (Mean - StdDev) and (Mean + StdDev). For the Flat distribution StdDev represents the minimum and maximum distance from the Mean. See table below for its meaning in other distributions. The default is 1.0.
Output: The last value generated by GetVal. This is a constant and cannot be set.
Generator Type Mean parameter StdDev parameter Gaussian Mean Standard deviation Flat Mean Maximum deviation Poisson Mean Not used Gamma Alpha Beta Weibull Alpha Beta Bernoulli Probability, p Not used Binomial n Probability, p Geometric Probability, p Not used Exponential Mean Not used Extreme Value Alpha Beta Log Normal m s Cauchy Alpha Beta Fisher F m n Student t n Not used
Member Functions
The examples in the table below are based on the following variables and 'Noise Class' declarations.
Noise a ;declares 'noise' instances
Real d
Call | Functionality | Return Type | Parameters | Example |
Init (Mean, StdDev, NoiseType, Global, Seed ) |
This can be used to set all the parameters. The random number generator is initialised and reset. |
Mean :Refer to description above |
a.Init(5.0,1.0,1,0,3) | |
Setup (Mean, StdDev, NoiseType, Global) |
This function can be used to set all the parameters. The random number generator is initialised and reset. |
Mean :Refer to description above |
a.Setup(4.0,0.9,4,1) | |
SetType (NoiseType) |
This sets the random number generator type. |
NoiseType: Is a 'byte' field which specifies the noise generator type required. See below the table for a description of 'NoiseTypes'. |
a.SetType(6) | |
SetGlobal (Global) |
This sets the global option. Must be used before the function SetSeed! |
Global: Is a 'bit' field which specifies if the random number must be obtained from a shared global random generator or from its own random number generator. |
a.SetGlobal(1) | |
SetSeed (Seed) |
This function sets the seed value.
|
Seed: Is a data type 'long' field which specifies the seed value for generating the first random number. |
a.SetSeed(5) | |
GetVal () |
This will return the value generated by the random number generator.
|
Real |
None |
d = a.GetVal() |
Noise Types
Descriptions of the NoiseType are shown in the table below.
Field Value Generator Type 0 Gaussian generator 1 Gaussian generator 2 Flat generator 3 Flat generator 4 Poisson generator 5 Poisson generator 6 Gamma generator 7 Gamma generator 8 Weibull generator 9 Weibull generator 10 Bernoulli generator 11 Binomial generator 12 Geometric generator 13 Exponential generator 14 Extreme Value generator 15 Log Normal generator 16 Cauchy generator 17 Fisher F generator 18 Student t generator
Notes:
- The Gaussian random noise generator's output characteristic is the "Bell curve" where 68.27% of the numbers generated are within +/- one StdDev from the Mean.
- The Flat random noise generator's output characteristic is flat where random numbers are generated between +/- StdDev from the Mean with equal probability.
Probability Density Functions
The random number generator used for all probability functions is from the C++ standard library (http://www.cplusplus.com/reference/random/).
The Probability Density functions used for the Noise generation are shown in the following table. In all cases the following convention is used:
- [math]\displaystyle{ \mu }[/math] = Mean Value
- [math]\displaystyle{ \sigma }[/math] = Standard Deviation
For all methods, the tag PlantModel.RandomSeedAtStart (set on the Plant Model - FlwSolve page) affects the repeatability of the random values generated. For the same seed value, a repeatable set of random numbers will be generated. For a different seed, a different set of random numbers will be generated. If "*" is used, then a new random set of values will be generated on every run.
Type | Probability Density Function P(t) | NOTES | |
---|---|---|---|
Gaussian |
[math]\displaystyle{ P(t) = \cfrac{1}{\sigma \sqrt{2\pi}}\cdot e^{\dfrac{-(t-\mu)^2}{2\sigma^2}} }[/math] |
where [math]\displaystyle{ \sigma \gt 0 }[/math] | Normal distribution: 68.27% of the numbers generated will be between [math]\displaystyle{ \mu-\sigma }[/math] and [math]\displaystyle{ \mu+\sigma }[/math] (see Wikipedia). |
Flat |
[math]\displaystyle{ P(t) = 0 }[/math] |
where [math]\displaystyle{ t \lt \mu - m }[/math] or [math]\displaystyle{ t \gt \mu + m }[/math] | |
[math]\displaystyle{ P(t) = \dfrac{1}{2\sigma} }[/math] |
where [math]\displaystyle{ \mu - m ≤ t ≤; \mu + m }[/math] and [math]\displaystyle{ m ≥; 0 }[/math] and [math]\displaystyle{ m }[/math] = maximum deviation |
||
Poisson |
[math]\displaystyle{ P(t) = \cfrac{\mu^t}{t!}\ e^{-\mu} }[/math] |
where [math]\displaystyle{ e }[/math] = the base of the natural logarithm system (2.71828...) and [math]\displaystyle{ \mu \gt 0 }[/math] | |
Gamma |
[math]\displaystyle{ P(t) = \cfrac{1}{\Gamma(\alpha)\ \beta^{\alpha}}\ t^{\alpha-1}\ e^{-t/\beta} }[/math] |
where [math]\displaystyle{ \alpha ≥ 0.5 }[/math] and [math]\displaystyle{ \beta \gt 0 }[/math] |
The Chi-squared distribution is a special case of the Gamma distribution |
Weibull |
[math]\displaystyle{ P(t) = \alpha^{-\beta}\ \beta\ t^{\beta-1}\ e^{-(t/\alpha)^\beta} }[/math] |
where [math]\displaystyle{ t = \alpha (-\ln(U))^{1/\beta} }[/math] and [math]\displaystyle{ \alpha ≥ 0.04 }[/math] and [math]\displaystyle{ \beta ≥ 0.01 }[/math] |
|
Bernoulli |
[math]\displaystyle{ P(t) = p^{t}\ (1-p)^{1-t} }[/math] |
where [math]\displaystyle{ 0 ≤ p ≤ 1 }[/math] |
|
Binomial |
[math]\displaystyle{ P(t) = \dbinom{n}{t} p^{t}\ (1-p)^{n-t} }[/math] |
where [math]\displaystyle{ n }[/math] is a positive integer, [math]\displaystyle{ \dbinom{n}{t} = \cfrac{n!}{t!(n-t)!} }[/math] and [math]\displaystyle{ 0 \lt p ≤ 1 }[/math] |
|
Geometric |
[math]\displaystyle{ P(t) = p\ (1-p)^{t} }[/math] |
where [math]\displaystyle{ 0 \lt p ≤ 1 }[/math] | |
Exponential |
[math]\displaystyle{ P(t) = \mu\ e^{-\mu\ t} }[/math] |
where [math]\displaystyle{ \mu \gt 0 }[/math] |
|
Extreme Value |
[math]\displaystyle{ P(t) = \cfrac{1}{\beta}\ z(t)\ e^{-z(t)} }[/math] |
where [math]\displaystyle{ z(t) = e^{(\alpha-t)/\beta} }[/math] and [math]\displaystyle{ \beta \gt 0 }[/math] | |
Log Normal |
[math]\displaystyle{ P(t) = \cfrac{1}{s\ t\ \sqrt{2\pi;}}\ e^{-(\ln t-m)^2/2s^2} }[/math] |
where [math]\displaystyle{ 0 \lt s ≤ 50.70 }[/math] | |
Cauchy |
[math]\displaystyle{ P(t) = \cfrac{1}{\pi;\ \beta\ \left [1+\left (\cfrac{t-\alpha}{\beta} \right )^2 \right ]} }[/math] |
where [math]\displaystyle{ \beta \gt 0 }[/math] | |
Fisher F |
[math]\displaystyle{ P(t) = \cfrac{\Gamma; \left (\cfrac{m+n}{2} \right )}{\Gamma;\left (\cfrac{m}{2}\right )\ \Gamma;\left (\cfrac{n}{2}\right )}\ \frac{\left (\cfrac{m\ t}{n} \right )^{(m/2)}}{t\ \left (1+\cfrac{m\ t}{n} \right )^{(m+n)/2}} }[/math] |
where [math]\displaystyle{ 1 ≤ m ≤ 100 }[/math] and [math]\displaystyle{ n ≥ 1 }[/math] | |
Student t |
[math]\displaystyle{ P(t) = \cfrac{1}{\sqrt{n\ \pi;}}\ \cfrac{\Gamma;\left (\cfrac{n+1}{2} \right )}{\Gamma;\left (\cfrac{n}{2} \right )}\ \left (1+\cfrac{t^2}{n} \right )^{-(n+1)/2} }[/math] |
where [math]\displaystyle{ n ≥ 0.25 }[/math] |
References
- Press W.H, Teukolsky S.A, Vetterling W.T, Flannery B.P Numerical Recipes in C (2nd Edition) Cambridge University Press 1992.
- Sanders D.H Statistics A Fresh Approach McGraw-Hill 1990.
- http://www.cplusplus.com/reference/random/ and related links describing each distribution.