Noise Class

From SysCAD Documentation
Jump to navigation Jump to search

Navigation: PGMs ➔ Classes ➔ Noise Class

SysCAD Pre-Defined Classes and Examples EXAMPLES: User Defined Classes
Sp Databse
Class
PSD
Class
Array
Class
StrArray
Class
Matrix
Class
Tag Select
Class
Plant Model
Class
Noise
Class
Time
Class
Agitator
Power
Reaction
Finder
Aq Feed Conc
Calculator
Evaporation
Correlation
Bayer Liquor
Class
Check
Element Bal

Latest SysCAD Version: 21 September 2021 - SysCAD 9.3 Build 139.29552

Related Links: Noise Controller


Description

The Noise class can be used to add noise to a value.

  • In SysCAD 9.3 Build 137 or later, a larger number of random number distributions are available, all using a single random number generator.
  • In SysCAD 9.3 Build 136 or earlier, a Gaussian, Flat, Poisson, Gamma or Weibull random number distributions may be selected. Each noise generator uses one of two random number generators.
  • 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. eg. 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

* Only available in SysCAD 9.3 Build 137 or later.

Member Functions

The examples in the table below is 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
StdDev :Refer to description above
NoiseType :Refer to SetType function below' Global :Refer to SetGlobal function below
Seed :Refer to SetSeed function below

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
StdDev :Refer to description above
NoiseType :Refer to SetType function below' Global :Refer to SetGlobal function below

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.

  • This is typically a negative prime integer.
  • If the global option is not set and the same seed is used, the same sequence of random numbers will be generated.
  • If SetGlobal is called after this the seed setting may be discarded.

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.

  • The method used will depend on the type of distribution selected.
  • The value returned depends on the value of Mean and StdDev.
  • The value returned is equal to the data member Output.

Real

None

d = a.GetVal()

Noise Types

Descriptions of the NoiseType for the different versions of SysCAD are shown in the table below.

Field Value Generator Type
Build 136 or earlier
Generator Type
Build 137 or later
0 Gaussian generator using Random Method 1 Gaussian generator
1 Gaussian generator using Random Method 2 Gaussian generator
2 Flat generator using Random Method 1 Flat generator
3 Flat generator using Random Method 2 Flat generator
4 Poisson generator using Random Method 1 Poisson generator
5 Poisson generator using Random Method 2 Poisson generator
6 Gamma generator using Random Method 1 Gamma generator
7 Gamma generator using Random Method 2 Gamma generator
8 Weibull generator using Random Method 1 Weibull generator
9 Weibull generator using Random Method 2 Weibull generator
10 Not used Bernoulli generator
11 Not used Binomial generator
12 Not used Geometric generator
13 Not used Exponential generator
14 Not used Extreme Value generator
15 Not used Log Normal generator
16 Not used Cauchy generator
17 Not used Fisher F generator
18 Not used 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

In SysCAD 9.3 Build 136 or earlier, the random number generator used for these probability functions is from Numerical Recipes in C.

In SysCAD 9.3 Build 137 or later, 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]\mu[/math] = Mean Value
[math]\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] P(t) = \cfrac{1}{\sigma \sqrt{2\pi}}\cdot e^{\tfrac{-(t-\mu)^2}{2\sigma^2}} [/math]
where [math] \sigma \gt 0 [/math]
Flat
  • [math] P(t) = 0 [/math]
where [math]t \lt \mu - m[/math] or [math]t \gt \mu + m[/math]
  • [math] P(t) = \dfrac{1}{2\sigma} [/math]

where [math]\mu - m ≤ t ≤ \mu + m[/math] and [math] m ≥ 0 [/math] and [math] m [/math] = maximum deviation

Poisson
  • [math] P(t) = \cfrac{\mu^t}{t!}\ e^{-\mu}[/math]
where [math]e[/math] = the base of the natural logarithm system (2.71828...) and [math] \mu \gt 0 [/math]
Gamma
  • [math]P(t) = \cfrac{1}{\Gamma(\alpha)\ \beta^{\alpha}}\ t^{\alpha-1}\ e^{-t/\beta}[/math]

where [math] \alpha ≥ 0.5 [/math] and [math] \beta \gt 0 [/math]

Note: The Chi-squared distribution is a special case of the Gamma distribution
with [math]\alpha = n/2 [/math] and [math] \beta = 2 [/math], where [math]n[/math] = degrees of freedom

Weibull
  • [math]P(t) = \alpha^{-\beta}\ \beta\ t^{\beta-1}\ e^{-(t/\alpha)^\beta}[/math]

where [math]t = \alpha (-\ln(U))^{1/\beta}[/math] and [math] \alpha ≥ 0.04 [/math] and [math] \beta ≥ 0.01 [/math]
[math]U[/math] is a randomly generated number between 0 and 1

Bernoulli
  • [math]P(t) = p^{t}\ (1-p)^{1-t} [/math]

where [math] 0 ≤ p ≤ 1 [/math]

(available in Build 137 or later)
Binomial
  • [math]P(t) = \dbinom{n}{t} p^{t}\ (1-p)^{n-t} [/math]

where [math]n[/math] is a positive integer, [math]\dbinom{n}{t} = \cfrac{n!}{t!(n-t)!}[/math] and [math] 0 \lt p ≤ 1 [/math]

(available in Build 137 or later)
Geometric
  • [math]P(t) = p\ (1-p)^{t} [/math]

where [math] 0 \lt p ≤ 1 [/math]

(available in Build 137 or later)
Exponential
  • [math]P(t) = \mu\ e^{-\mu\ t} [/math]

where [math] \mu \gt 0 [/math]

(available in Build 137 or later)
Extreme Value
  • [math]P(t) = \cfrac{1}{\beta}\ z(t)\ e^{-z(t)} [/math]
where [math]z(t) = e^{(\alpha-t)/\beta} [/math] and [math] \beta \gt 0 [/math] (available in Build 137 or later)
Log Normal
  • [math]P(t) = \cfrac{1}{s\ t\ \sqrt{2π}}\ e^{-(\ln t-m)^2/2s^2} [/math]
where [math] 0 \lt s ≤ 50.70 [/math] (available in Build 137 or later)
Cauchy
  • [math]P(t) = \cfrac{1}{π\ \beta\ \left [1+\left (\cfrac{t-\alpha}{\beta} \right )^2 \right ]} [/math]
where [math] \beta \gt 0 [/math] Example (available in Build 137 or later)
Fisher F
  • [math]P(t) = \cfrac{Γ \left (\cfrac{m+n}{2} \right )}{Γ\left (\cfrac{m}{2}\right )\ Γ\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] 1 ≤ m ≤ 100 [/math] and [math] n ≥ 1 [/math] (available in Build 137 or later)
Student t
  • [math]P(t) = \cfrac{1}{\sqrt{n\ π}}\ \cfrac{Γ\left (\cfrac{n+1}{2} \right )}{Γ\left (\cfrac{n}{2} \right )}\ \left (1+\cfrac{t^2}{n} \right )^{-(n+1)/2} [/math]
where [math] n ≥ 0.25 [/math] (available in Build 137 or later)

References

  1. Press W.H, Teukolsky S.A, Vetterling W.T, Flannery B.P Numerical Recipes in C (2nd Edition) Cambridge University Press 1992.
  2. Sanders D.H Statistics A Fresh Approach McGraw-Hill 1990.
  3. http://www.cplusplus.com/reference/random/ and related links describing each distribution.