Learn R Programming

GA4Stratification (version 1.0)

GA4StratificationSelection: The selection operation in genetic algorithm for the determination of stratum boundaries and sample sizes of each stratum in stratified sampling with Equal sample allocation scheme

Description

This is the selection 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

GA4StratificationSelection(selectionGeneration, selectionGenerationFitness)

Arguments

selectionGeneration
The generation that selection operator will be applied.
selectionGenerationFitness
The fitness value of the generation that selection operator will be applied.

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 GA4StratificationP1x

randomnumGenerator

Examples

Run this code
## The function is currently defined as
function(selectionGeneration,selectionGenerationFitness)
   {
   	rowSelectionGeneration=nrow(selectionGeneration)
	colSelectionGeneration=ncol(selectionGeneration)
   	selectionStrata=array(0,dim=c(rowSelectionGeneration,(colSelectionGeneration+1)))
   	newSelectionGeneration=cbind(selectionGeneration, -selectionGenerationFitness)
   	sortedSelectionGeneration=newSelectionGeneration[order(newSelectionGeneration[,colSelectionGeneration+1]),]
   	sortedSelectionGenerationFitness=selectionGenerationFitness[order(-selectionGenerationFitness),]
   	wheelOld = sortedSelectionGenerationFitness / sum(selectionGenerationFitness)
	wheel=1:rowSelectionGeneration

	for(i in rowSelectionGeneration:1)
	{
		wheel[rowSelectionGeneration+1-i]=wheelOld[i]
	}
	wheel=cumsum(wheel)

   	for ( i in  1:rowSelectionGeneration )
   	{
		r = runif(1,0,1)
		for ( j in  1:rowSelectionGeneration )
		{
			if(r < wheel[j])
			{
				selectionStrata[i,] = sortedSelectionGeneration[j,]
				break;
			}
		}
	}
	randomGeneration=selectionStrata[,1:colSelectionGeneration]
	fitnessValueGeneration=selectionStrata[,(colSelectionGeneration+1)]
	return(randomGeneration)
   }

Run the code above in your browser using DataLab