Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we specify a number of evaluations (fevals) in pygmo in each run? #67

Closed
chuongask opened this issue Jan 27, 2021 · 2 comments
Closed

Comments

@chuongask
Copy link

chuongask commented Jan 27, 2021

Dear All,
I am using pygmo to solve an optimization problem. Could you please show me how to specify a number of evaluations (fevals) in each run. Thank you very much!

My code is as follows:

# Define pygmo classs
class alge_function:
   # def __init__(self):
    #    self.starting = np.random.randint(1,5,16)

    def fitness(self, x):
        x = np.array(x, dtype=int) # to make integers
       x = list(x)
        fsr = look_up_function(x)
        vec = [fsr[1], fsr[2], fsr[3], fsr[4], fsr[5], fsr[6], fsr[7], fsr[8], fsr[9], \
               fsr[10], fsr[11], fsr[12], fsr[13], fsr[14], fsr[15], fsr[16], fsr[17], fsr[18]]
        obj = -choquet_pwl_function(k, mu, vec)

return [obj]

    def get_nix(self):
        return 16

# bounds [1,4]
    def get_bounds(self):
        return ([1]*16, [4] * 16)

# Algorithm of gradient
    def gradient(self, x):
        return pg.estimate_gradient_h(lambda x: self.fitness(x), x)

# use "slsqp"- sequential least squares programming algorithm
start = time.time()
algo = pg.algorithm(uda = pg.mbh(pg.nlopt("slsqp"), stop = 20, perturb = .2))
algo.set_verbosity(1) # print dialog
# Formulate minimization problem
pop = pg.population(prob = alge_function(), size = 2)
pop.set_x(1,starting_point)
# Solve the problem
pop = algo.evolve(pop)

# Collect information
print("objective value: obj=", pop.champion_f[0])
@darioizzo
Copy link
Member

darioizzo commented Jan 27, 2021

Stopping criterions depend on the uda used. In your case mbh with nlopd inner. For nlop look here to the attribute max_fevals: https://esa.github.io/pygmo2/algorithms.html#pygmo.nlopt.maxeval, for mbh you cannot define a maximum number of fevals, but you can log them and crop later if thats what you need.

@chuongask
Copy link
Author

Thank you for your message. I will study this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants