Learn R Programming

GA4Stratification (version 1.0)

GA4StratificationP1x: The crossover operation in genetic algorithm for the determination of stratum boundaries and sample sizes of each stratum in stratified sampling

Description

This is the crossover operation in the Genetic Algorithm approach for the determination of the stratum boundaries and sample sizes in each stratum in stratified sampling with an Equal Sample Allocation Scheme.

Usage

GA4StratificationP1x(crossoverGeneration,bestGeneration,dataName,numberOfStrata,sampleSize,fitnessValueGeneration,cumTotal,sumSquares,lengthData,dd,nocrom,fitp1,fit,N,means,s,n,vars,mas,NN,k,p,t,randomNumbersX,tableData,randomnumRange,lengthRandomnum)

Arguments

crossoverGeneration
The generation that will be crossovered and transfered to the next generation.
bestGeneration
The generation that has the best fitness value after the selection process.
dataName
A string: The name of any type of numeric data containing the values of a univariate stratification variable.
numberOfStrata
An integer: The number of strata.
sampleSize
An integer: The total sample size.
fitnessValueGeneration
The fitness value -the variance of the estimate- of the best generation after selection
cumTotal
An array: The cumulative total of the data elements from i=1 to i=N
sumSquares
An array: The cumulative total of the squares of the data elements from i=1 to i=N
lengthData
An integer: The size of the data.
dd
An array (nocrom X 1): The minimum of the difference in between the size of each stratum and the sample size to be drawn from that stratum.
nocrom
An integer: The number of the chromosomes in the generation.
fitp1
An array (1 X nocrom): The fitness value for each chromosome in the generation.
fit
An array (nocrom X 1): The fitness value for each chromosome in the generation.
N
An array (nocrom X nofstrata): The number of the elements in each stratum for each chromosome in the generation.
means
An array (nocrom X nofstrata): The mean of the elements in each stratum for each chromosome in the generation.
s
An array (nocrom X nofstrata): The standart deviation of the elements in each stratum for each chromosome in the generation.
n
An array (nocrom X nofstrata): The number of the sample size to be drawn from each stratum for each chromosome in the generation.
vars
An array (nocrom X nofstrata): The variance of the estimate in each stratum for each chromosome in the generation.
mas
An array (nocrom X nofstrata): The indice of each stratum for each chromosome in the generation.
NN
An array (nocrom X nofstrata): The cumulative sum of the number of the elements in each stratum.
k
An array (nocrom X nofstrata): The difference between the number of the elements and the sample sizes in each stratum.
t
An array (nocrom X nofstrata): The maximum of the k
p
An array (nocrom X nofstrata): The indice of the element where k is equal to t
randomNumbersX
An integer: The number of random numbers.
tableData
The frequency table of the data.
randomnumRange
An array: The range of the data where different random numbers will be chosen.
lengthRandomnum
An integer: The number of random numbers that are different from eachother.

References

http://ideas.repec.org/a/eee/csdana/v52y2007i1p53-67.html

http://www.sciencedirect.com/science/article/B6V8V-4NHM520-1/2/a21e0295aa1616ff56da1ddf2c0ba1ac

See Also

GA4StratificationP1 GA4StratificationP1fit GA4StratificationP1fitt GA4StratificationP1m

GA4StratificationSelection randomnumGenerator

Examples

Run this code
## The function is currently defined as
function(crossoverGeneration,bestGeneration,dataName,numberOfStrata,sampleSize,fitnessValueGeneration,cumTotal,sumSquares,lengthData,dd,nocrom,fitp1,fit,N,means,s,n,vars,mas,NN,k,p,t,randomNumbersX,tableData,randomnumRange,lengthRandomnum)
 {

   fitnessValueParents=fitnessValueGeneration
   parents=cbind(crossoverGeneration,fitnessValueParents)
   crossoverGenerationp=crossoverGeneration
   rowCrossoverGenerationp=nocrom
	   
   for (i in 1:rowCrossoverGenerationp)
   {
	randomNumbersX[i,]=randomnumGenerator((1:rowCrossoverGenerationp),(rowCrossoverGenerationp+1),2)
   }

   mother=father=NULL

   for (i in 1:rowCrossoverGenerationp)
   {
	  mother=randomNumbersX[i,1]
	  father=randomNumbersX[i,2]
   
    	  crossoverPoint=sample((randomnumRange[1:lengthRandomnum-1]),1)
        while ( sum(crossoverGenerationp[mother,c(1:crossoverPoint)])!=sum(crossoverGenerationp[father,c(1:crossoverPoint)]) )
        {
		crossoverPoint=sample((randomnumRange[1:lengthRandomnum-1]),1)

	  }
    	  crossoverGeneration[i,c(1:crossoverPoint)]=crossoverGenerationp[mother,c(1:crossoverPoint)]
        crossoverGeneration[i,c((crossoverPoint+1):lengthData)]=crossoverGenerationp[father,c((crossoverPoint+1):lengthData)]
   }
      s=GA4StratificationP1fit(crossoverGeneration,dataName,numberOfStrata,sampleSize,cumTotal,sumSquares,lengthData,dd,nocrom,fitp1,fit,N,means,s,n,vars,mas,NN,k,p,t)
      crossoverGenerationx=cbind(crossoverGeneration,s)
      GA4StratificationP1x=rbind(parents, crossoverGenerationx)
      GA4StratificationP1x=GA4StratificationP1x[order(GA4StratificationP1x[,(lengthData+1)]),]
      GA4StratificationP1x=GA4StratificationP1x[c((rowCrossoverGenerationp+1):(rowCrossoverGenerationp*2)),c(1:lengthData)]
	return(GA4StratificationP1x)
 }


Run the code above in your browser using DataLab