Difference between revisions of "Random"

m
 
(7 intermediate revisions by 2 users not shown)
Line 2: Line 2:
 
[[Category:Doc Status C]] <!-- For Lumina use, do not change -->
 
[[Category:Doc Status C]] <!-- For Lumina use, do not change -->
 
   
 
   
Function Random generates a single random value from a probability distribution. It is not a probability distribution ''per se'', such as Normal() or Uniform(). It generates a single value, not a sample indexed by Run, and it does so whether evaluated in a deterministic (Mid) or probabilistic context. For example.
+
__TOC__
Random(Normal(10, 2))
 
generates a single value generated at random from the specified Normal distribution.
 
Random()
 
with no parameters, it returns a single uniformly-distributed random number between 0 and 1.
 
  
== Declaration ==
+
==Random(''dist, method, over'')==
  
Random(dist: Optional Unevaluated; method: Optional Scalar; over: ... Optional Index)
+
Function [[Random]] generates a single random value from a probability distribution. It is not a probability distribution ''per se'', such as [[Normal]]() or [[Uniform]](). It generates a single value, not a sample indexed by [[Run]], and it does so whether evaluated in a deterministic ([[Mid]]) or probabilistic context. For example.
 +
:<code>Random(Normal(10, 2))</code>
  
Parameters:
+
generates a single value generated at random from the specified [[Normal]] distribution. [[Random]]() with no parameters returns a single uniformly-distributed random number between 0 and 1.
* '''''dist''''' : If specified, must be an explicit call to a distribution function that supports single-sample generation (see below).  If you specify no distribution, it defaults to Uniform(0,1). If dist is a multivariate distribution, indexed by I, it truents
 
* '''''method''''' Selects the algorithm used to generate the random number.  Possible value are:  0=use system default, 1=Minimal standard, 2=L'Ecuyer, 3=Knuth.
 
* '''''over:''''' A convenient way to list indexes that independent random numbers will be generated over.  (This will also occur if the index(es) occur in any of the other parameters).
 
  
== Description ==
+
Because there is often a need to access a random number generator stream, such as for rejection sampling, Metropolis-Hastings simulation, etc,  [[Random]]() makes it possible to get such values, even if the global sampling method is Latin hypercube, and efficiently since it isn't necessary to generate an entire sample.  [[Random]] can return variates from a wide variety of distributions.  It is even possible to write user-defined distribution functions for custom distributions that work with random.
  
Random is not a distribution-function per-se, as Uniform(0,1) is.  However, one often needs access to a random number generator stream, such as for rejection sampling, Metropolis-Hastings simulation, etc.  Random() makes it possible to get such values, even if the global sampling method is Latin hypercube, and efficiently since it isn't necessary to generate an entire sample. Random can return variates from a wide variety of distributions. It is even possible to write user-defined distribution functions for custom distributions that work with random.
+
The full declaration of  the function is
 +
:[[Random]](''dist'': Optional Unevaluated; ''method'': Optional Scalar; ''over'': ... Optional Index)
  
== Examples ==
+
==Optional parameters==
 +
===Dist===
 +
If specified, «dist» must be a call to a distribution function that supports single-sample generation (most do, but see below).  If you specify no distribution, it defaults to [[Uniform]](0,1). If «dist» is a multivariate distribution, indexed by <code>I</code>, it returns an array of random samples indexed by <code>I</code>.
  
Random(Uniform(-100, 100)):  Returns a single real-valued random number uniformly selected between -100 and 100.
+
===Method===
 +
Selects the algorithm used to generate the random number. Possible value are:
 +
:<code>0</code>: use system default
 +
:<code>1</code>: Minimal standard
 +
:<code>2</code>: L'Ecuyer
 +
:<code>3</code>: Knuth
  
Random(Uniform(1, 100, integer: True)): Returns a random integer between 1 and 100 inclusive.
+
===Over===
  
Random(Over: I): Returns an array of independent uniform random numbers between 0 and 1 indexed by IThe numbers are independent (i.e., Monte Carlo sampled, never Latin Hypercube).
+
Give it an index or list of indexes. Random will choose an independent random number for each index value, or combination of index valuesIt also does this if any of the other parameters is an array with one or more indexes.
  
  Random(Over: I, J): Returns a 2-D array of independent uniform random numbers between 0 and 1, indexed by I and J.  All numbers in the array are sampled independently.
+
== Examples ==
 +
:<code>Random(Uniform(-100, 100))</code>  
 +
::Returns a single real-valued random number uniformly selected between -100 and 100.
 +
