ljvmiranda921/pyswarms

IndexError: index 122 is out of bounds for axis 1 with size 1

LizzAlice opened this issue · 1 comments

I am doing a LocalBestPSO. It runs without any problems. Now I wanted to include bounds, since the parameters are getting to small. The only thing I changed in my code was adding the bounds like this:
options = {'c1': 3.4881250747716916, 'c2': 2.952051274747192, 'w': 0.618850762148508, 'k': 13, 'p': 2}

optimizer = ps.single.LocalBestPSO(n_particles=n_particles, dimensions=p_size, options=options, init_pos=log10(init_p), bounds=(np.array(log10(1e-3),), np.array(log10(1e+3),)))
The only new thing about my code is the "bounds"-Definition at the end of the PSO-Call.
Now I get the Index error mentioned in the title.

I don't understand how that could be the case since without the bounds, everything is running fine.

Did I choose the wrong format for giving the bounds?

TRACEBACK:
---> 12 best_cost, best_pos = optimizer.optimize(optimize_all, iters=iterations, n_processes=n_processes, model=pickled_model, args_dict=args_dict, verbose=True)
13 end = time.time()
14 #best_cost, best_pos = optimizer.optimize(qual_obj_func, iters=100, n_processes=1,model=pickled_model, species_log_dict=species_log_dict)

~/virtual/sspeVE/lib/python3.8/site-packages/pyswarms/single/local_best.py in optimize(self, objective_func, iters, n_processes, verbose, **kwargs)
272 self.swarm, self.velocity_clamp, self.vh, self.bounds
273 )
--> 274 self.swarm.position = self.top.compute_position(
275 self.swarm, self.bounds, self.bh
276 )

~/virtual/sspeVE/lib/python3.8/site-packages/pyswarms/backend/topology/ring.py in compute_position(self, swarm, bounds, bh)
168 New position-matrix
169 """
--> 170 return ops.compute_position(swarm, bounds, bh)

~/virtual/sspeVE/lib/python3.8/site-packages/pyswarms/backend/operators.py in compute_position(swarm, bounds, bh)
199
200 if bounds is not None:
--> 201 temp_position = bh(temp_position, bounds)
202
203 position = temp_position

~/virtual/sspeVE/lib/python3.8/site-packages/pyswarms/backend/handlers.py in call(self, position, bounds, **kwargs)
130 """
131 try:
--> 132 new_position = self.strategies[self.strategy](
133 position, bounds, **kwargs
134 )

~/virtual/sspeVE/lib/python3.8/site-packages/pyswarms/backend/handlers.py in periodic(self, position, bounds, **kwargs)
385 )
386 if greater_than_bound[0].size != 0 and greater_than_bound[1].size != 0:
--> 387 new_pos[greater_than_bound] = lb[greater_than_bound] + np.mod(
388 (new_pos[greater_than_bound] - ub[greater_than_bound]),
389 bound_d[greater_than_bound],

IndexError: index 122 is out of bounds for axis 1 with size 1

1

Found the problem, I thought I had to give one bound for all parameters, but it was one bound per parameter.