public GammaInvFitnessFunction(int genomeLength,double alpha,double beta,double pInv,int stateSize,boolean randomFittest){
  GammaDistribution gamma=new GammaDistribution(beta,alpha);
  fitness=new double[genomeLength][stateSize];
  fittest=new byte[genomeLength];
  int fitpos=0;
  for (int i=0; i < genomeLength; i++) {
    if (randomFittest) {
      fitpos=MathUtils.nextInt(stateSize);
    }
    fitness[i][fitpos]=1.0;
    fittest[i]=(byte)fitpos;
    for (int j=0; j < stateSize; j++) {
      if (j != fitpos) {
        if (MathUtils.nextDouble() > pInv) {
          double prob=Math.round(MathUtils.nextDouble() * 1000.0) / 1000.0;
          while ((prob <= 0.0) || (prob >= 1.0)) {
            prob=Math.round(MathUtils.nextDouble() * 1000.0) / 1000.0;
          }
          fitness[i][j]=Math.max(0.0,1.0 - gamma.quantile(prob));
        }
 else {
          fitness[i][j]=0.0;
        }
      }
    }
  }
}

public GammaInvFitnessFunction ( int genomeLength , double alpha , double beta , double pInv , int stateSize , boolean randomFittest ) { GammaDistribution gamma = new GammaDistribution ( beta , alpha ) ; fitness = new double [ genomeLength ] [ stateSize ] ; fittest = new byte [ genomeLength ] ; int fitpos = 0 ; for ( int i = 0 ; i < genomeLength ; i ++ ) { if ( randomFittest ) { fitpos = MathUtils . nextInt ( stateSize ) ; } fitness [ i ] [ fitpos ] = 1.0 ; fittest [ i ] = ( byte ) fitpos ; for ( int j = 0 ; j < stateSize ; j ++ ) { if ( j != fitpos ) { if ( MathUtils . nextDouble ( ) > pInv ) { double prob = Math . round ( MathUtils . nextDouble ( ) * 1000.0 ) / 1000.0 ; while ( ( prob <= 0.0 ) || ( prob >= 1.0 ) ) { prob = Math . round ( MathUtils . nextDouble ( ) * 1000.0 ) / 1000.0 ; } fitness [ i ] [ j ] = Math . max ( 0.0 , 1.0 - gamma . quantile ( prob ) ) ; } else { fitness [ i ] [ j ] = 0.0 ; } } } } }
selection coefficients are gamma distributed with parameters alpha and beta
