ljvmiranda921 / pyswarms

A research toolkit for particle swarm optimization in Python
https://pyswarms.readthedocs.io/en/latest/
MIT License
1.28k stars 332 forks source link

Linear Function Test #488

Closed EdoF90 closed 2 years ago

EdoF90 commented 2 years ago

Describe the bug The code does not act as it should on a simple linear function.

To Reproduce This is the code that I am running:

import numpy as np
import pyswarms as ps

def test_func(x):
    return np.sum(x)

# Set-up hyperparameters
options = {'c1': 0.5, 'c2': 0.3, 'w':0.3}

x_max = 10 * np.ones(2)
x_min = 0 * x_max
bounds = (x_min, x_max)

# Call instance of PSO
optimizer = ps.single.GlobalBestPSO(
    n_particles=10,
    dimensions=2,
    options=options, 
    bounds=bounds
)

# Perform optimization
cost, pos = optimizer.optimize(
    test_func,
    iters=1000
)
print("cost: ", cost)
print("pos: ", pos)

Expected behavior I would expect to return the point (0,0) or the point (10,10).

Environment (please complete the following information):

stale[bot] commented 2 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.