2

私は Pyevolve で最適化を行い、結果を見て、収束を改善するためにいくつかの世代を追加したいと考えました。評価はかなり長いので、最後の世代に最適化を再開して、さらに 20 世代ほど追加できるかどうか疑問に思っていました。すべてをDBに設定する必要があるので、彼が可能になることを願っています。

これが私のGAプロパティです(最初の例に似ていますが、より複雑な評価関数があります):

    # Genome instance, 1D List of 6 elements
genome = G1DList.G1DList(6)

# Sets the range max and min of the 1D List
genome.setParams(rangemin=1, rangemax=15)

# The evaluator function (evaluation function)
genome.evaluator.set(eval_func)

# Genetic Algorithm Instance
ga=GSimpleGA.GSimpleGA(genome)

# Set the Roulette Wheel selector method, the number of generations and
# the termination criteria
ga.selector.set(Selectors.GRouletteWheel)
ga.setGenerations(50)
ga.setPopulationSize(10)
ga.terminationCriteria.set(GSimpleGA.ConvergenceCriteria)

# Sets the DB Adapter, the resetDB flag will make the Adapter recreate
# the database and erase all data every run, you should use this flag
# just in the first time, after the pyevolve.db was created, you can
# omit it.
sqlite_adapter = DBAdapters.DBSQLite(identify="F-Beam-Optimization", resetDB=True)
ga.setDBAdapter(sqlite_adapter)

# Do the evolution, with stats dump
# frequency of 5 generations
ga.evolve(freq_stats=2)

アイデアを持っている人はいますか?

4

1 に答える 1

3

こんにちは、Pyevolve のドキュメントを確認した後、データベースに保存したものに基づいて進化ベースを再開する方法はないようです (奇妙な動作)。

このタイプのメカニズムを実装したい場合は、たまに人口をピクルして、すべてを Pyevolve に実装することを検討できます。

または、進化的アルゴリズムのあらゆる側面を透過的に表示および操作できる、非常にオープンなフレームワークであるDEAPを試すこともできます。また、すでにいくつかのチェックポイントメカニズムが実装されています。

DEAP でのコードは次のようになります。

import random    
from deap import algorithms, base, creator, tools

# Create the needed types
creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("Individual", list, fitness=creator.FitnessMax)

# Container for the evolutionary tools
toolbox = base.Toolbox()
toolbox.register("attr", random.random, 1, 15)
toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr, 6)
toolbox.register("population", tools.initRepeat, list, toolbox.individual)

# Operator registering
toolbox.register("evaluate", eval_func)
toolbox.register("mate", tools.cxTwoPoints)
toolbox.register("mutate", tools.mutGaussian, mu=0, sigma=1, indpb=0.05)
toolbox.register("select", tools.selTournament, tournsize=3)

population = toolbox.population(n=10)
stats = tools.Statistics(key=lambda ind: ind.fitness.values)
stats.register("Max", max)
checkpoint = tools.Checkpoint(population=population)

GEN, CXPB, MUTPB = 0, 0.5, 0.1
while stats.Max() < CONDITION:
    # Apply standard variation (crossover followed by mutation)
    offspring = algorithms.varSimple(toolbox, population, cxpb=CXPB, mutpb=MUTPB)

    # Evaluate the individuals
    fits = toolbox.map(toolbox.evaluate, offspring)
    for fit, ind in zip(fits, offspring):
        ind.fitness.values = fit

    # Select the fittest individuals
    offspring = [toolbox.clone(ind) for ind in toolbox.select(offspring, len(offspring)]
    # The "[:]" is important to not replace the label but what it contains
    population[:] = offspring

    stats.update(population)
    if GEN % 20 == 0:
        checkpoint.dump("my_checkpoint")
    GEN += 1

上記のコードはテストされていないことに注意してください。しかし、それはあなたが要求するすべてを行います。次に、チェックポイントをロードして進化を再開する方法を説明します。

checkpoint = tools.Checkpoint()
checkpoint.load("my_checkpoint.ems")
population = checkpoint["population"]

# Continue the evolution has in before

さらに、DEAP は十分に文書化されており、25 を超える多様な例があり、新しいユーザーが非常に迅速に立ち上げるのに役立ちます。また、開発者が質問に非常に迅速に回答することも聞いています。

于 2011-08-05T03:46:39.430 に答える