Difference between revisions of "Random"

Line 9: Line 9:
 
:<code>Random(Normal(10, 2))</code>
 
:<code>Random(Normal(10, 2))</code>
  
generates a single value generated at random from the specified Normal distribution.
+
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.
:<code>Random()</code>
 
  
with no parameters, it 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.
  
== Declaration ==
+
The full declaration of  the function is
 +
:[[Random]](''dist'': Optional Unevaluated; ''method'': Optional Scalar; ''over'': ... Optional Index)
  
  Random(dist: Optional Unevaluated; method: Optional Scalar; over: ... Optional Index)
+
==Optional parameters==
 +
===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 <code>I</code>, it truants
  
Parameters:
+
===Method===
* «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
+
Selects the algorithm used to generate the random number.  Possible value are:  
* «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.
+
:<code>0</code>: use system default
* «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).
+
:<code>1</code>: Minimal standard
 +
:<code>2</code>: L'Ecuyer
 +
:<code>3</code>: Knuth
  
== Description ==
+
===Over===
 
+
A convenient way to list indexes that independent random numbers will be generated overThis will also occur if the index(es) occur in any of the other parameters.
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, etcRandom() 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.
 
  
 
== Examples ==
 
== 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.
  
:<code>Random(Uniform(-100, 100))</code>  Returns a single real-valued random number uniformly selected between -100 and 100.
+
==Details and more examples==
 
+
=== Distribution function support for single samples ===
Random(Uniform(1, 100, integer: True)): Returns a random integer between 1 and 100 inclusive.
+
Random supports only those distribution functions with parameter «singleMethod», usually declared as:  
 
+
:<code>singleSampleMethod: Optional Atomic Numeric</code>
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.[[Category:Distribution Functions]]
 
[[Category:Doc Status C]]
 
 
 
=== 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:
 
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:
+
Possible values for «singleMethod»:
0 = use default method
+
:<code>0</code>: use default method
1 = use Minimal standard
+
:<code>1</code>: use Minimal standard
2 = use L'Ecuyer
+
:<code>2</code>: use L'Ecuyer
3 = use Knuth
+
:<code>3</code>: use Knuth
  
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:
+
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:
 
:<code>Normal(2, 3, singleSampleMethod: 0)</code>
 
:<code>Normal(2, 3, singleSampleMethod: 0)</code>
  
Random(dist) supports any of these built-in probability distributions functions as the distribution:
+
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:
 
<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
 
<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
 
* [[Bernoulli]]
 
* [[Bernoulli]]
Line 83: Line 88:
 
* [[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 superceded by [[LogNormal]])
 
* [[Lorenzian]]
 
* [[Lorenzian]]
 
* [[NegBinomial]]
 
* [[NegBinomial]]
Line 111: Line 116:
 
</div>
 
</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">
 
<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
 
* [[ChanceDist]]
 
* [[ChanceDist]]
Line 119: Line 125:
 
</div>
 
</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 =
+
== See Also ==
 +
* [[RandomType]]
 
* [[Shuffle]]
 
* [[Shuffle]]
 
* [[Sample]]
 
* [[Sample]]

Revision as of 18:45, 13 January 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, 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 truants

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.

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.