Skip to content

Commit

Permalink
Minor modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
blankjul committed Mar 4, 2019
1 parent be6987a commit 7412348
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
14 changes: 11 additions & 3 deletions pymoo/algorithms/so_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

class DifferentialEvolution(GeneticAlgorithm):
def __init__(self,
variant="DE/rand+best/1/exp",
variant="DE/rand+best/1/bin",
CR=0.5,
F=0.75,
n_replace=None,
**kwargs):

_, self.var_selection, self.var_n, self.var_mutation, = variant.split("/")
Expand All @@ -28,6 +29,7 @@ def __init__(self,
set_if_none(kwargs, 'survival', None)
super().__init__(**kwargs)

self.n_replace = n_replace
self.func_display_attrs = disp_single_objective

def _next(self, pop):
Expand Down Expand Up @@ -75,8 +77,14 @@ def _next(self, pop):
_F, _CV, _feasible = self.off.get("F", "CV", "feasible")
_F = parameter_less(_F, _CV)

# replace if better
is_better = (_F <= F)[:, 0]
# find the individuals which are indeed better
is_better = np.where((_F <= F)[:, 0])[0]

# truncate the replacements if desired
if self.n_replace is not None and self.n_replace < len(is_better):
is_better = is_better[random.perm(len(is_better))[:self.n_replace]]

# replace the individuals in the population
pop[is_better] = self.off[is_better]

return pop
4 changes: 1 addition & 3 deletions pymoo/indicators/igd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ def dist(A, B):
return np.sqrt(np.sum(np.square((A - B) / self.N), axis=1))

D = vectorized_cdist(self.pareto_front, F, dist)
#_D = cdist(self.pareto_front, F, metric=lambda u, v: np.sqrt((((u - v)/self.N) ** 2).sum()))

else:
D = cdist(self.pareto_front, F)

#np.all(np.abs(cdist(self.pareto_front, F) - D) < 1e-4)

return np.mean(np.min(D, axis=1))
6 changes: 5 additions & 1 deletion pymoo/usage/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
res = minimize(problem,
method='de',
method_args={
'pop_size': 100
'variant': "DE/best/1/bin",
'CR': 2,
'F': 0.75,
'n_replace': 5,
'pop_size': 200
},
termination=('n_gen', 1000),
disp=True)
Expand Down

0 comments on commit 7412348

Please sign in to comment.