ljvmiranda921/pyswarms

Linear Function Test

EdoF90 opened this issue · 1 comments

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):

  • OS: Linux
  • Version Ubuntu 20.04
  • Python Version 3.8.5
stale commented

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.