4 An example based on the Iris flowers dataset

Marco Ballin and Giulio Barcaroli

Previous | Next

To show how to apply the algorithm for finding the optimal stratification, the well known Iris flowers dataset can be considered. This dataset consists of a total of 150 observations, equally distributed by the three species of Iris flowers (setosa, virginica and versicolor). Four features are measured for each observation (i.e., the length and the width of sepal and petal, in centimetres).

We will consider this dataset as a possible sampling frame from which to draw a sample, under a stratified design, in order to estimate two target variables:

  • Y 1 MathType@MTEF@5@5@+= feaagKart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaamywam aaBaaaleaacaaIXaaabeaaaaa@3BC5@ : Petal.Length;
  • Y 2 MathType@MTEF@5@5@+= feaagKart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaamywam aaBaaaleaacaaIYaaabeaaaaa@3BC6@ : Petal.Width.

For sake of simplicity, we suppose there are only two auxiliary variables available in the frame:

  • X 1 MathType@MTEF@5@5@+= feaagKart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaamiwam aaBaaaleaacaaIXaaabeaaaaa@3BC4@ : Sepal.Length;
  • X 2 MathType@MTEF@5@5@+= feaagKart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaamiwam aaBaaaleaacaaIYaaabeaaaaa@3BC5@ : Species.

While the second auxiliary variable is categorical, the first one is continuous, and needs to be transformed into a categorical ordered variable. To this aim, we make use of the k ­ MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaam4Aae rbhv2BYDwAHbacfaGaa8xRaaaa@3F00@ means univariate clustering method (Hartigan and Wong 1979), obtaining the following ranges: [4.3; 5.5], (5.5; 6.5], (6.5; 7.9].

The Cartesian product of the two auxiliary variables should produce 3 × 3 = 9 MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaaG4mai abgEna0kaaiodacqGH9aqpcaaI5aaaaa@3F5B@ different strata. Actually, one of these contains no units, the one related to Species = MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaeyypa0 daaa@3B07@ "setosa� and Sepal.Length MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaeyicI4 maaa@3B85@ (6.5; 7.9]. So the one reported in table 4.1 will be considered as the initial atomic stratification.

Table 4.1
Information concerning atomic strata

Table summary
This table displays information concerning atomic strata. The information is grouped by stratum, X 1 = Sepal.Length, X 2 = Species, N, Y 1 = Petal.Length, Y 1 = Petal.Width, Cost (appearing as column headers).
stratum X 1 = Sepal.Length X 2 = Species N Y 1 = Petal.Length Y 1 = Petal.Width Cost
Mean Standard deviation Mean Standard deviation
1 [4.3; 5.5] (1) Setosa (1) 45 1.47 0.17 0.24 0.11 1
2 [4.3; 5.5] (1) Versicora (2) 6 3.58 0.49 1.17 0.21 1
3 [4.3; 5.5] (1) Virginica (3) 1 4.50 0.00 1.70 0.00 1
4 [5.5; 6.5] (2) Setosa (1) 5 1.42 0.17 0.26 0.08 1
5 [5.5; 6.5] (2) Versicora (2) 35 4.27 0.37 1.32 0.19 1
6 [5.5; 6.5] (2) Virginica (3) 23 5.23 0.32 1.95 0.29 1
7 [6.5; 7.9] (3) Versicora (2) 9 4.68 0.19 1.46 0.11 1
8 [6.5; 7.9] (3) Virginica (3) 26 5.88 0.49 2.11 0.23 1

For sake of simplicity, we assume that the fixed cost C 0 MathType@MTEF@5@5@+= feaagKart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaam4qam aaBaaaleaacaaIWaaabeaaaaa@3BAE@ is null, and all C h MathType@MTEF@5@5@+= feaagKart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaam4qam aaBaaaleaacaWGObaabeaaaaa@3BE1@ are set equal to 1: by so doing, the cost of a solution coincides with the sum of sampling units allocated in the strata, i.e., with the total sample size ( C = n = h = 1 H n h ) . MathType@MTEF@5@5@+= feaagKart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaWaaeWaae aacaWGdbGaeyypa0JaamOBaiabg2da9maaqadabaGaamOBamaaBaaa leaacaWGObaabeaaaeaacaWGObGaeyypa0JaaGymaaqaaiaadIeaa0 GaeyyeIuoaaOGaayjkaiaawMcaaiaac6caaaa@478A@

We set as precision constraints to the estimates of both target variables an upper limit of 0.05 (5%) to their expected coefficient of variation.

Finally, we set a minimum number of units to be selected in each stratum equal to 2 (the minimum required in order to calculate sampling variance).

