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

[BUG]: Problem with negative fitness #139

Closed
lucianolorenti opened this issue Feb 20, 2024 · 0 comments · Fixed by #140
Closed

[BUG]: Problem with negative fitness #139

lucianolorenti opened this issue Feb 20, 2024 · 0 comments · Fixed by #140
Assignees
Labels
bug Something isn't working

Comments

@lucianolorenti
Copy link

lucianolorenti commented Feb 20, 2024

Description of the bug

Hello!
Thank you for the library, it's been great working with it.

I am having issues when running ABC.

When the fitness function is negative ABC fails with the following message

File  mealpy\optimizer.py:636, in Optimizer.get_index_roulette_wheel_selection(self, list_fitness)
    633     final_fitness = np.max(list_fitness) - list_fitness
    635 prob = final_fitness / np.sum(final_fitness)
--> 636 return int(self.generator.choice(range(0, len(list_fitness)), p=prob))

File _generator.pyx:745, in numpy.random._generator.Generator.choice()

ValueError: probabilities are not non-negative

Steps To Reproduce

I know the problem does not make so much sense but 🤷

from mealpy import IntegerVar, ABC
import numpy as np

lower_bound = 0
upper_bound = 500
rows = 11
columns = 3
target_matrix = np.random.randint(lower_bound, upper_bound, size=(rows, columns))


def objective_func(solution):
    return np.sum(solution.flatten() - target_matrix.flatten())


problem_dict = {
    "obj_func": objective_func,
    "bounds": IntegerVar(
        lb=[0]*11*3,
        ub=[500]*11*3
    ),
    "minmax": "max",
}


abc_model = ABC.OriginalABC(epoch=1000, pop_size=100, n_limits=50)
g_best = abc_model.solve(problem_dict)

Additional Information

I think I know where the prolem is. I am creating an PR so you can take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants