A GENERALIZATION OF A CLASSICAL MONTE CARLO ALGORITHM TO ESTIMATE π


 John Day
 5 months ago
 Views:
Transcription
1 U.P.B. Sci. Bull., Series A, Vol. 68, No., 6 A GENERALIZATION OF A CLASSICAL MONTE CARLO ALGORITHM TO ESTIMATE π S.C. ŞTEFĂNESCU Algoritmul Monte Carlo clasic A1 estimeazează valoarea numărului π bazânduse pe faptul ca raportul dintre aria unui cerc oarecare C şi aria pătratului D circumscris cercului este egal cu π / 4. Prezentul articol extinde procedura de simulare stocastica A1 introducând parametrii suplimentari λ, a, b. Noul algoritm propus A(λ,a,b) ne conduce la varianta clasică pentru λ = sau a.b =. Variabila aleatoare W λ,a,b ce caracterizează valorile w generate de algoritmul A(λ,a,b) constituie un estimator nedeplasat al numărului π. În lucrare sunt determinate şi valorile optime λ *, a *, b * astfel încât variabila aleatoare W λ,a,b sa aibă cea mai mică dispersie. Comparat cu A1, precizia estimaţiilor furnizate de algoritmul A(λ *,a *,b * ) creşte de aproximativ γ * = 1.38 ori. Rezultatele teoretice obţinute au fost confirmate practic prin simulare stocastică pe calculator. It is very known that the ratio between the area of any circle C and the corresponding area of the circumscribed square domain D of C is equal to π /4. The classical algorithm A1 to estimate the number π is based on this remark. In the present paper the standard procedure A1 is extended by considering the additional parameters λ, a, b. Our suggested A(λ,a,b) procedure implies the standard variant A1 when λ = or a.b =. The random variable W λ,a,b which characterize the outputs w of A(λ,a,b) algorithm is an unbiased estimator for π. More, we determined the optimum values λ *, a *, b * such that the variance of the random variable W λ,a,b to attain its minimum value. The proposed A(λ *,a *,b * ) algorithm is approximately γ * = 1.38 times more accurate than the classical A1 Monte Carlo procedure. The theoretical results were confirmed experimentally by stochastic simulations on the computer. Keywords : Estimation of π, Monte Carlo method, stochastic simulation, unbiased estimator, minimum variance. Prof., Dept. of Probability, Statistics and Operations Research, Faculty of Mathematics and Informatics, University of Bucharest, ROMANIA,
2 4 S. C. Ştefănescu Introduction In the literature there are presented many deterministic and also Monte Carlo algorithms for estimating the unknown value of π ( Devroye [], Dodge [3], Sacuiu, Zorilescu [7] ). The classical probabilistic procedures which estimate the number π is based on a rejection type method ( Bradley, Fox, Schrage [1], Devroye [], Gentle [4], Kleijnen [6] ). More precisely, we generate a string of n independent random points P i (x,y) having an uniform distribution in the square domain D = { (x,y) x, y 1 }. Finally we reject all those points P i which did not fall inside the circular domain C, C = { (x,y) x, y, x + y 1 }. Obviously C D. In this manner are retained only m independent random points P i, with m n. All these selected points belong to the domain C and are also uniformly distributed on C. For this reason the number mn / could be considered a good approximation of the ratio Area(C)/Area(D), that is an appropriate estimation for the unknown quantity π /4. So, the value of π should be estimated by the quantity w= 4 m/ n. The classical algorithm A1 determines an estimation w for the number π. Algorithm A1. ( The standard rejection procedure for π estimation ) Step. Input : the number n of simulation steps. m = ; j = { j = the current simulation step } Step 1. j = j + 1 Generate two independent random variates x, y having a uniform U([, 1 ]) distribution Step. ( the rejection procedure ). If x + y 1 then m= m+ 1 Step 3. If j < n then Goto Step 1 Step 4. w= 4 m/ n ; Print w ; STOP. In the subsequent we'll generalize the standard algorithm A1 using additional parameters.
3 A generalization of a classical Monte Carlo algorithm to estimate π 5 Main results 1. A more general algorithm. Let λ, a, b be fixed real numbers with a > and b >. We'll define an extension A of A1 algorithm by considering the real numbers λ, a, b as additional parameters for A. Algorithm A(λ, a, b). ( Extension of A1 procedure ) Step. Inputs : n ( n = the number of simulation steps ) λ, a, b ( λ R, a >, b >, a + b 1 ) m = ( n = the number of the points P i which fall in the domain C ) k = ( n = the number of the points P i belonging to [, a] x [, b] domain ) j = { j = the current simulation step } Step 1. j = j + 1 Generate two independent random variates x, y having a U([, 1 ]) uniform distribution Step. ( the rejection procedure ). If x + y > 1 then Goto Step 4 m= m+1 If ( x a)&( y b) then k = k + 1 Step 4. If j < n then Goto Step 1 Step 5. w= 4 m/ n+ λk/ n λ ab ; Print w ; STOP. Particular cases :  Considering λ = in A algorithm we just obtain the classical A1 procedure, A(,a,b) A1.  At the same conclusion we arrive if we take ab= for any λ R ( A(λ,a,) A(λ,,b) A1 ). In the following we'll try to prove that for any λ R and a >, b > with a + b 1 the w value produced by A(λ,a,b) algorithm is an unbiased estimation of π. More, taking into consideration different variants of A(λ,a,b) procedure which depend on the parameters λ, a, b we can choose the appropriate values λ *, a *, b * of these parameters such that the estimations w of π to attain a minimum dispersion.
4 6 S. C. Ştefănescu. Theoretical results. We define the functions 4 ; if ( x, y, x + y 1) h1 ( x, y) = (1) ; otherwise 1 ; if ( x a, y b) h( x, y) = () ; otherwise In the following we'll impose some restrictions for the unknown values of the parameters a, b. So, we'll consider Hypothesis H1. a, b 1. Hypothesis H. a, b and a + b 1. Definition 1. For any independent random variables ( r.v.s ) X,Y which have an uniform distribution on the interval [, 1], X~ U([, 1]), Y~ U([, 1]), we define the r.v. W λ,a,b given by the expression Wλ, ab, = h1( X, Y) + λ h ( X, Y) ab (3) ( ) Remark 1. Analyzing the algorithm A(λ,a,b) we deduce that its output w can be regarded as an observation from the r.v. W λ,a,b. In the subsequent we intend to use the r.v. W λ,a,b to study the statistical qualities of the estimations w. More precisely Proposition 1. For any λ R and a, b respecting the restriction H1, the r.v. W λ,a,b is an unbiased estimation of π, that is Mean( Wλ, ab,) = π (4) Proof. The probability density function (p.d.f.) f 1 (x,y) of the random vector (X,Y) has the form 1 ; if ( x 1, y 1) f1( x, y) = ; otherwise So, we get + + Mean( Wλ, ab, ) = ( h1( x, y) + λ ( h( x, y) a. b) ) f1 ( x, y) dx dy = = h 1( x, y ) dxdy + λ ( h ( x, y ) a. b ) dxdy =
5 A generalization of a classical Monte Carlo algorithm to estimate π x a b 1 = + dy dx λ dx dy a. b = 1 x dx = π / π / 1+ cos( t) = 4 cos () t dt = 4 dt = π Proposition. If the hypothesis H is satisfied then the variance Var( Wλ, ab,) of the r.v. W λ,a,b has the expression Var( Wλ, ab, ) = g1( λ, a, b) = ab( 1 ab) λ + ab( 4 π) λ + π( 4 π) (5) Proof. Indeed, for any a, b with a + b 1 we deduce successively g1( λ, a, b) = Var( Wλ, ab,) = Mean( Wλ, ab,) Mean( Wλ, ab,) = ( ) + + = ( h x y + ( h x y a b) ) f x y dxdy = 1(, ) λ (, ). 1(, ) π = h 1 x y dxdy + h x y a b (, ) λ (, ). dxdy + ( ) ( ) λ h1( x, y) h( x, y) a. b dxdy π = 1 = 1 x a b dy dx λ ( ab) dx dy + λ a b + a b 1 1 x + λ 4dx dy λab 4dy dx π = = 4π + λ ab( 1 ab) + λab( 4 π) π = ab( 1 ab) λ + ab( 4 π) λ + π( 4 π) Remark. The function g1( λ, a, b) defined by the formula (5) is symmetrical one in the arguments a and b, that is g1( λ, a, b) = g1( λ, b, a) for any real values a, b which satisfy the restriction H.
6 8 S. C. Ştefănescu Remark 3. The accuracy of A1 outputs is given by the variance of the r.v. W, ab, that is Var( W, ab, ) = π( 4 π ) for any real numbers a, b respecting H hypothesis. Proposition 3. For given real numbers a, b which verify the restriction H, the minimum value of the variance Var( Wλ, ab,), regarded as a function of λ, is attained for λ = λ 1 where π 4 λ1 = (6) and in addition ab Var( Wλ, ab, ) = g ( a, b) ( π) π( π) 1 = (7) Proof. We'll treat individually the situations ab. =, respectively ab.. Case 1. If ab. = then for any λ R we have Var( Wλ, ab, ) = g1( λ, a, b) = ab( 1 ab) λ + ab( 4 π) λ + π( 4 π) = π( 4 π) and hence for λ = λ 1 we conclude ab Var( Wλ, ab, ) = π( 4 π) = ( 4 π) + π( 4 π) = g ( a, b) 1 Case. Indeed, since ab. we deduce that the polynomial function g1 ( λ, a, b ) has the degree two in the variable λ and more it takes its minimum when ab( 4 π ) π 4 λ = λ1 = = ab( 1 ab) So, the minimum g (a,b) of the function g 1 (λ,a,b) has the following expression g( a, b) = g1( λ1, a, b) = ab( 1 ab) λ1 + ab( 4 π) λ1 + π( 4 π ) = ab = π( 4 π) ( 4 π) which finish the proposition proof. Proposition 4. Respecting the hypothesis H, the minimum variance of the random variables W λ,a,b is attained when the parameters a, b, λ take the values a* = b* =1/ λ* = π 8 (8) and more Var( Wλ, a, b ) = ( 4 π )( π 4) (9) * * *
7 A generalization of a classical Monte Carlo algorithm to estimate π 9 Proof. Taking into consideration the results of Proposition 3 it remains to find those values a *, b * which minimize the function g( a, b) given by (7). At the end we'll consider λ* = ( π 4)/ ( 1 ab * *). Case 1. When ab. = then the constant function g( a, b) = π( 4 π ) has obviously its minimum value equal to π( 4 π ). Case. Now we'll find the minimum value of the function g( a, b) for any a >, b > which respect the inequality a + b 1. First, we remark that the function g3() t = t /( 1 t), < t < 1, is an increasing one. So, the minimum value for the expression g ( a, b) given by (7), ab t g( a, b) = π( 4 π) ( 4 π) = π( 4 π) ( 4 π ) 1 t is obtained when the variable t = ab takes its maximum value, respecting also the restrictions : a >, b>, a + b 1. But the maximum value of t = a b with a + b 1 is attained for a = b = 1 /, that is a* = b* =1/. Having a* = b* =1/ we deduce λ* = ( π 4)/( 1 ab * *) = π 8. More ab Var( W a b ) g ( a, b ) ( ) * * λ ( ) ( )( ). *, *, = * * * = π 4 π 4 π = 4 π π 4 = * * Analyzing both previous alternatives, since ( 4 π )( π 4) < ( 4 π ) π we deduce the results mentioned by Proposition A Monte Carlo study. Figure 1 presents the graphic of the function g ( a, a) = Var( Wλ 1, aa, ) which has the form (7). We mention here that g( a, a) is a decreasing application. Comparing with A1, the algorithm A(λ 1,a,b) is γ ( ab, ) times more accurate to estimate π. The coefficient γ ( ab, ) is just the ratio Var( W, ab, ) π( 4 π) π γ ( ab, ) = = = (1) Var( Wλ, ab, ) g( a, b) π ab( 4 π)/( 1 ab) 1 Obviously γ ( ab, ) = γ ( ba, ). Table 1 lists the values of γ ( aa, ) when a 1/.
8 1 S. C. Ştefănescu Figure 1. The graphic of the function g (a,a). 3.5 g(a,a) a The values of the coefficient γ ( aa, ). Table 1 a γ(a,a) The maximum value γ * of the indicator γ ( ab, ) is attained for a * = 1/ and b * = 1/, that is Var( W, a, ) * a* π( 4 π) π γ * = = = = (11) Var( Wλ,, ) ( π )( π) π * a* a * Table gives the optimum values λ 1 computed with formula (6) for the parameter λ of A(λ,a,a) algorithm ( the case a = b ). Table The optimum value λ 1 ( formula (6), the case a = b ). a = b λ
9 A generalization of a classical Monte Carlo algorithm to estimate π 11 Running the algorithm A(λ 1,a,a) for n=1 we obtained the estimations w of π, quantities which are listed in Table 3. This process was repeated s = times, the variable s counting the current simulated step. The outputs w of A(λ 1,a,a) algorithm ( n=1, s= simulations ). Table 3 s a =. a =.1 a =. a =.3 a =.4 a =.5 a =.6 a = Taking into consideration the outputs w k, 1 k s, produced after s independent runs of A(λ 1,a,a) procedure we are also computed the mean μ and the dispersion σ of these experimental results, where w1 + w + w ws μ = s ( w1 μ) + ( w μ) + ( w3 μ) ( ws μ) σ = (1) s The values of μ and σ indicators obtained for different values for the input parameter a of A(λ 1,a,a) estimation procedure are presented in Table 4. The experimental data confirm the theoretical results. More precisely, the dispersion σ decreases when the values of the parameter a increase ( compare Figure 1 with Table 4 ). Table 4
10 1 S. C. Ştefănescu The mean μ and the variance σ for the outputs w of A(λ 1,a,a) algorithm considering s= simulation runs ( n=1 ). a =. a =.1 a =. a =.3 a =.4 a =.5 a =.6 a =.7 μ σ Concluding remarks Imagining new parameters to the classical A1 estimation algorithm we obtained the extended procedure A(λ,a,b). The procedure A1 is deduced from A(λ,a,b) as a particular case, that is by considering λ = or ab= ( A(,a,b) A(λ,a,) A(λ,,b) A1 ). A theoretical proof ( Proposition 1 ) confirms the good properties of w outputs produced by A(λ,a,b) procedure to evaluate the unknown value of π ( the random variable W λ, ab, is an unbiased estimator for π ). The dispersion of the estimator W λ, ab, is also computed ( see Proposition ). More, we determined the optimum values λ *, a *, b * for the parameters of A(λ,a,b) generalized algorithm such that the outputs w to have a minimum dispersion ( Proposition 4 ). A Monte Carlo computer simulation confirmed the theoretical results ( see Table 4 ). In conclusion, the suggested A(λ *,a *,b * ) algorithm is approximately γ * = times more accurate than the standard A1 Monte Carlo procedure. R E F E R E N C E S 1. Paul Bratley, Bennett Fox, Linus Schrage, A guide to simulation. Springer Verlag, New York, Luc Devroye, Non uniform random variate generation. Springer Verlag, NY, Yadolah Dodge, A natural random number generator. International Statistical Review (3), 64, 1996, James E. Gentle, Random number generation and Monte Carlo methods. Springer Verlag  Statistics and Computers, New York, M.G. Kendall, P.A.P. Moran, Geometrical probability. Griffin, London, J.P.C. Kleijnen, Statistical techniques in simulation. Dekker, New York, Part 1 (1974), Part (1975). 7. I. Sacuiu, D. Zorilescu, Numere aleatoare  Aplicaţii în economie, industrie şi studiul fenomenelor naturale. Editura Academiei Române, Bucuresti, 1978.