Git Product home page Git Product logo

Comments (3)

bluescarni avatar bluescarni commented on September 27, 2024

@oni73 apologies for the delay in the reply.

As long as you are using directly the algorithm API (as you show in your example), manually pickling after every evolve based on whatever criterion you like should "just work".

Are you asking about a higher-level API? I am not sure about the added value of a higher-level facility with respect to your code snippet, but I am open to suggestions.

from pygmo2.

oni73 avatar oni73 commented on September 27, 2024

Hi @bluescarni ,

many thanks for your reply. Indeed, i can confirm that the proposed approach works and this way we have quite fine-grained control over the evolution process....

what i ended up using is the following:

prob=pygmo.problem()
n_iterations=100
popsize=40
algo = pygmo.algorithm(pygmo.de1220(gen=1))
pop = pygmo.population(prob, popsize)
for i in range(n_iterations):
    pop = algo.evolve(pop)
    if pop.champion_f < best_f:
        best_f = pop.champion_f
        save_population(pop, 'experiment-1', i, best_f)

where save_population and load_population are defined as:

    def save_population(pop, exp_name, iteration: int, bestf: float):
        pop_snapshot_fname = exp_name + '/' + 'population-' + str(iteration) + '-' + str(bestf)
        np.savez_compressed(pop_snapshot_fname, x=pop.get_x(), fitnesses=pop.get_f())

    def load_population(pop_snapshot_path: str, prob, popsize: int):
        print('loading population snapshot', pop_snapshot_path, '...')
        xfs = np.load(pop_snapshot_path)

        pop = pygmo.population(prob=prob)

        for i in range(popsize):
            pop.push_back(x=xfs['x'][i], f=xfs['fitnesses'][i])
        print('done.')

        return pop

IMO, it would be beneficial to provide library support for such functionality.

from pygmo2.

EveCharbie avatar EveCharbie commented on September 27, 2024

Hi :)
Thank you @oni73 for sharing the code.
I have a large problem to run (weeks or months of computation).
I am concern that if something happens and the code gets interrupted (ex we loose power), I will loose all the progress made.
From the code above, I see that each evolution of the population can be saved.
So I can load the results form the last population evolution before interruption.
My question (@bluescarni) is : Is it possible to warm start a problem? I would provide the starting point and the optimization would resume from there.

from pygmo2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.