Roulette-wheel selection via stochastic acceptance
aa r X i v : . [ c s . N E ] D ec Roulette-wheel selection via stochastic acceptance
Adam Lipowski and Dorota Lipowska Faculty of Physics, Adam Mickiewicz University, Pozna´n, Poland Faculty of Modern Languages and Literature, Adam Mickiewicz University, Pozna´n, Poland
Roulette-wheel selection is a frequently used method in genetic and evolutionary algorithms or inmodeling of complex networks. Existing routines select one of N individuals using search algorithmsof O ( N ) or O (log N ) complexity. We present a simple roulette-wheel selection algorithm, whichtypically has O (1) complexity and is based on stochastic acceptance instead of searching. We alsodiscuss a hybrid version, which might be suitable for highly heterogeneous weight distributions,found, for example, in some models of complex networks. With minor modifications, the algorithmmight also be used for sampling with fitness cut-off at a certain value or for sampling withoutreplacement. Keywords: roulette-wheel selection, genetic algorithm, complex networks
I. INTRODUCTION
Finding low-energy configurations of crystals [1], disor-dered magnets [2] or proteins [3], reconstructing geologi-cal structure from seismic data [4], and analysing X-raydata [5] are just a few examples of optimization prob-lems in physical sciences [6]. Various techniques havebeen developed to approach these problems and one ofthe most frequently used is genetic algorithms [7]. Theirbasic idea is to mimic the way biological evolution cre-ates apparrently better fitted species. To do so one needsto represent a pool of optimization methods (routines,functions, strategies, etc.) as a population of individu-als, which, as in nature, is subjected to two, in a senseopposing, processes. On the one hand, due to mutationsor crossing-over operations, the variability in the popula-tion increases. On the other hand, to guide the evolutionin a desired direction, one has to trim the populationwith some selection mechanisms. It turns out that sucha biology-inspired scheme allows us to find optimal ornearly optimal solutions of various problems in a veryefficient way [8].Selection is an important part of genetic algorithmssince it affects significantly their convergence. The basicstrategy follows the rule: The better fitted an individ-ual, the larger the probability of its survival and mating.The most straightforward implementation of this rule isthe so-called roulette-wheel selection [8]. This methodassumes that the probability of selection is proportionalto the fitness of an individual. It can be briefly describedas follows. Let us consider N individuals, each character-ized by its fitness w i > i = 1 , , . . . , N ). The selectionprobability of the i -th individual is thus given as p i = w i P Ni =1 w i ( i = 1 , , . . . , N ) (1)Let us imagine a roulette wheel with sectors of size pro-portional to w i ( i = 1 , , . . . , N ). Selection of an individ-ual is then equivalent to choosing randomly a point onthe wheel and locating the corresponding sector (Fig. 1).When a simple search is used, such a location requires O ( N ) operations while the binary search needs O (log N ) FIG. 1. In a roulette-wheel selection, one constructs a linesegment of length P Ni =1 w i out of consecutive sectors of length w i ( i = 1 , , . . . , N ), generates a random number r such that0 < r < P Ni =1 w i , and locates the corresponding sector ( w in this case), thus selecting the respective individual. Whena simple search of an N -element list is used for location, theprocedure requires O ( N ) operations, which can be reduced to O (log N ) by means of the binary search. operations.There are also other methods with the selection proba-bility depending on the fitness, such as stochastic remain-der or stochastic universal selection [9, 10]. They haveslightly different statistical properties and in general leadto populations of larger variability. In yet another classof selection methods, the ranking or ordering of individ-uals rather than their fitness plays a central role [11].It is certainly difficult to indicate which of these meth-ods is the best [12, 13]. Although some studies suggestthat fitness-based selection methods suffer from certainscaling-related problems [14], there are some works thatseem to alleviate this difficulty [15].Let us notice that the roulette-wheel selection is alsoused in the generation of complex networks. For exam-ple, in some models of growing networks, a newly addedsite is linked to one of the already existing sites withprobability proportional to the degree of this old site [16–18]. This preferential-attachment algorithm is known togenerate highly heterogeneous scale-free networks, whichrecently have been intensively studied [19]. The roulette-wheel selection is also used in certain adaptive networkmodels [20].Due to simplicity of implementation and straightfor-ward interpretation, the roulette-wheel selection is fre-quently used in genetic algorithms. Although the binarysearch significantly reduces computational complexity,still faster implementations would be, in our opinion, de-sirable. In the present paper, we show that the roulette-wheel selection can be realized with a simple algorithm oftypically O (1) complexity. The proposed algorithm doesnot use searching but is based on a stochastic acceptanceof a randomly selected individual. II. DESCRIPTION AND PROPERTIES OF THEALGORITHM
Our algorithm consists of the following steps:1. Select randomly one of the individuals (say, i ). Theselection is done with uniform probability (1 /N ),which does not depend on the individual’s fitness w i (Fig. 2).2. With probability w i /w max , where w max =max { w i } Ni =1 is the maximal fitness in the popula-tion, the selection is accepted. Otherwise, the pro-cedure is repeated from step 1 (i.e., in the case ofrejection, another selection attempt is made).Of course, the probability that the i -th individual willbe selected in a single attempt equals w i / ( N w max ). How-ever, since several first attempts might fail, one has tocalculate the probability that the individual selected inan unspecified number of attempts will be the i -th indi-vidual. Straightforward calculations give p ′ i = w i N w max (1 + q + q + . . . ) (2)where q = 1 N N X i =1 (1 − w i /w max ) = 1 − P Ni =1 w i N w max = 1 − h w i w max (3)is the rejection probability and h w i = ( P Ni =1 w i ) /N is theaverage fitness. The geometrical series (2) is convergent(0 < q <
1) and summing it up, we easily find that p ′ i = p i (4)where p i is defined in Eq. (1). This shows that the prob-ability distribution of our procedure is indeed the sameas in the roulette-wheel selection.Similarly, we can calculate the average number of at-tempts τ needed for a single selection of any individual.One obtains τ = 1 N N X i =1 w i w max [1 + 2 q + 3 q + . . . ] = w max h w i (5)Although τ , which determines the computational com-plexity of our algoritmm, does not depend explicitly on FIG. 2. In the proposed algorithm, one selects randomly(with equal probability 1 /N ) an individual (say, i ) and ac-cepts such a selection with probability w i /w max , where w max is the maximal fitness. In case of rejection, the procedureis repeated anew (i.e., a new individual is selected repeat-edly until acceptance). Although it requires extra call(s) ofa random-number generator, it remains typically O (1) algo-rithm. N , the ratio w max h w i might change with N , depending onthe specificity of the problem. We expect, however, thatin many applications, for example, those where fitnessremains bounded ( w i < B ) and h w i does not diminish to0 for increasing N , the ratio w max h w i does not increase un-boundedly with N and thus a typical complexity of ouralgorithm should be O (1).One can examine a more general algorithm where ac-ceptance is made with probability w i /A , where A > w max is a certain constant. For such an algorithm the selectionprobability p ′ i also satisfies Eq. (4). However, a smalleracceptance probability results in a larger rejection prob-ability and the efficiency of the algorithm is reduced (as τ increases). For A < w max , some of the fractions w i /A may turn out greater than unity and the equality (4)does not hold. Thus, the choice A = w max ensures opti-mal performance.To examine its performance, we applied our algorithmto a population of N individuals with fitness being a uni-formly distributed random number 0 < w i <
1. Weimplemented the roulette-wheel selection algorithms us-ing linear or binary search as well as our stochastic ac-ceptance method. We found that the distributions ofselected individuals generated by these programs werewithin statistical errors the same. Average executiontime per single selection as a function of N is shown inFig. 3. As expected, the linear and binary search show O ( N ) and O (log N ) behaviour, respectively. Our algo-rithm requires basically N -independent CPU time and aslight increase for large N is due to excessive memory re-quirements that exceeded the size of cache memory. Wealso measured the average number of attempts τ . In ournumerical example, w max ≈ N , and h w i ∼ / τ ≈
2, and our numerical dataare in excellent agreement with this result (Fig. 3). -2-1.5-1-0.5 0 0.5 1 1.5 2 1 1.5 2 2.5 3 3.5 4 4.5 5 -2-1.5-1-0.5 0 0.5 1 1.5 2 l og ( t ) [ µ s ] l og ( τ ) log (N)linear searchbinary searchstochastic acceptanceattempts/selection FIG. 3. The average CPU time t (in µ s) of roulette-wheelselection of a single individual as a function of the popula-tion size N (log-log scale). As expected, the linear searchhas the complexity O ( N ) and the binary search O (log( N )).The stochastic acceptance algorithm behaves as O (1) and aslight increase for the largest N is due to excessive memoryrequirements that exceeded the size of cache memory. Calcu-lations were made on the Intel Xeon 2.8GHz processor. Filledsquares show the average number of attempts per selection. III. POSSIBLE EXTENSIONS ANDCONCLUSIONS
As we have already mentioned in Introduction, theroulette-wheel selection is used in some models of com-plex networks that are based on preferential attachment.The networks generated in this way are strongly inho-mogeneous with a small fraction of sites having a verylarge degree. The distribution of weights, which areproportional to degrees, is thus very broad and the ra-tio w max h w i might be quite large. Consequently, the ef-ficiency of our algorithm might diminish. However, asimple modification of the algorithm might lead to abetter performance. First, let us assume that there isone weight that is much larger than the others, say w (= w max ≫ w i , i = 2 , , . . . N ). In this case wemight use the following hybrid algorithm, which com-bines search and stochastic acceptance: With probabil- ity p = w / P Ni =1 w i one selects the first individual andwith probability 1 − p one of the remaining N − N − w was removed. Theprobability of selection of the individual i ( >
1) equals(1 − p ) w i P Nj =2 w j = w i P Nj =1 w j , thus it is indeed equal to (1).Generalization to the case where there are several muchlarger weights is straightforward.To ensure a sufficiently large variability of the popula-tion, it is sometimes desirable in optimization problemsto use sampling without replacement. In order to guar-antee that a once selected individual is never selectedagain, one can simply set its fitness to 0. However, whenthe individual happened to have the maximal fitness, anew maximum should be found. Sacrifying slightly theefficiency, one can use the old maximum to calculate theacceptance probability w i /w max . Similarly, when fitnessof individuals is known to be bounded ( w i < B ), it is notneeded to keep track of the current maximum, as onecan use w i /B as the acceptance probability. Althoughthe efficiency of the algorithm is reduced, it still shouldremain of the O (1) type [21].The replacement of w max with a certain constant A Adaptation in Natural and Artificial Sys- tems (University of Michigan Press, Ann Arbor, Michi-gan, 1975); re-issued by (MIT Press, 1992).[8] D.E. Goldberg