(genome, **args)
return int(mutations)
A gaussian mutator for GTree of Real numbers

   Accepts the *rangemin* and *rangemax* genome parameters, both optional. Also
   accepts the parameter *gauss_mu* and the *gauss_sigma* which respectively
   represents the mean and the std. dev. of the random distribution.
A gaussian mutator for GTree of Real numbers
A gaussian mutator for GTree of Real numbers
def GTreeMutatorRealGaussian(genome, **args):
   """ A gaussian mutator for GTree of Real numbers

   Accepts the *rangemin* and *rangemax* genome parameters, both optional. Also
   accepts the parameter *gauss_mu* and the *gauss_sigma* which respectively
   represents the mean and the std. dev. of the random distribution.

   """
   if args["pmut"] <= 0.0:
      return 0
   elements = len(genome)
   mutations = args["pmut"] * elements

   mu = genome.getParam("gauss_mu", Consts.CDefG1DListMutRealMU)
   sigma = genome.getParam("gauss_sigma", Consts.CDefG1DListMutRealSIGMA)

   if mutations < 1.0:
      mutations = 0
      for i in xrange(len(genome)):
         if Util.randomFlipCoin(args["pmut"]):
            mutations += 1
            rand_node = genome.getRandomNode()
            final_value = rand_node.getData() + rand_gauss(mu, sigma)
            final_value = min(final_value, genome.getParam("rangemax", Consts.CDefRangeMax))
            final_value = max(final_value, genome.getParam("rangemin", Consts.CDefRangeMin))
            rand_node.setData(final_value)
   else:
      for it in xrange(int(round(mutations))):
         rand_node = genome.getRandomNode()
         final_value = rand_node.getData() + rand_gauss(mu, sigma)
         final_value = min(final_value, genome.getParam("rangemax", Consts.CDefRangeMax))
         final_value = max(final_value, genome.getParam("rangemin", Consts.CDefRangeMin))
         rand_node.setData(final_value)

   return int(mutations)
def GTreeMutatorRealGaussian ( genome , * * args ) : if args [ "pmut" ] <= 0.0 : return 0 elements = len ( genome ) mutations = args [ "pmut" ] * elements mu = genome . getParam ( "gauss_mu" , Consts . CDefG1DListMutRealMU ) sigma = genome . getParam ( "gauss_sigma" , Consts . CDefG1DListMutRealSIGMA ) if mutations < 1.0 : mutations = 0 for i in xrange ( len ( genome ) ) : if Util . randomFlipCoin ( args [ "pmut" ] ) : mutations += 1 rand_node = genome . getRandomNode ( ) final_value = rand_node . getData ( ) + rand_gauss ( mu , sigma ) final_value = min ( final_value , genome . getParam ( "rangemax" , Consts . CDefRangeMax ) ) final_value = max ( final_value , genome . getParam ( "rangemin" , Consts . CDefRangeMin ) ) rand_node . setData ( final_value ) else : for it in xrange ( int ( round ( mutations ) ) ) : rand_node = genome . getRandomNode ( ) final_value = rand_node . getData ( ) + rand_gauss ( mu , sigma ) final_value = min ( final_value , genome . getParam ( "rangemax" , Consts . CDefRangeMax ) ) final_value = max ( final_value , genome . getParam ( "rangemin" , Consts . CDefRangeMin ) ) rand_node . setData ( final_value ) return int ( mutations )