📄 swarm.random.sgml.reference.html
字号:
><P>A `split' generator is a long-period generator forwhich we are able to split the period into arbitrary sub-periods,which we can access quickly. We then configure the generator ashaving a number (A) of `virtual generators', each of which can addressa number (2^v) of sub-segments of length 2^w. These parameters(A,v,w) are user selectable when the generator is created. (As anexample, for C4LCGXgen the default values are A=128, v=31, w=41.) Theadvantage is that the subsegments act as statistically independentstreams of random numbers.</P></LI><LI><P>In addition to the -getUnsignedSample method,generators now also supply floating point output in the range[0.0,1.0), in the form of these methods:<TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> -(float) getFloatSample; // using 1 unsigned value -(double) getThinDoubleSample; // using 1 unsigned value -(double) getDoubleSample; // using 2 unsigned values -(long double) getLongDoubleSample; // using 2 unsigned values</PRE></TD></TR></TABLE>Note that the last method is not portable across architectures, sincethe length of a long double varies between machines.</P></LI><LI><P>Generators may now be started with a single seed, *or*with a vector of seeds whose length is generator dependent. (PMMLCGrequires 1 integer for a seed, while MT19937 needs 624 ofthem.)</P></LI><LI><P>Generators now remember what seed values they werestarted with. They also count how many variates they have delivered(i.e., how many calls to -getUnsignedSample they haveserviced.)</P></LI><LI><P>There are a few arbitrary seed values, DEFAULTSEED,DEFAULTSEED1, DEFAULTSEED2, DEFAULTSEED3, DEFAULTSEED4 defined. Thereis also the value FIRSTSEED, which returns the value that the defaultgenerator `randomGenerator' was started with.</P></LI><LI><P>The macro NEXTSEED will generate a deterministicsequence of seed values, using and inline LCG and starting withFIRSTSEED. There is the macro RANDOMSEED, which will be differentevery time it is invoked because it depends on program time. Andthere is value STARTSEED, which will by default equal NEXTSEED, butwill instead be equal to RANDOMSEED if you start your program with the<TTCLASS="OPTION">--varyseed</TT> or <TTCLASS="OPTION">-s</TT> command lineparameter.</P></LI><LI><P>The generators have gained a new creation method,'+createWithDefaults: aZone', which creates the generator andinitializes it with STARTSEED. Split generators get default values forA,v,w.</P></LI></UL></P></DIV><DIVCLASS="FORMALPARA"><P><B>Version 0.7: Changes since version 0.6. </B><P></P><UL><LI><P>The generator classes have changed names to where theyall end in '-gen'. A simple search-and-replace in your code will getyou up and running again.(Or perhaps you'll want to try one of the newgenerators?)</P></LI><LI><P>A bug in SWBgen was corrected. Code for ACG and SCGwas also changed.</P></LI><LI><P>The <TTCLASS="FUNCTION">-verifySelf</TT> method isgone. Instead see the test program located in<TTCLASS="FILENAME">/random/testR0</TT>. (Available in a separate tarballat the SFI ftp site.)</P></LI><LI><P>The `getState:' method has been named `putStateInto:(void *) buffer', and the `setState:' method is now `setStateFrom:(void *) buffer'. A quick search-and-replace fixes things in yourcode.</P></LI><LI><P>Note: these methods have also changed somewhat, as hasthe size of the data being saved. As a result, v. 0.7 generators willrefuse to `setStateFrom' data saved by v. 0.6objects.</P></LI><LI><P>There should be fewer changes like this in the nextrelease.</P></LI></UL></P></DIV><DIVCLASS="FORMALPARA"><P><B>Testing Generators. </B> Since v. 0.6 we have done some rudimentary statistical testingof the implemented generators, using Marsaglia's Diehard tests and theENT tests. The results of these tests are summarized in Generatorquality table (now found in the <AHREF="http://www.swarm.org"TARGET="_top"><ICLASS="CITETITLE">Swarm User Guide</I></A>), where test results aswell as period length, state size and execution times are listed. Youcan use these data to select a generator that suits yoursimulation. Some brief comments:<P></P><OLTYPE="a"><LI><P> the tests show that old generators SCG and LCG are ofpoor quality and should be avoided.</P></LI><LI><P> the lagged-Fibonacci based generators (ACG, SWB,PSWB) all fail Diehard's `Birthday spacings test', for reasons havingto do with their lattice structure. These generators are onlyconditionally recommended.</P></LI><LI><P> The rest of the 32-bit generators (i.e. generatorsthat fill all 32 bits of an unsigned int) pass all tests, and arerecommended at this time. (Note that while a test may show that agenerator is bad, passing a number of tests does not prove that agenerator is good!) </P></LI><LI><P> The 31-bit generators all fail the same set oftests. Some of these cannot be passed by a generator whose output hasa `stuck' bit. Until I clear up with Prof. Marsaglia how to interpretthese results, I believe all the 31-bit generators are in the`recommended' category.</P></LI><LI><P>However, a cautionary note: while the PMMLCGgenerators pass the tests, they have a very short period ( less than2^31 ) and should only be used for `toy' simulations. You don't wantyour generator(s) to `go around' and start repeating themselves!</P></LI><LI><P>For what it's worth, Professor L'Ecuyer recommends hisown C4LCGX and C2MRG3 generators as well as Matsumoto's TT800 (themonster MT19937 hadn't been released yet), and Prof. Marsagliarecommends his own Multiply-With-Carry generators (MWCA, MWCB, C3MWC,RWC2, RWC8="Mother").</P></LI></OL></P></DIV></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN13021">5.3. Implementation notes for Distributions</A></H2><DIVCLASS="FORMALPARA"><P><B>Version 0.8: Changes over version 0.75. </B>No functional changes were made. Code was rearranged to conformto create-phase protocol (CREATING-SETTING-USING) ordering.</P></DIV><DIVCLASS="FORMALPARA"><P><B>Version 0.75: Changes over version 0.7. </B>No functional changes were made.</P></DIV><DIVCLASS="FORMALPARA"><P><B>Version 0.7: Improvements over version 0.6. </B><P></P><UL><LI><P>One new distribution class, BernoulliDist, has beenadded. It returns binary values (yes/true/1) with a given probability(while the old RandomBitDist has a fixed 50% probability, a fair cointoss.)</P></LI><LI><P>Distributions now have a new create method,'+createWithDefaults: aZone'. This method creates the distributionobject, and also a new generator object for its exclusive use. Eachdistribution class has a different default generator classassigned. These generators are initialized with STARTSEED, which bydefault equals the fixed value DEFAULTSEED, but will be equal to thevarying RANDOMSEED if you start your program with the command lineparameter <TTCLASS="OPTION">--varyseed</TT> or<TTCLASS="OPTION">-s</TT>.</P></LI><LI><P>All distributions have code to interact with the new`split' generators.</P></LI><LI><P>UniformIntegerDist and UniformUnsignedDist now allowyou to set parameter minValue equal to maxValue. In this case thatvalue is returned every time.</P></LI><LI><P>UniformDoubleDist also allows this, even if the set[x,x) is mathematically suspect ...</P></LI><LI><P>NormalDist and LogNormalDist now allow you to specifyzero Variance, in which case the values returned are the Mean andexp(Mean) respectively.</P></LI></UL> </P></DIV><DIVCLASS="FORMALPARA"><P><B>Version 0.7: Changes since version 0.6. </B><P></P><UL><LI><P>The distribution classes have changed names to wherethey all end in `Dist'. A simple search-and-replace in your code willget you back up and running.</P></LI><LI><P>The strong distinction between `frozen' and`un-frozen' distribution objects in v. 0.6 has been softenedconsiderably. You may now set and reset the default parameters asoften as you wish, and you may make calls for variates with givenparameters even if different default parameters have beenset.</P></LI><LI><P>The generation of uniform(0,1) floating point valueshas been moved from the distribution objects into the generatorobjects. Thus, if all you need is a uniform(0,1) double, you have noneed of a distribution but can get what you desire from agenerator.</P></LI><LI><P>Note that the generators fill the mantissa of a doublefrom two 32-bit unsigned values in a different manner from v. 0.6distributions, so output will be a bit different in the newversion.</P></LI><LI><P>A bug in LogNormalDist has beenfixed.</P></LI><LI><P>The `getState:' method has been named `putStateInto:(void *) buffer', and the `setState:' method is now `setStateFrom:(void *) buffer. A quick search-and-replace fixes things in yourcode.</P></LI><LI><P>But note: these methods have also changed somewhat, ashas the size of the data being saved. As a result, v. 0.7distributions will refuse to `setStateFrom' data saved by v. 0.6objects.</P></LI></UL> </P></DIV><DIVCLASS="FORMALPARA"><P><B>Utility Objects Provided. </B>The following objects have been defined in<TTCLASS="FILENAME">random/random.m</TT>. They may be accessed and usedfrom anywhere in your program.<TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="100%"><TR><TD><PRECLASS="PROGRAMLISTING"> id <SimpleRandomGenerator> randomGenerator;id <UniformIntegerDist> uniformIntRand;id <UniformUnsignedDist> uniformUnsRand;id <UniformDoubleDist> uniformDblRand;</PRE></TD></TR></TABLE>The 3 distribution objects all draw their random numbers from theMT19937 generator, which has a period of 2^19937 (10^6001) and isquite fast.</P></DIV></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="AEN13070">5.4. Programming yet to do</A></H2><P>Like many Open Source projects, this random-number library is a work in process. Further developments still on the to-do list are detailed below. </P><P>The following changes and additions are contemplated for thenext release of Random for Swarm (though I don't promise they'll allmake it in -- nor when that next release will be):<P></P><OLTYPE="a"><LI><P>ADD a few more generators. It's good to have manydifferent types of generators, so you can test your model's resultswith different generators and ensure that the results aren't artifactsof the generator used. And people seem to insist on inventing new,better ones with longer periods!</P></LI><LI><P>ADD more distributions. NOTE: if you have any strongopinions about what distributions or generators need to be added,please e-mail me!</P></LI><LI><P>TEST the generators, using Marsaglia's Diehardbattery, or L'Ecuyer's tests when/if those become available. This willallow us (a) to make a choice between the implemented generators onthe basis of their statistical quality, (b) to decide what old and badgenerators to remove, and (c) to detect any bugs in myimplementation.</P></LI><LI><P>TEST the distributions, to make sure they actuallyput out numbers according to the probability distribution andparameters used.</P></LI><LI><P>ELIMINATE 'bad' old generators on the basis ofstatistical tests</P></LI><LI><P>RETAIN PMMLCG as the only short-period generator, forconvenience</P></LI><LI><P>ADD an 'empirical' distribution, whose f is definedby a set of user- supplied data</P></LI><LI><P>IMPLEMENT a version of getState/setState that isportable across machine architectures, so that simulations may bemoved to or duplicated on other machines. (The problem: integers anddoubles are stored in different byte orders on differentsystems.)</P
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -