Skip to content

Commit 6730515

Browse files
authoredJul 10, 2024··
Merge pull request #536 from NiaOrg/fix-numpy-compat
fixed numpy compatibility errors
2 parents 25922b2 + 6ba82fa commit 6730515

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
 

‎niapy/algorithms/modified/shade.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def evolve(self, pop, hist_cr, hist_f, archive, arc_ind_cnt, task, **_kwargs):
271271
272272
"""
273273
new_pop = objects_to_array([self.gen_ind_params(xi, hist_cr, hist_f) for xi in pop])
274-
p_num = np.int_(np.around(len(pop) * self.pbest_factor))
274+
p_num = round(len(pop) * self.pbest_factor)
275275
if p_num < 2:
276276
p_num = 2
277277
# cr and f for mutation are computed
@@ -309,7 +309,7 @@ def selection(self, pop, new_pop, archive, arc_ind_cnt, best_x, best_fitness, ta
309309
success_f = np.asarray([]) # array for storing successful f values
310310
success_cr = np.asarray([]) # array for storing successful cr values
311311
fitness_diff = np.asarray([]) # array for storing the difference of fitness of new individuals
312-
archive_size = np.int_(np.around(len(pop) * self.extern_arc_rate))
312+
archive_size = round(len(pop) * self.extern_arc_rate)
313313
arr = np.copy(pop)
314314
for i, vi in enumerate(new_pop):
315315
if vi.f == pop[i].f:
@@ -380,7 +380,7 @@ def init_population(self, task):
380380
h_mem_f = np.full(self.hist_mem_size, 0.5)
381381
# all values in the historical memory for parameters f and cr are initialized to 0.5
382382
k = 0 # the starting memory position is set to 1
383-
arc_size = np.int_(np.around(self.population_size * self.extern_arc_rate))
383+
arc_size = round(self.population_size * self.extern_arc_rate)
384384
archive = np.zeros((arc_size, task.dimension))
385385
# the external archive of max size pop_size * arc_rate is initialized
386386
arc_ind_cnt = 0 # the number of archive elements is set to 0
@@ -514,7 +514,7 @@ def post_selection(self, pop, arc, arc_ind_cnt, task, xb, fxb, **kwargs):
514514
max_nfe = task.max_evals
515515
nfe = task.evals
516516

517-
next_pop_size = np.int_(np.around((((4.0 - self.population_size) / np.float_(max_nfe)) * nfe) + self.population_size))
517+
next_pop_size = round((((4.0 - self.population_size) / max_nfe) * nfe) + self.population_size)
518518

519519
if next_pop_size < 4:
520520
next_pop_size = 4
@@ -529,7 +529,7 @@ def post_selection(self, pop, arc, arc_ind_cnt, task, xb, fxb, **kwargs):
529529
worst = j if e.f > pop[worst].f else worst
530530
pop = np.delete(pop, worst)
531531

532-
next_arc_size = np.int_(next_pop_size * self.extern_arc_rate) # the size of the new archive
532+
next_arc_size = int(next_pop_size * self.extern_arc_rate) # the size of the new archive
533533
if arc_ind_cnt > next_arc_size:
534534
arc_ind_cnt = next_arc_size
535535

0 commit comments

Comments
 (0)