Best way to store a copy of the Pareto Front from every generation in an eaSimple?

215 views
Skip to first unread message

Randy Olson

unread,
Mar 8, 2016, 12:05:36 AM3/8/16
to deap-users
Hello,

I am running a DEAP eaSimple algorithm with Pareto optimization and want to store the Pareto front from every generation. I found a hacky way to accomplish this using deep copies in the statistics log:

stats.register("ParetoFront", lambda x: copy.deepcopy(hof))

(stats is a Statistics object that is passed to the eaSimple; hof is a ParetoFront object)

but is there a better way to do this? This works for my purposes, but I just want to make sure that it's the "correct" way to store a copy of the HOF/Pareto Front from every generation in DEAP.

Best,
Randy

François-Michel De Rainville

unread,
Mar 9, 2016, 8:49:07 AM3/9/16
to deap-users
The best way would be to make your own algorithm script and add a variable that is a list of pareto fronts.

The most direct way to do everything in DEAP is to copy the desired algorithm and add what you really want without any hack. This way your are sure you don't mess with anything else and keep everything clean.

Best regards,
François-Michel

--
You received this message because you are subscribed to the Google Groups "deap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deap-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Manuel Belmadani

unread,
Mar 10, 2016, 6:43:46 PM3/10/16
to deap-users
Maybe a suggestion: you might find it useful to drop some checkpoints (http://deap.gel.ulaval.ca/doc/dev/tutorials/advanced/checkpoint.html) every few generation and inspect the population/pareto front from there by reloading populations

I have some sample code I use to store and load checkpoints. It's a bit hacky, and not super efficient as I'm just pickling everything I need and reloading it when I rerun my program, but I'm able to resume an existing point and reproduce the same results consistently. The code below should give you an idea. Feel comment or question the code :)


def store_checkpoint(path,
                     population,
                     generation,
                     halloffame,
                     logbook,
                     toolbox,
                     rndstate,
                     numpystate,
                     pset=None
                     ):
"""
#    Stores the curent population and stats along with the 'random' state
"""
    cp = dict(population=population,
              toolbox=toolbox,
              generation=int(generation),
              halloffame=halloffame,
              logbook=logbook,
              rndstate=rndstate,
              numpystate=numpystate
              )

    print "Writing gen", generation, "at path", path
    with open(path, 'w') as f:
        json.dump(cp, f)
        pickle.dump(cp, f)

def explode_checkpoint(path, pset):
   try:
        deap.creator.Individual
    except:
        deap.creator.create("Individual", deap.gp.PrimitiveTree, fitness=deap.creator.FitnessMax, pset=pset)

    with open(path, "r") as f:
        cp = json.load(f)
    return cp['population'], cp['toolbox'], cp['generation'], cp['halloffame'], cp['logbook'], cp['rndstate'], cp['numpystate']
.
Reply all
Reply to author
Forward
0 new messages