:<code>Random(Uniform(1, 100, integer: True))</code>
 +
::Returns a random integer between 1 and 100 inclusive.
 +
:<code>Random(Over: I)</code>
 +
::Returns an array of independent uniform random numbers between 0 and 1 indexed by <code>I</code>.  The numbers are independent (i.e., Monte Carlo sampled, never Latin Hypercube).
 +
:<code>Random(Over: I, J)</code>
 +
::Returns a 2-D array of independent uniform random numbers between 0 and 1, indexed by <code>I</code> and <code>J</code>.  All numbers in the array are sampled independently.
 +
:<code>Random(Uniform(min: Array(I, J, 0), max: 1))</code>
 +
::This is functionally equivalent to the preceding example. It demonstrates how the «over» parameter is only a convenience, but results in an easier to interpret syntax.
  
Random(Uniform(min: Array(I, J, 0), max: 1)): This is functionally equivalent to the preceding example. It demonstrates how the Over parameter is only a convenience, but results in an easier to interpret syntax.[[Category:Distribution Functions]]
+
==Details and more examples==
[[Category:Doc Status C]]
+
=== Distribution function support for single samples ===
 +
Random supports only those distribution functions with parameter «singleMethod», usually declared as:  
 +
:<code>singleSampleMethod: Optional Atomic Numeric</code>
  
=== Distribution Function Support for Single Samples ===
+
When the parameter is provided, the distribution function must return a single random variate from the distribution indicated by the other parameters.  Random will fill in this parameter with one of the following values, indicating which sampling method should be used:
 +
Possible values for «singleMethod»:
 +
:<code>0</code>: use default method
 +
:<code>1</code>: use Minimal standard
 +
:<code>2</code>: use L'Ecuyer
 +
:<code>3</code>: use Knuth
  
Random supports only those distribution functions with parameter singleMethod, usually declared as:  
+
As an example, consider what happens when <code>Random(Normal(2, 3))</code> is evaluated.  The [[Random]] function checks that its parameter is an acceptable distribution function, and then it evaluates:
singleSampleMethod: Optional Atomic Numeric
+
:<code>Normal(2, 3, singleSampleMethod: 0)</code>
  
When the parameter is provided, the distribution function must return a single random variate from the distribution indicated by the other parameters.  Random will fill in this parameter with one of the following values, indicating which sampling method should be used:
+
User-defined functions can support single-variate generation, and therefore can be used as a parameter to [[Random]], if they have a parameter named «singleMethod».
Possible values for singleMethod:
 
0 = use default method
 
1 = use Minimal standard
 
2 = use L'Ecuyer
 
3 = use Knuth
 
  
As an example, consider what happens when Random(Normal(2,3)) is evaluated.  The Random function checks that its parameter is an acceptable distribution function, and then it evaluates:
+
===Functions supported===
  Normal(2, 3, singleSampleMethod: 0)
+
[[Random]](dist) supports any of these built-in probability distributions functions as the distribution:
Random(dist) supports any of these built-in probability distributions functions as the distribution:
+
<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
 
* [[Bernoulli]]
 
* [[Bernoulli]]
 
* [[Beta]]
 
* [[Beta]]
Line 67: Line 81:
 
* [[Uniform]]
 
* [[Uniform]]
 
* [[Weibull]]
 
* [[Weibull]]
 +
</div>
  
 
It also works for these distributions from the ''Distribution variations'' library:
 
It also works for these distributions from the ''Distribution variations'' library:
 +
<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
 
* [[Beta_m_sd]]
 
* [[Beta_m_sd]]
 
* [[Erlang]]
 
* [[Erlang]]
 
* [[Gamma_m_sd]]
 
* [[Gamma_m_sd]]
 
* [[InverseGaussian]]
 
* [[InverseGaussian]]
* LogNormal_m_sd (but note that this one is superceded by LogNormal)
+
* [[Lognormal_m_sd]] (but note that this one is superseded by [[LogNormal]])
 
* [[Lorenzian]]
 
* [[Lorenzian]]
 
* [[NegBinomial]]
 
* [[NegBinomial]]
Line 81: Line 97:
 
* [[Smooth_Fractile]]
 
* [[Smooth_Fractile]]
 
* [[Wald]]
 
* [[Wald]]
 +
</div>
  
 
It also works for these distributions from the ''Multivariate Distributions'' library:
 
It also works for these distributions from the ''Multivariate Distributions'' library:
 +
<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
 
* [[BiNormal]]
 
