📄 nr02doc.htm
字号:
<li>Indefinite</li> <li>Missing</li></ul><p>The arithmetic functions <tt>+</tt>, <tt>-</tt>, <tt>*</tt>, <tt>/</tt> are defined inthe obvious ways, as is <tt><<</tt> for printing. The constructor can take either aReal or a value of <tt>EXT_REAL_CODE</tt> as an argument. If there is no argument theobject is given the value <i>Missing</i>. Member function <tt>IsReal()</tt> returns <i>true</i>if the enumeration value is <i>Finite</i> and in this case value of the Real can be foundwith <tt>Value()</tt>. The enumeration value can be found with member function <tt>Code()</tt>.</p><p><i>ExtReal</i> is used at the type for values returned from the <i>Mean</i> and <i>Variance</i>member functions since these values may be infinite, indefinite or missing. </p><p> </p><h2><a NAME="supporting"></a><font COLOR="#FF0000">Descriptions of the supporting classes:</font></h2><h3><font COLOR="#FF0000">ChiSq1:</font></h3><p>Non-central chi-squared with one degree of freedom. Used as part of ChiSq. </p><h3><font COLOR="#FF0000">Gamma1:</font></h3><p>This generates random numbers from a gamma distribution with shape parameter <tt>alpha< 1</tt>. Because the density is infinite at <i>x</i> = 0 a power transform isrequired. The constructor takes <tt>alpha</tt> as an argument. </p><h3><font COLOR="#FF0000">Gamma2:</font></h3><p>Gamma distribution for the shape parameter, <tt>alpha</tt>, greater than 1. Theconstructor takes <tt>alpha</tt> as the argument. </p><h3><font COLOR="#FF0000">Poisson1:</font></h3><p>Poisson distribution; derived from AsymGen. The constructor takes the mean as theargument. Used by Poisson for values of the mean greater than 10. </p><h3><font COLOR="#FF0000">Poisson2:</font></h3><p>Poisson distribution with mean less than or equal to 10. Uses DiscreteGen. Constructortakes the mean as its argument. </p><h3><font COLOR="#FF0000">Binomial1:</font></h3><p>Binomial distribution; derived from AsymGen. Used by Binomial for <tt>n >= 40</tt>.Constructor takes <i>n</i> and <i>p</i> as arguments. </p><h3><font COLOR="#FF0000">Binomial2:</font></h3><p>Binomial distribution with <tt>n < 40</tt>. Uses DiscreteGen. Constructor takes <i>n</i>and <i>p</i> as arguments. </p><h3><font COLOR="#FF0000">AddedRandom, SubtractedRandom, MultipliedRandom, ShiftedRandom,ReverseShiftedRandom, ScaledRandom, RepeatedRandom, SelectedRandom, AddedSelectedRandom:</font></h3><p>These are used by SumRandom and MixedRandom. </p><p> </p><h2><a NAME="generating"></a><font COLOR="#FF0000">Generating numbers from otherdistributions:</font></h2><table BORDER="0" CELLSPACING="4" CELLPADDING="4"> <tr> <th ALIGN="LEFT" VALIGN="TOP"><b>Distribution type</b></th> <th ALIGN="LEFT" VALIGN="TOP"><b>Method</b></th> <th ALIGN="LEFT" VALIGN="TOP"><b>Example</b></th> </tr> <tr> <td VALIGN="TOP">Continuous finite unimodal density (no parameters, can calculate density)</td> <td VALIGN="TOP">Use <a HREF="#posgenx">PosGenX</a>, <a HREF="#symgenx">SymGenX</a> or <a HREF="#asymgenx">AsymGenX</a>.</td> <td VALIGN="TOP"></td> </tr> <tr> <td VALIGN="TOP">Continuous finite unimodal density (with parameters, can calculate density)</td> <td VALIGN="TOP">Derive a new class from <a HREF="#posgen">PosGen</a>, <a HREF="#symgen">SymGen</a> or <a HREF="#asymgen">AsymGen</a>, over-ride <i>Density</i>.</td> <td VALIGN="TOP">Gamma2</td> </tr> <tr> <td VALIGN="TOP">Can calculate inverse of distribution</td> <td VALIGN="TOP">Transform <a HREF="#random">uniform random</a> number.</td> <td VALIGN="TOP">Pareto</td> </tr> <tr> <td VALIGN="TOP">Transformation of supported random number</td> <td VALIGN="TOP">Derive a new class from the existing class</td> <td VALIGN="TOP">ChiSq1</td> </tr> <tr> <td VALIGN="TOP">Transformation of several random numbers</td> <td VALIGN="TOP">Derive new class from <a HREF="#random">Random</a>; generate the new random number from the existing generators.</td> <td VALIGN="TOP">ChiSq</td> </tr> <tr> <td VALIGN="TOP">Density with infinite singularity</td> <td VALIGN="TOP">Transform a random variable generated by <a HREF="#posgen">PosGen</a>, <a HREF="#symgen">SymGen</a> or <a HREF="#asymgen">AsymGen</a>.</td> <td VALIGN="TOP">Gamma1</td> </tr> <tr> <td VALIGN="TOP">Distribution with several modes</td> <td VALIGN="TOP">Breakdown into a <a HREF="#mixed">mixture</a> of unimodal distributions.</td> <td VALIGN="TOP"></td> </tr> <tr> <td VALIGN="TOP">Linear or quadratic combination of supported random numbers</td> <td VALIGN="TOP">Use <a HREF="#sum">SumRandom</a>.</td> <td VALIGN="TOP"></td> </tr> <tr> <td VALIGN="TOP">Mixture of supported random numbers</td> <td VALIGN="TOP">Use <a HREF="#mixed">MixedRandom</a>.</td> <td VALIGN="TOP"></td> </tr> <tr> <td VALIGN="TOP">Discrete distribution (< 100 possible values)</td> <td VALIGN="TOP">Use <a HREF="#discretegen">DiscreteGen</a>.</td> <td VALIGN="TOP">Poisson2</td> </tr> <tr> <td VALIGN="TOP">Discrete distribution (many possible values)</td> <td VALIGN="TOP">Use <a HREF="#posgen">PosGen</a>, <a HREF="#symgen">SymGen</a> or <a HREF="#asymgen">AsymGen</a>.</td> <td VALIGN="TOP">Poisson1</td> </tr></table><p> </p><h2><a NAME="other"></a><font COLOR="#FF0000">Other people's code:</font></h2><p>The gamma function and Shell sort routines are adapted from <i>Numerical Recipes in C</i>by Press, Flannery, Teukolsky, Vetterling published by the Cambridge University Press. </p><p> </p><h2><a NAME="files"></a><font COLOR="#FF0000">Files included in this package:</font></h2><table BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%"> <tr> <td VALIGN="TOP">readme.txt</td> <td VALIGN="TOP">readme file</td> </tr> <tr> <td VALIGN="TOP">newran.htm</td> <td VALIGN="TOP">this file</td> </tr> <tr> <td VALIGN="TOP">newran.h</td> <td VALIGN="TOP">header file for <i>newran</i></td> </tr> <tr> <td VALIGN="TOP">newran.cpp</td> <td VALIGN="TOP">main code file</td> </tr> <tr> <td VALIGN="TOP">extreal.h</td> <td VALIGN="TOP">header file for <i>extended reals</i></td> </tr> <tr> <td VALIGN="TOP">extreal.cpp</td> <td VALIGN="TOP">code file for <i>extended reals</i></td> </tr> <tr> <td VALIGN="TOP">boolean.h</td> <td VALIGN="TOP">definition of <i>bool</i></td> </tr> <tr> <td VALIGN="TOP">include.h</td> <td VALIGN="TOP">option file</td> </tr> <tr> <td VALIGN="TOP">tryrand.cpp</td> <td VALIGN="TOP">test file</td> </tr> <tr> <td VALIGN="TOP">tryrand1.cpp</td> <td VALIGN="TOP">called by tryrand - histograms of simple examples</td> </tr> <tr> <td VALIGN="TOP">tryrand2.cpp</td> <td VALIGN="TOP">called by tryrand - histograms of advanced examples</td> </tr> <tr> <td VALIGN="TOP">tryrand3.cpp</td> <td VALIGN="TOP">called by tryrand - statistical tests</td> </tr> <tr> <td VALIGN="TOP">tryrand4.cpp</td> <td VALIGN="TOP">called by tryrand - test permutations</td> </tr> <tr> <td VALIGN="TOP">hist.cpp</td> <td VALIGN="TOP">called by tryrand - draw histogram</td> </tr> <tr> <td VALIGN="TOP">tryrand.txt</td> <td VALIGN="TOP">output from tryrand</td> </tr> <tr> <td VALIGN="TOP">nrcc.mak</td> <td VALIGN="TOP">make file for CC compiler</td> </tr> <tr> <td VALIGN="TOP">nrgnu.mak</td> <td VALIGN="TOP">make file for gnu G++ compiler</td> </tr> <tr> <td VALIGN="TOP">nrwat.mak</td> <td VALIGN="TOP">makefile for Watcom 32 bit 10a compiler</td> </tr></table><p> </p><h2><a NAME="class"></a><font COLOR="#FF0000">Class structure:</font></h2><p>The following diagram gives the class hierarchy of the package. </p><pre><font SIZE="-1"><b>ExtReal</b>.......................... <i>Extended real numbers</i><b>Random</b>........................... Uniform random number generator | +---Constant.................... Return a constant | +---PosGen...................... Used by PosGenX etc | | | +---PosGenX................ Positive random #s from decreasing density | | | +---Exponential............ Negative exponential rng | | | +---Gamma1................. Used by Gamma (shape parameter < 1) | | | +---SymGen................. Used by SymGenX etc | | | +---SymGenX........... Random numbers from symmetric density | | | +---Cauchy............ Cauchy random number generator | | | +---Normal............ Standard normal random number generator | | | +---ChiSq1....... Used by ChiSq (one df) | +---AsymGen..................... Used by AsymGenX etc | | | +---AsymGenX............... Random numbers from asymmetric density | | | +---Poisson1............... Used by Poisson (mean > 8) | | | +---Binomial1.............. Used by Binomial (n >= 40) | | | +---NegativeBinomial....... Negative binomial random number generator | | | +---Gamma2................. Used by Gamma (shape parameter > 1) | +---ChiSq....................... Non-central chi-squared rng | +---Gamma....................... Gamma random number generator | +---Pareto...................... Pareto random number generator | +---DiscreteGen................. Discrete random number generator | +---Poisson2.................... Used by Poisson (mean <= 8) | +---Binomial2................... Used by Binomial (n < 40) | +---Poisson..................... Poisson random number generator | +---Binomial.................... Binomial random number generator | +---SumRandom................... Sum of random numbers | +---MixedRandom................. Mixture of random numbers | +---MultipliedRandom............ Used by SumRandom | | | +---AddedRandom............ Used by SumRandom | | | +---SubtractedRandom....... Used by SumRandom | +---ShiftedRandom............... Used by SumRandom | | | +---ReverseShiftedRandom... Used by SumRandom | | | +---ScaledRandom........... Used by SumRandom | +---NegatedRandom.......... .... Used by SumRandom | +---RepeatedRandom.............. Used by SumRandom | +---AddedSelectedRandom......... Used by MixedRandom | +---SelectedRandom.............. Used by MixedRandom<b>RandomPermutation</b>................ Random permutation | +---RandomCombination........... Sorted random permutation</font></pre><p> </p><h2><a NAME="todo"></a><font COLOR="#FF0000">To do:</font></h2><ul> <li>More modern alternatives to the <a HREF="#random">LGM generator</a>;</li> <li>Additional generator classes;</li> <li>Better methods for combinations and permutations with large <tt>N</tt> and small <tt>M</tt>;</li> <li>An alternative (slower) class for Poisson with short setup time.</li></ul><p> </p><h2><a name="history"></a><font COLOR="#FF0000">History:</font></h2><p>August, 1998 - update exception package; work around problem with MS VC++ 5</p><p>January, 1998 - version compatible with newmat09</p><p>1995 - <em>newran</em> version, additional distributions</p><p>1989 - initial version</p><hr><p><a HREF="#top">Go to top</a> </p><p><a HREF="ol_doc.htm">To online documentation page</a> </p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -