140 likes | 164 Views
Explore random distributions, basic statistics, and generating custom distributions for modeling and simulation in CS/IT. Understand the concepts of additive and multiplicative noise, histograms, PDF, CDF, and generating random variates. Learn about seeding random variates and Java implementations.
E N D
Random Variates Dr. Jim Holten CS 351/ IT 351 Modelling and SimulationTechnologies
CS 351/ IT 351 Random Distributions • Basic Statistics • Common Random Distributions • Generating Custom Distributions • Generating Random Variates (from custom distributions)
CS 351/ IT 351 Using Random Variates • x’ = x + v • Add random “noise” to the variable’s value • Called additive noise • Commonly used • x’’ = x* v • Multiply random “noise” times variable’s value • Called multiplicative noise • Not as common • Generating Custom Distributions • Generating Random Variates (from custom distributions)
CS 351/ IT 351 Basic Statistics • min, max, count, sum (sum of squares aka sumsq can be useful too) • range = max – min • mean = Σxi / count • variance = Σ(xi– mean)2 / count • standard deviation -- σ = sqrt(variance)
CS 351/ IT 351 Other Basic Statistics • mode • The center value when all samples are in order by value • kurtosis (aka skew) κ = Σ(x[i] – mean)3, i ϵ [0, n] • histogram – a bar chart of frequency of value occurrences (usually counts of values within evenly spaced intervals).
CS 351/ IT 351 Histogram of a Set of Values • Find the min, max, and range of the values • Divide the range into k value intervals (i = 0, k - 1) (aka “buckets”), Ii =[vi, vi+1]. • Count the number of values in each interval hi = count for interval i vi ≤ v < vi+1→ hi = hi + 1 • Generally displayed as a bar chart. • The histogram bar chart defines a “shape” of value occurrence counts.
CS 351/ IT 351 Common Random Distributions • The Probability Distribution Function (PDF) shape (aka Probability Density Function) defines a distribution which matches the shape of its histogram. • Common standard distributions: Uniform, Normal, Exponential, Poisson • It can define other distribution shapes as needed. • Integrate the PDF (from -∞ to X for each value of X) to get the Cumulative Distribution Function (CDF)
CS 351/ IT 351 PDF from a Histogram • Start with the histogram. • Normalize the k counts to measured probabilities for each value interval’s counts: n = Σhj pi = hi/ n, for j ϵ [0, n-1] • This defines a probability distribution function (PDF), aka probability density function for the variable's values. • It’s shape can be compared to the common distributions for approximate matching.
CS 351/ IT 351 CDF from the PDF • Create the piecewise linear PDF from the histogram counts. • Create a CDF via cj= Σpi, for all i ≤ j for each of the k bucket value intervals. • This gives a piecewise linear CDF over the range of values for the original data.
CS 351/ IT 351 Random VariatesGeneration • Project (map) the random variates obtained from Uniform[0, 1.0) (the CDF vertical axis) to the original data values (the horizontal axis) via the CDF curve. • Use linear interpolation for “better” intermediate values.
CS 351/ IT 351 Random Variates • Math packages include a random number generator. • It must be “seeded” once, then it will generate a different random number each time it is called. • If the same seed is used then the same sequence of “random” values will be retrieved.
CS 351/ IT 351 Random Variates (via Java) • Random rand = new Random(long_seed_value) • seed the random number generator. • Do this ONCE for the entire random sequence. • value = rand.nextDouble() • retrieve one new random value • in the range [0.0, 1.0). • value = rand.nextGaussian() • retrieve one new random value • from Normal distribution, mean = 0.0, std_dev = 1.0
CS 351/ IT 351 Seeding Random Variates • The same seed generates the same sequence of random variates for a given generator. • Often the current epoch time in seconds or milliseconds is used to get a “random seed” so each run uses a different sequence of random variates. • Using the seed again starts the sequence over.
CS 351/ IT 351 Getting ANear Random Seed (Java) • Get the seed • import java.util.Date; • Date date = new Date(); • long ms_since_epoch = date.getTime(); • Seed the generator • Random rand = new Random(ms_since_epoch); • The actual sequence generated is now (somewhat) independent for each run because the time changes.