GithubHelp home page GithubHelp logo

Comments (8)

VittorioTrotta avatar VittorioTrotta commented on August 13, 2024 1

Hello,

Taking a similar case from the first post, i wanted to know if there is any big difference between the (1) first aprroach and the (2) sencond aprroach in terms of the final result:

import pygmo as pg
import numpy as np
import pandas as pd
from pygmo import *


class sphere_function:
     def __init__(self, dim):
         self.dim = dim

     def fitness(self, x):
         return [sum(x*x)]

     def get_bounds(self):
         return ([-1] * self.dim, [1] * self.dim)

     def get_name(self):
         return "Sphere Function"

     def get_extra_info(self):
         return "\tDimensions: " + str(self.dim)
     
        
pro = pg.problem(sphere_function(3))

# First approach - setting number of generations to one and looping n times
pop1 = pg.population(pro, size=8)
algo1 = pg.algorithm(pg.bee_colony(gen=1))

fits1=[]
for i in range(10):
    pop1 = algo1.evolve(pop1)
    fits1.append(pop1.champion_f)
print(fits1)

# Second approach - setting number of generations n 
pop2 = pg.population(pro, size=8)
algo2 = pg.algorithm(pg.bee_colony(gen=10))
algo2.set_verbosity(1)
pop2 = algo2.evolve(pop2)
fits2=pd.DataFrame(algo2.extract(bee_colony).get_log())
#get only the best result from each generation
print( fits2[2])

In the first approach it is easy too keep track of the evolving population and evaluation function, but in the second i can not find a way to keep track of the population.

Cheers

Vittorio

from pagmo2.

VittorioTrotta avatar VittorioTrotta commented on August 13, 2024 1

Thanks for the fast response @darioizzo !

In the second case you can access the log. Maybe check the tutorials (https://esa.github.io/pagmo2/docs/python/tutorials/solving_schwefel_20.html) where this is shown in code.

I checked the tutorial and the code, and have found out how to get the log of the champion evaluation of each generation, the problem is that the code does not return the decision vector champion for each generation.

Is there a way around to get this data?

from pagmo2.

bluescarni avatar bluescarni commented on August 13, 2024 1

@VittorioTrotta

I have added to pygmo a decorator meta-problem, that allows you (amongst other things) to modify a problem so that it logs the decision vectors that have been passed to it. See for instance the example in the documentation:

https://esa.github.io/pagmo2/docs/python/tutorials/udp_meta_decorator.html#logging-fitness-evaluations

This should allow you to log the information you need.

I am closing the report for now, please open a new one if you find issues with the decorator problem approach.

from pagmo2.

bluescarni avatar bluescarni commented on August 13, 2024

It depends what you mean exactly by tracking.

Some algorithms support some form of logging, meaning that you can have some information recorded during the evolution process and then later you can retrieve that information. Look for methods called get_log() and similar in the UDA (user-defined algorithms). Note that the log is not a general property of the pygmo.algorithm container, it is something that is specific to each and every UDA, so you will have to extract the UDA from the pygmo.algorithm if you want to access its log. Also note that each UDA does logging differently, so there's not a uniform way of accessing the logged information.

Otherwise, if you are running evolutions in an island, the "current" population of the island is always accessible (it gets replaced with the evolved population only at the end of the execution of the algorithm's evolve() method). So for instance you could periodically extract the current population of an island and extract from it the information you are interested in.

Finally, how the population is "evolved" is entirely dependent on the specific UDA. I believe at this time no algorithm discards or adds any individual from/to an input population, so the number of individuals will be a constant. For single-objective optimisation, there is the concept of a population "champion" (the best individual), but for multiobjective optimisation there's no champion defined and you will have to do the individual ranking on your own (perhaps using the ranking functions provided by pagmo). @darioizzo can tell you more precisely as he's the algorithmic expert.

from pagmo2.

ckaldemeyer avatar ckaldemeyer commented on August 13, 2024

t depends what you mean exactly by tracking.

Some algorithms support some form of logging, meaning that you can have some information recorded during the evolution process and then later you can retrieve that information. Look for methods called get_log() and similar in the UDA (user-defined algorithms). Note that the log is not a general property of the pygmo.algorithm container, it is something that is specific to each and every UDA, so you will have to extract the UDA from the pygmo.algorithm if you want to access its log. Also note that each UDA does logging differently, so there's not a uniform way of accessing the logged information.

That (tracking=logging) was exactly what I was looking for. Thanks!

Otherwise, if you are running evolutions in an island, the "current" population of the island is always accessible (it gets replaced with the evolved population only at the end of the execution of the algorithm's evolve() method). So for instance you could periodically extract the current population of an island and extract from it the information you are interested in.

This would be realized like in my example above, right?

Finally, how the population is "evolved" is entirely dependent on the specific UDA. I believe at this time no algorithm discards or adds any individual from/to an input population, so the number of individuals will be a constant. For single-objective optimisation, there is the concept of a population "champion" (the best individual), but for multiobjective optimisation there's no champion defined and you will have to do the individual ranking on your own (perhaps using the ranking functions provided by pagmo). @darioizzo can tell you more precisely as he's the algorithmic expert.

Thanks for your clarification!

from pagmo2.

bluescarni avatar bluescarni commented on August 13, 2024

This would be realized like in my example above, right?

That would be a possibility. The other thing you could do is to analyse at regular intervals of time the population. Since the island evolution is asynchronous, you can just periodically check what happens to the contained population (keeping in mind that the population is updated all at once every time the algorithm returns, so this makes sense only if you are calling the island's evolve method with n > 1).

The other thing I remembered, is that I am not 100% sure what happens to the algorithm's log when running in the island. I think there's a possibility that the log gets lost if using a multiprocessing or clustering island, but I am not 100% sure. Please open a report if you figure that out, we would consider it a defect to rectify.

from pagmo2.

darioizzo avatar darioizzo commented on August 13, 2024

In the second case you can access the log. Maybe check the tutorials (https://esa.github.io/pagmo2/docs/python/tutorials/solving_schwefel_20.html) where this is shown in code.

As for the optimization flow, the two cases as you use bee colony should be equivalent as bee_colony has no memory of previous calls to evolve.

from pagmo2.

ckaldemeyer avatar ckaldemeyer commented on August 13, 2024

This would be realized like in my example above, right?

That would be a possibility. The other thing you could do is to analyse at regular intervals of time the population. Since the island evolution is asynchronous, you can just periodically check what happens to the contained population (keeping in mind that the population is updated all at once every time the algorithm returns, so this makes sense only if you are calling the island's evolve method with n > 1).

The other thing I remembered, is that I am not 100% sure what happens to the algorithm's log when running in the island. I think there's a possibility that the log gets lost if using a multiprocessing or clustering island, but I am not 100% sure. Please open a report if you figure that out, we would consider it a defect to rectify.

Your answer somehow got lost in my mail flood. Thanks a lot! I'll do so!

from pagmo2.

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.