* [[BiNormal]]
 
* [[Dirichlet]]
 
* [[Dirichlet]]
Line 97: Line 115:
 
* [[Normal_serial_correl]]
 
* [[Normal_serial_correl]]
 
* [[UniformSpherical]]
 
* [[UniformSpherical]]
 +
</div>
  
Random does not support these built-in distribution functions:
+
===Functions not supported===
 +
[[Random]] does not support these built-in distribution functions:
 +
<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
 
* [[ChanceDist]]
 
* [[ChanceDist]]
 
* [[Fractiles]]
 
* [[Fractiles]]
 
* [[ProbDist]]
 
* [[ProbDist]]
 
* [[Truncate]]
 
* [[Truncate]]
 +
</div>
  
User-defined functions can support single-variate generation, and therefore can be used as a parameter to Random, if they have a parameter named singleMethod.
+
== See Also ==
 
+
* [[RandomType]]
= See Also =
 
 
 
 
* [[Shuffle]]
 
* [[Shuffle]]
 
* [[Sample]]
 
* [[Sample]]
 +
* [[Distribution Functions]]
 +
* [[Distribution Densities Library]]

Latest revision as of 20:01, 13 April 2016


Random(dist, method, over)

Function Random generates a single random value from a probability distribution. It is not a probability distribution per se, such as Normal() or Uniform(). It generates a single value, not a sample indexed by Run, and it does so whether evaluated in a deterministic (Mid) or probabilistic context. For example.

Random(Normal(10, 2))

generates a single value generated at random from the specified Normal distribution. Random() with no parameters returns a single uniformly-distributed random number between 0 and 1.

Because there is often a need to access a random number generator stream, such as for rejection sampling, Metropolis-Hastings simulation, etc, Random() makes it possible to get such values, even if the global sampling method is Latin hypercube, and efficiently since it isn't necessary to generate an entire sample. Random can return variates from a wide variety of distributions. It is even possible to write user-defined distribution functions for custom distributions that work with random.

The full declaration of the function is

Random(dist: Optional Unevaluated; method: Optional Scalar; over: ... Optional Index)

Optional parameters

Dist

If specified, «dist» must be a call to a distribution function that supports single-sample generation (most do, but see below). If you specify no distribution, it defaults to Uniform(0,1). If «dist» is a multivariate distribution, indexed by I, it returns an array of random samples indexed by I.

Method

Selects the algorithm used to generate the random number. Possible value are:

0: use system default
1: Minimal standard
2: L'Ecuyer
3: Knuth

Over

Give it an index or list of indexes. Random will choose an independent random number for each index value, or combination of index values. It also does this if any of the other parameters is an array with one or more indexes.

Examples

Random(Uniform(-100, 100))
Returns a single real-valued random number uniformly selected between -100 and 100.
Random(Uniform(1, 100, integer: True))
Returns a random integer between 1 and 100 inclusive.
Random(Over: I)
Returns an array of independent uniform random numbers between 0 and 1 indexed by I. The numbers are independent (i.e., Monte Carlo sampled, never Latin Hypercube).
Random(Over: I, J)
Returns a 2-D array of independent uniform random numbers between 0 and 1, indexed by I and J. All numbers in the array are sampled independently.
Random(Uniform(min: Array(I, J, 0), max: 1))
This is functionally equivalent to the preceding example. It demonstrates how the «over» parameter is only a convenience, but results in an easier to interpret syntax.

Details and more examples

Distribution function support for single samples

Random supports only those distribution functions with parameter «singleMethod», usually declared as:

singleSampleMethod: Optional Atomic Numeric

When the parameter is provided, the distribution function must return a single random variate from the distribution indicated by the other parameters. Random will fill in this parameter with one of the following values, indicating which sampling method should be used: Possible values for «singleMethod»:

0: use default method
1: use Minimal standard
2: use L'Ecuyer
3: use Knuth

As an example, consider what happens when Random(Normal(2, 3)) is evaluated. The Random function checks that its parameter is an acceptable distribution function, and then it evaluates:

Normal(2, 3, singleSampleMethod: 0)

User-defined functions can support single-variate generation, and therefore can be used as a parameter to Random, if they have a parameter named «singleMethod».

Functions supported

Random(dist) supports any of these built-in probability distributions functions as the distribution:

It also works for these distributions from the Distribution variations library:

It also works for these distributions from the Multivariate Distributions library:

Functions not supported

Random does not support these built-in distribution functions:

See Also

Comments


You are not allowed to post comments.