Under these assumptions, and using the atomic stratification, the Bethel algorithm solves the optimal allocation problem by defining a minimum sample size of 17 units, with an allocation vector a = ( 2 , 2 , 1 , 2 , 3 , 3 , 2 , 2 ) . MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaacbeGaa8 xyaiabg2da9maabmaabaGaaGOmaiaacYcacaaIYaGaaiilaiaaigda caGGSaGaaGOmaiaacYcacaaIZaGaaiilaiaaiodacaGGSaGaaGOmai aacYcacaaIYaaacaGLOaGaayzkaaGaaiOlaaaa@48DF@

If we proceed to partition the set of atomic strata, the resulting number of all possible stratifications (given by the Bell formula) is B 8 = MathType@MTEF@5@5@+= feaagKart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaamOqam aaBaaaleaacaaI4aaabeaakiabg2da9aaa@3CC5@ 4,140. This number is such that we can afford to enumerate all partitions of atomic strata, and for each of them we are able to calculate the minimum sample size by applying the Bethel algorithm (to enumerate all the partitions in this example, we made use of the function setparts(), contained in the R package partitions (Hankin 2011)).

The range of sample sizes steps from a minimum of 11 to a maximum of 78 (this latter corresponds to the "no stratification solution�) (see figure 4.1).

Figure 4.1 Space of partitions

Description for figure 4.1

Figure 4.1 Space of partitions

We notice that the minimum value ( n = 11 ) MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaWaaeWaae aacaWGUbGaeyypa0JaaGymaiaaigdaaiaawIcacaGLPaaaaaa@3EF9@ that has been found is considerably lower than the one calculated in correspondence with the atomic stratification ( n = 17 ) . MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaWaaeWaae aacaWGUbGaeyypa0JaaGymaiaaiEdaaiaawIcacaGLPaaacaGGUaaa aa@3FB1@ This minimum value characterizes only 8 partitions out of 4,140.

Now, the genetic algorithm is applied in order to evaluate its capability to find the optimal solution (or at least one that is not far from it), without being obliged to explore all solutions, but only a strict subset of them.

Step 0: Creation of the initial generation

First, we set U = 8 MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaamyvai abg2da9iaaiIdaaaa@3CA3@ (we can accept a number of final strata that is equal to the number of atomic strata, so U = K MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaamyvai abg2da9iaadUeaaaa@3CB1@ ). The generation size parameter pop is set equal to 10. So, an initial set containing 10 different individuals (stratifications) is generated. Each of them is represented by a vector of 8 elements, i.e., the number of different atomic strata. An individual v = ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ) MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaacbmGaa8 NDaiabg2da9maabmaabaGaaGymaiaacYcacaaIYaGaaiilaiaaioda caGGSaGaaGinaiaacYcacaaI1aGaaiilaiaaiAdacaGGSaGaaG4nai aacYcacaaI4aaacaGLOaGaayzkaaaaaa@4857@ or, equivalently, v = ( 3 , 6 , 4 , 2 , 1 , 8 , 7 , 5 ) MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaacbmGaa8 NDaiabg2da9maabmaabaGaaG4maiaacYcacaaI2aGaaiilaiaaisda caGGSaGaaGOmaiaacYcacaaIXaGaaiilaiaaiIdacaGGSaGaaG4nai aacYcacaaI1aaacaGLOaGaayzkaaaaaa@4857@ corresponds to the most detailed stratification (as all strata are labelled with different labels), while v = ( 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ) MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaacbmGaa8 NDaiabg2da9maabmaabaGaaGymaiaacYcacaaIXaGaaiilaiaaigda caGGSaGaaGymaiaacYcacaaIXaGaaiilaiaaigdacaGGSaGaaGymai aacYcacaaIXaaacaGLOaGaayzkaaaaaa@483B@ or equivalently v = ( 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 ) MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaacbmGaa8 NDaiabg2da9maabmaabaGaaGinaiaacYcacaaI0aGaaiilaiaaisda caGGSaGaaGinaiaacYcacaaI0aGaaiilaiaaisdacaGGSaGaaGinai aacYcacaaI0aaacaGLOaGaayzkaaaaaa@4853@ corresponds to "null stratification� (as atomic strata are labelled with identical labels).

Step 1: Evaluation of fitness for each individual in the generation

To each one of the 10 individuals in the current generation, the Bethel algorithm is applied in order to find the cost of the sample required to comply with fixed precision constraints.

To do this, first of all related strata and information are calculated for each individual. For example, for a generated individual v = ( 4 , 1 , 1 , 4 , 8 , 7 , 8 , 1 ) MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaacbmGaa8 NDaiabg2da9maabmaabaGaaGinaiaacYcacaaIXaGaaiilaiaaigda caGGSaGaaGinaiaacYcacaaI4aGaaiilaiaaiEdacaGGSaGaaGioai aacYcacaaIXaaacaGLOaGaayzkaaaaaa@4855@ the information is derived by the one available from atomic strata, by applying (3.1) and (3.2) (see table 4.2).

