12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <html lang="en">
- <head>
- <title>mtwist calling conventions - avram - a virtual machine code interpreter</title>
- <meta http-equiv="Content-Type" content="text/html">
- <meta name="description" content="avram - a virtual machine code interpreter">
- <meta name="generator" content="makeinfo 4.13">
- <link title="Top" rel="start" href="index.html#Top">
- <link rel="up" href="mtwist.html#mtwist" title="mtwist">
- <link rel="prev" href="mtwist.html#mtwist" title="mtwist">
- <link rel="next" href="mtwist-exceptions.html#mtwist-exceptions" title="mtwist exceptions">
- <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
- <meta http-equiv="Content-Style-Type" content="text/css">
- <style type="text/css"><!--
- pre.display { font-family:inherit }
- pre.format { font-family:inherit }
- pre.smalldisplay { font-family:inherit; font-size:smaller }
- pre.smallformat { font-family:inherit; font-size:smaller }
- pre.smallexample { font-size:smaller }
- pre.smalllisp { font-size:smaller }
- span.sc { font-variant:small-caps }
- span.roman { font-family:serif; font-weight:normal; }
- span.sansserif { font-family:sans-serif; font-weight:normal; }
- --></style>
- </head>
- <body>
- <div class="node">
- <a name="mtwist-calling-conventions"></a>
- <p>
- Next: <a rel="next" accesskey="n" href="mtwist-exceptions.html#mtwist-exceptions">mtwist exceptions</a>,
- Previous: <a rel="previous" accesskey="p" href="mtwist.html#mtwist">mtwist</a>,
- Up: <a rel="up" accesskey="u" href="mtwist.html#mtwist">mtwist</a>
- <hr>
- </div>
- <h4 class="subsection">D.12.1 <code>mtwist</code> calling conventions</h4>
- <p>All of the functions in this library simulate a random draw from a
- distribution. There is a choice of distribution statistics depending
- on the function used.
- <dl>
- <dt><code>bern</code><dd>takes a floating point number <var>p</var> between 0 and 1, encoded as in
- <a href="math.html#math">math</a>, and returns a boolean value, either <code>(nil,nil)</code> for
- true or <code>nil</code> for false. A true value is returned only if a
- random draw from a uniform distribution ranging from 0 to 1 is less
- than <var>p</var>. This function therefore simulates a draw from a
- Bernoulli distribution. A <code>nil</code> value of <var>p</var> is treated as
- 1/2.
- <br><dt><code>u_cont</code><dd>takes a floating point number <var>x</var> as an
- argument, and returns a random draw from a continuous uniform
- distribution ranging from 0 to <var>x</var>. A <code>nil</code> value of <var>x</var>
- is treated as unity.
- <br><dt><code>u_disc</code><dd>simulates a draw from a uniform discrete distribution whose domain
- is the set of natural numbers from 0 to <var>n</var> - 1. The number <var>n</var>
- is given as a parameter to this function, and the retuned value
- is the draw.
- <ul>
- <li>The returned value will have at most 64 bits regardless of <var>n</var>.
- <li>Natural numbers are encoded as described in
- <a href="Representation-of-Numeric-and-Textual-Data.html#Representation-of-Numeric-and-Textual-Data">Representation of Numeric and Textual Data</a>.
- <li>If a value of 0 is passed for <var>n</var>, the full 64 bit range is
- used.
- </ul>
- <br><dt><code>u_path</code><dd>takes a pair of natural numbers <code>(</code><var>n</var><code>,</code><var>m</var><code>)</code> and returns a
- randomly chosen tree (<a href="Raw-Material.html#Raw-Material">Raw Material</a>) with 1 leaf and <var>n</var>
- non-leaves each having either a left or a right descendent but not
- both. The number <var>m</var> constrains the result to fall within the
- first <var>m</var> - 1 trees of this form enumerated by exhausting all
- possibilities at lower levels before admitting a right descendent at a
- higher level. Within these criteria, all possible results are equally
- probable. Both numbers are masked to 64 bits, but if <var>m</var> is zero,
- it is treated as 2^<var>n</var>.
- <br><dt><code>u_enum</code><dd>simulates a random draw from a uniform discrete distribution whose
- domain is enumerated. The argument to the function is a non-empty list,
- and the result is an item selected from the list, with all choices
- being equally probable.
- <br><dt><code>w_disc</code><dd>simulates a random draw from a non-uniform, or “weighted” discrete
- distribution whose domain is a set of consecutive natural numbers
- starting from zero. The argument to the function is a list giving the
- probability of each outcome starting from zero as a floating point
- number. Probabilities must be non-negative but needn't be normalized.
- <br><dt><code>w_enum</code><dd>simulates a random draw from a non-uniform, or “weighted” discrete
- distribution with an arbitrary domain enumerated in the argument. The
- argument is a list of pairs <code><(</code><var>x</var><code>,</code><var>p</var><code>)..></code>, where
- <var>x</var> is a possible outcome and <var>p</var> is its probability. The
- result returned is one of the values of <var>x</var> from the input list
- chosen at random according to the associated
- probability. Probabilities must be non-negative but needn't be
- normalized.
- </dl>
- </body></html>
|