ljvmiranda921 / pyswarms

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

Unexpected stagnation with VonNeumann and Pyramid topologies #521

Open earthtech23 opened 9 months ago

earthtech23 commented 9 months ago

Dear pyswarms contributors and maintainers,

I have noticed while extensively using pyswarms for neural network training when i am using as topology the VonNeumann or Pyramid architectures, my swarms are facing a strong stagnation that i cannot explain. The error i think it has to do with the argument r which is the range of VonNeumann topology (which i can't find it anywhere in the literature except some references that are not exactly describing what you mean by r). Some of the times, due to r selection in combination with the number of particles returns the following error

Traceback (most recent call last): File "/home/earthtech/salinity/von_neumann_tuning_8.py", line 131, in cost, pos = optimizer.optimize(f, iters=iters) File "/home/earthtech/.local/lib/python3.10/site-packages/pyswarms/single/general_optimizer.py", line 252, in optimize self.swarm.best_pos, self.swarm.best_cost = self.top.compute_gbest( File "/home/earthtech/.local/lib/python3.10/site-packages/pyswarms/backend/topology/von_neumann.py", line 50, in compute_gbest return super(VonNeumann, self).compute_gbest(swarm, p, k) File "/home/earthtech/.local/lib/python3.10/site-packages/pyswarms/backend/topology/ring.py", line 78, in compute_gbest idx_min = swarm.pbest_cost[self.neighbor_idx].argmin(axis=1) IndexError: index 64 is out of bounds for axis 0 with size 64

My neural network is for regression analysis with 1 hidden layer of 6 neurons, 8 inputs at the input layer and 1 neuron in the output.

I have executed a lot of tests, hyperparameter tuning procedures and validation procedures with the same source code on a large number of feature subsets with LocalBest and GlobalBest PSO implementations and i faced no problem.

I am running on Ubuntu 20.04, python 3.10 and pyswarms 1.3.0

I have tried to contact some of you through email or personal accounts on social media.

Hope that we will find a solution.

Thanks for your contribution to the Evolutionary Intelligence community.

Best Regards, Earthtech

earthtech23 commented 8 months ago

I am adding more info with the following error that occurred after waiting on a stagnated pyramid pso.

2023-10-26 07:42:52,778 - pyswarms.single.general_optimizer - INFO - Optimize for 500 iters with {'c1': 0.5, 'c2': 0.5, 'w': 0.5, 'r': 15, 'p': 1} pyswarms.single.general_optimizer: 0%| |0/500 Traceback (most recent call last): File "/home/sneofytides/.local/lib/python3.10/site-packages/pyswarms/backend/topology/pyramid.py", line 76, in compute_gbest pyramid = Delaunay( File "_qhull.pyx", line 1827, in scipy.spatial._qhull.Delaunay.init File "_qhull.pyx", line 353, in scipy.spatial._qhull._Qhull.init scipy.spatial._qhull.QhullError: QH7038 qhull option warning: joggle ('QJ') produces simplicial output (i.e., triangles in 2-D). Unless merging is requested, option 'Qt' has no effect QH6235 qhull error (qh_memalloc): negative request size (-2104280056). Did int overflow due to high-D?

While executing: | qhull d Qt QJ0.001 Qc Qbb Qx Options selected for Qhull 2019.1.r 2019/06/21: run-id 1226680527 delaunay Qtriangulate QJoggle 0.001 Qcoplanar-keep Qbbound-last Qxact-merge _zero-centrum Qinterior-keep Q3-no-merge-vertices-dim-high Pgood _run 1 _joggle-seed 16807 _max-width 1 Error-roundoff 3e-14 _one-merge 1.6e-12 _near-inside 0.01 Visible-distance 1.8e-13 U-max-coplanar 1.8e-13 Width-outside 3.6e-13 _wide-facet 1.1e-12 _maxoutside 1.6e-12 Last point added to hull was p21.

At error exit:

Delaunay triangulation by the convex hull of 50 points in 26-d:

Number of input sites: 39 Total number of nearly incident points: 11 Number of Delaunay regions: 7050044

Statistics for: | qhull d Qt QJ0.001 Qc Qbb Qx

Number of points processed: 38 Number of hyperplanes created: 6373192 Number of facets in hull: 8428051 Number of distance tests for qhull: 6276385 Input joggled by: 0.001 Maximum distance of point above facet: 0.0051 Maximum distance of vertex below facet: -0.0051

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/sneofytides/salinity/pyramid_tuning_8.py", line 126, in cost, pos = optimizer.optimize(f, iters=iters) File "/home/sneofytides/.local/lib/python3.10/site-packages/pyswarms/single/general_optimizer.py", line 252, in optimize self.swarm.best_pos, self.swarm.best_cost = self.top.compute_gbest( File "/home/sneofytides/.local/lib/python3.10/site-packages/pyswarms/backend/topology/pyramid.py", line 76, in compute_gbest pyramid = Delaunay( KeyboardInterrupt