Table 4.2
Information concerning generated aggregated strata

Table summary
This table displays information concerning generated aggregated strata. The information is grouped by Aggregated stratum, Original atomic strata, ( X 1, X 2), N, Y 1, Y 2 (appearing as column headers).
Aggregated stratum Original atomic strata ( X 1, X 2) N Y 1 Y 2
Mean Standard deviation Mean Standard deviation
1 2,3,8 (1,2) or (1,3) or (3,3) 33 5.41 1.01 1.92 0.44
2 1,4 (1,1) or (2,1) 50 1.46 0.17 0.25 0.10
3 6 (2,3) 23 5.23 0.31 1.95 0.28
4 5,7 (2,2) or (3,2) 44 4.35 0.37 1.35 0.18

The fitness of this individual is measured by the corresponding required sample size, that results to be 14, with an allocation vector a = ( 6 , 2 , 3 , 3 ) . MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaacbeGaa8 xyaiabg2da9maabmaabaGaaGOnaiaacYcacaaIYaGaaiilaiaaioda caGGSaGaaG4maaGaayjkaiaawMcaaiaac6caaaa@4334@

All individuals are sorted accordingly with their performance: the individual in the first position is the one supporting the minimum sample size, the 10th individual is the one requiring the maximum sample size.

Step 2: Breeding a new generation

By setting the elitism parameter to 20% (a common default value) we always take the best 2 individuals in the current generation and directly move them to the next generation, without any change of their genome.

Then, we proceed in generating new individuals in the following way:

  1. we select couples of individuals of the current generation with probability proportional to their fitness: for instance, assume to select v k = ( 1 , 1 , 3 , 4 , 3 , 2 , 2 , 2 ) MathType@MTEF@5@5@+= feaagKart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaaeODam aaBaaaleaacaWGRbaabeaakiabg2da9maabmaabaGaaGymaiaacYca caaIXaGaaiilaiaaiodacaGGSaGaaGinaiaacYcacaaIZaGaaiilai aaikdacaGGSaGaaGOmaiaacYcacaaIYaaacaGLOaGaayzkaaaaaa@4960@ and v j = ( 2 , 2 , 2 , 2 , 2 , 1 , 1 , 1 ) ; MathType@MTEF@5@5@+= feaagKart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaaeODam aaBaaaleaacaWGQbaabeaakiabg2da9maabmaabaGaaGOmaiaacYca caaIYaGaaiilaiaaikdacaGGSaGaaGOmaiaacYcacaaIYaGaaiilai aaigdacaGGSaGaaGymaiaacYcacaaIXaaacaGLOaGaayzkaaGaai4o aaaa@4A19@
  2. a crossover point is randomly generated, i.e., an integer internal to the interval [ 1 , 8 ] : MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaWaamWaae aacaaIXaGaaiilaiaaiIdaaiaawUfacaGLDbaacaGG6aaaaa@3EDE@ suppose to set it equal to 3;
  3. the crossover is performed by assigning to the child the first three elements of parent v k MathType@MTEF@5@5@+= feaagKart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaaeODam aaBaaaleaacaWGRbaabeaaaaa@3C15@ and the last five elements of parent v j , MathType@MTEF@5@5@+= feaagKart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaaeODam aaBaaaleaacaWGQbaabeaakiaacYcaaaa@3CCE@ obtaining in this way v new = ( 1 , 1 , 3 , 2 , 2 , 1 , 1 , 1 ) ; MathType@MTEF@5@5@+= feaagKart1ev2aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaaeODam aaBaaaleaacaqGUbGaaeyzaiaabEhaaeqaaOGaeyypa0ZaaeWaaeaa caaIXaGaaiilaiaaigdacaGGSaGaaG4maiaacYcacaaIYaGaaiilai aaikdacaGGSaGaaGymaiaacYcacaaIXaGaaiilaiaaigdaaiaawIca caGLPaaacaGG7aaaaa@4BFC@
  4. having set a mutation rate parameter equal to 0.05, for each element of the child a random number is generated in the interval [ 0 , 1 ] : MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaWaamWaae aacaaIWaGaaiilaiaaigdaaiaawUfacaGLDbaacaGG6aaaaa@3ED6@ if it is less than 0.05, the value of the element is changed (by generating a new value comprised between 1 and 9), otherwise it is not changed.

Step 3: Iteration and stopping criteria

The number of iterations has been set equal to 25. So, steps 1 and 2 are repeated 25 times. The individual with the best fitness alongside all the generations is retained as the best solution.

The graph in figure 4.2, obtained during the execution of the program, shows the convergence of the algorithm. In the graph, two different curves are reported: the lower one is related to the best solution found until the k th MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaam4Aam aaCaaaleqabaGaaeiDaiaabIgaaaaaaa@3D00@ iteration (as the best solution is memorised, it can only decrease as the algorithm proceeds); the upper one reports the mean of the 10 solutions evaluated in each iteration.

Figure 4.2 Best and mean evaluation values during GA execution

Description for figure 4.2

Figure 4.2  Best and mean evaluation values during GA execution

The resulting best solution is v = ( 4 , 1 , 3 , 4 , 1 , 3 , 3 , 2 ) . MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaacbmGaa8 NDaiabg2da9maabmaabaGaaGinaiaacYcacaaIXaGaaiilaiaaioda caGGSaGaaGinaiaacYcacaaIXaGaaiilaiaaiodacaGGSaGaaG4mai aacYcacaaIYaaacaGLOaGaayzkaaGaaiOlaaaa@48FA@ It corresponds to the stratification reported in table 4.3, with an allocation vector a = ( 3 , 2 , 4 , 2 ) . MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaacbeGaa8 xyaiabg2da9maabmaabaGaaG4maiaacYcacaaIYaGaaiilaiaaisda caGGSaGaaGOmaaGaayjkaiaawMcaaiaac6caaaa@4331@

Table 4.3
Information concerning final strata
Table summary
This table displays information concerning final strata. The information is grouped by Aggregated stratum, Original atomic strata, ( X 1, X 2), N, Y 1, Y 2 (appearing as column headers).
Aggregated stratum Original atomic strata ( X 1, X 2) N Y 1 Y 2
Mean Standard deviation Mean Standard deviation
1 2,5 (1,2) or (2,2)  41 4.16 0.45 1.30 0.19
2 8 (3,3) 26 5.88 0.49 2.10 0.22
3 3,6,7 (1,3) or (2,3) or (3,2) 33 5.06 0.38 1.80 0.33
4 1,4 (1,1) or (2,1) 50 1.46 0.17 0.25 0.10

In conclusion, by applying the genetic algorithm, we succeeded in finding the optimal solution by exploring only 25 × 10 = 250 MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaaGOmai aaiwdacqGHxdaTcaaIXaGaaGimaiabg2da9iaaikdacaaI1aGaaGim aaaa@4243@ alternative stratifications instead of the 4,140 belonging to the universe of partitions.

In order to verify that this result is not due to a "lucky strike�, we perform different executions of the algorithm: each execution iterates 10 times the application of the genetic algorithm, varying the values of the parameter "number of iterations�. Results are reported in table 4.4.

Table 4.4
Capability of GA to find the optimal solution

Table summary
This table displays the capability of GA to find the optimal solution. The information is grouped by Execution of the GA (10 times each), Value of parameter "number of iterations� in the GA, Solutions with n = 11 (optimal), Solutions with n = 12, Solutions with n = 14 (appearing as column headers).
Execution of the GA (10 times each) Value of parameter "number of iterations� in the GA Solutions with n = 11 (optimal) Solutions with n = 12 Solutions with n = 14
(a) 25 5 4 1
(b) 50 7 3 -
(c) 100 9 1 -
(d) 200 10 - -

In execution (a), we discover that, with only 25 iterations, to succeed in finding the optimal solution is actually a "lucky strike�, as in half of the trials the found solution is higher than the optimal. But increasing the number of the iterations up to 200 (execution (d)), the genetic algorithm proves to be reliable with respect to its capability to reach optimality, as in all the trials the optimal solution is found.

As for the number of the strata corresponding to the found optimal solutions, on average it is 4, with a range of [ 3 , 5 ] . MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaWaamWaae aacaaIZaGaaiilaiaaiwdaaiaawUfacaGLDbaacaGGUaaaaa@3ED1@

Finally, we also want to verify that the found solutions are compliant with the precision constraints (maximum CV equal to 5% for both target variables). So, in execution (d) (iterations  = 200 MathType@MTEF@5@5@+= feaagKart1ev2aqatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr 4rNCHbGeaGqiVu0Je9sqqrpepC0xbbL8F4rqqrFfpeea0xe9LqFf0x e9q8qqvqFr0dXdbrVc=b0P0xb9sq=fFfeu0RXxb9qr0dd9q8as0lf9 Fve9Fve9vapdbaqaaeGacaGaaiaabeqaamaabaabaaGcbaGaeyypa0 JaaGOmaiaaicdacaaIWaaaaa@3D37@ ), for each one of the 10 produced solutions we proceed to draw 1,000 samples from the frame and to calculate the related CV's. Corresponding results are shown in figure 4.3: the average of CV's for the first target variable (Petal.Lenght) is around 3%, while for the second one is around 5%. So, we can say that, on average, precision constraints have not been violated.

Figure 4.3 Distributions of CV's for target variables in the simulation

Description for figure 4.3

Figure 4.3  Distributions of CV's for target variables in the simulation

A more complete example involving the use of all the functions in the package SamplingStrata is reported in Barcaroli (2013b).

Previous | Next

Date modified: