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

How can I run with N-dimensional functions #17

Closed
AllSundayCroco opened this issue Jun 30, 2021 · 1 comment
Closed

How can I run with N-dimensional functions #17

AllSundayCroco opened this issue Jun 30, 2021 · 1 comment

Comments

@AllSundayCroco
Copy link

Could you please give an example for running N-dimensional functions such as [sphere dim = 50] with GA optimizer
Thank you so much !!!!!!!!

@thieu1995
Copy link
Owner

thieu1995 commented Jun 30, 2021

Hi @AllSundayCroco ,
Have you check the file: examples/evolutionary_based/run_test_GA.py

Basically, with sphere function.

from numpy import sum 
from mealpy.evolutionary_based import GA

def sphere(solution):
	return sum(solution**2)

## Setting parameters
epoch = 10                              # Maximum number of generations
pop_size = 50                          # Population size
lb = [-3, -5, 1, -10, ...]		# Enter your lower bound (50 dimensions)
ub = [5, 10, 100, 30, ...]		# Enter your upper bound (50 dimensions)
verbose = True                        # Print out the training process

model = GA.BaseGA(sphere, lb, ub, verbose, epoch, pop_size)		# Create model object 
best_position, best_fitness, list_loss = model.train()			        # Call train() function from object 
# List loss is the best fitness found in each iterations.

Depend on the algorithm you choose, some algorithms have several variant versions, such as PSO.

You can call the class to create a object like above:

model1 = PSO.BasePSO()
model2 = PSO.HPSO_TVAC()

Check the end of the readme.md file to see the variant versions of each algorithm.

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