I'm trying to use pyevolve to implement a real valued genetic algorithm. (Example documentation is given here: http://pyevolve.sourceforge.net/examples.html#example-2-real-numbers-gaussian-mutator)
The range of the parameters (20 in this example) can be set using setParams
as follows:
# Genome instance
genome = G1DList.G1DList(20)
genome.setParams(rangemin=-6.0, rangemax=6.0)
However, the same range is applied to all 20. I'd like to have different ranges for the parameters. The way I tried to do it is changing the Initializators file.
The original relevant section within the file is:
def G1DListInitializatorReal(genome, **args):
""" Real initialization function of G1DList
This initializator accepts the *rangemin* and *rangemax* genome parameters.
"""
genome.clearList()
for i in xrange(genome.listSize):
randomReal = rand_uniform(genome.getParam("rangein", 0),
genome.getParam("rangemax", 100))
genome.append(randomReal)
My modification (assuming that the first 15 have one range and the last 5 have another range) is this:
def G1DListInitializatorReal(genome, **args):
genome.clearList()
for i in xrange(0,15):
print i
randomReal = rand_uniform(genome.getParam("rangein_1", 0),
genome.getParam("rangemax_1", 100))
genome.append(randomReal)
for j in xrange(15,20):
print j
randomReal2 = rand_uniform(genome.getParam("rangein_2", 0),
genome.getParam("rangemax_2", 100))
genome.append(randomReal2)
I added the printing of indices i and j to make sure that I know this one is being called. I've put the modified Initializators
file in the same folder as my code but when I run it, it calls the original one from elsewhere. I feel like I'm missing more changes that I need to make in pyevolve, or I'm not calling Initializators
correctly, or...I don't know.
How can I successfully change the range of my chromosome parameters in pyevolve?
Thanks in advance.