正在加载图片...
312 Chapter 7.Random Numbers Initializing Values Used in sobseq Degree Polynomial Starting Values 0 1 (3) (5) (15) 2 1 (7) (11) 3 1 3 7 (5) 44。 3 2 3 3 (15) 3 http://www.nr read able files Permission is 4 1 5 9 83 Parenthesized values are not freely specifiable,but are forced by the required recurrence for this degree. 11-600 (including this one) -872 Define a sequence of integers Mi by the g-term recurrence relation, to any server from NUMERICAL RECIPES IN 19881992020ammm09e M4=2a1M-1⊕22a2M-2⊕…⊕29-1M-g+1ag-1⊕(29M1-g⊕Mi-g)(7.7.2) Here bitwise XOR is denoted by The starting values for this recurrence are that Mi,...,Mg (North can be arbitrary odd integers less than 2,...24,respectively.Then,the direction numbers Vi are given by America computer make one paper e University Press. THE V=M/2i=1,,w ART (7.7.3) The accompanying table lists all primitive polynomials modulo 2 with degree g 10. Programs Since the coefficients are either 0 or 1,and since the coefficients of r9 and of 1 are predictably 1,it is convenient to denote a polynomial by its middle coefficients taken as the bits of a binary number(higher powers of being more significant bits).The table uses this convention. Turn now to the implementation of the Sobol'sequence.Successive calls to the function sobseq(after a preliminary initializing call)return successive points in an n-dimensional Sobol'sequence based on the first n primitive polynomials in the table.As given,the routine is initialized for maximum n of 6 dimensions,and for a word length w of 30 bits.These OF SCIENTIFIC COMPUTING(ISBN parameters can be altered by changing MAXBIT (=w)and MAXDIM,and by adding more initializing data to the arrays ip (the primitive polynomials from the table),mdeg (their 1788-1982 degrees),and iv(the starting values for the recurrence,equation 7.7.2).A second table, above,elucidates the initializing data in the routine #include "nrutil.h" #define MAXBIT 30 Numerical Recipes 10-621 43108 #define MAXDIM 6 void sobseq(int *n,float x[]) (outside When n is negative,internally initializes a set of MAXBIT direction numbers for each of MAXDIM North Software. different Sobol'sequences.When n is positive (but <MAXDIM),returns as the vector x[1..n] the next values from n of these sequences.(n must not be changed between initializations. Ame int j,k,l; unsigned long i,im,ipp; static float fac; static unsigned long in,ix [MAXDIM+1],*iu[MAXBIT+1]; static unsigned long mdeg[MAXDIM+1]={0,1,2,3,3,4,4}; static unsigned long ip[MAXDIM+1]={0,0,1,1,2,1,4}; static unsigned long iv [MAXDIM*MAXBIT+1]={ 0,1,1,1,1,1,1,3,1,3,3,1,1,5,7,7,3,3,5,15,11,5,15,13,9]: if(*n<0){ Initialize,don't return a vector. for (k=1;k<=MAXDIM;k++)ix[k]=0;312 Chapter 7. Random Numbers Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machine￾readable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). Initializing Values Used in sobseq Degree Polynomial Starting Values 1 0 1 (3) (5) (15) ... 2 1 1 1 (7) (11) ... 3 1 1 3 7 (5) ... 3 2 1 3 3 (15) ... 4 1 1 1 3 13 ... 4 4 1 1 5 9 ... Parenthesized values are not freely specifiable, but are forced by the required recurrence for this degree. Define a sequence of integers Mi by the q-term recurrence relation, Mi = 2a1Mi−1 ⊕ 22 a2Mi−2 ⊕···⊕ 2q−1 Mi−q+1aq−1 ⊕ (2q Mi−q ⊕ Mi−q) (7.7.2) Here bitwise XOR is denoted by ⊕. The starting values for this recurrence are that M1,...,Mq can be arbitrary odd integers less than 2,..., 2q, respectively. Then, the direction numbers Vi are given by Vi = Mi/2i i = 1,...,w (7.7.3) The accompanying table lists all primitive polynomials modulo 2 with degree q ≤ 10. Since the coefficients are either 0 or 1, and since the coefficients of xq and of 1 are predictably 1, it is convenient to denote a polynomial by its middle coefficients taken as the bits of a binary number (higher powers of x being more significant bits). The table uses this convention. Turn now to the implementation of the Sobol’ sequence. Successive calls to the function sobseq (after a preliminary initializing call) return successive points in an n-dimensional Sobol’ sequence based on the first n primitive polynomials in the table. As given, the routine is initialized for maximum n of 6 dimensions, and for a word length w of 30 bits. These parameters can be altered by changing MAXBIT (≡ w) and MAXDIM, and by adding more initializing data to the arrays ip (the primitive polynomials from the table), mdeg (their degrees), and iv (the starting values for the recurrence, equation 7.7.2). A second table, above, elucidates the initializing data in the routine. #include "nrutil.h" #define MAXBIT 30 #define MAXDIM 6 void sobseq(int *n, float x[]) When n is negative, internally initializes a set of MAXBIT direction numbers for each of MAXDIM different Sobol’ sequences. When n is positive (but ≤MAXDIM), returns as the vector x[1..n] the next values from n of these sequences. (n must not be changed between initializations.) { int j,k,l; unsigned long i,im,ipp; static float fac; static unsigned long in,ix[MAXDIM+1],*iu[MAXBIT+1]; static unsigned long mdeg[MAXDIM+1]={0,1,2,3,3,4,4}; static unsigned long ip[MAXDIM+1]={0,0,1,1,2,1,4}; static unsigned long iv[MAXDIM*MAXBIT+1]={ 0,1,1,1,1,1,1,3,1,3,3,1,1,5,7,7,3,3,5,15,11,5,15,13,9}; if (*n < 0) { Initialize, don’t return a vector. for (k=1;k<=MAXDIM;k++) ix[k]=0;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有