Skip to content

Commit

Permalink
Added an indicator module that contains the hypervolume least contrib…
Browse files Browse the repository at this point in the history
…utor function

--HG--
branch : dev
  • Loading branch information
fmder committed Apr 29, 2014
1 parent 53c713b commit 8a9c00f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
20 changes: 15 additions & 5 deletions deap/cma.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ def __init__(self, population, sigma, **params):
self.computeParams(params)
self.psucc = [self.ptarg] * len(population)

self.indicator = params.get("indicator", tools.indicator.hypervolume)

self.success_count = 0

def computeParams(self, params):
Expand Down Expand Up @@ -394,12 +396,20 @@ def update(self, population):
# as the worst in each dimension +1
ref = numpy.array([ind.fitness.wvalues for ind in candidates]) * -1
ref = numpy.max(ref, axis=0) + 1
keep_idx = tools.hypervolume_kmax(mid_front, k, ref)
rm_idx = set(range(len(mid_front))) - set(keep_idx)
chosen += [mid_front[i] for i in keep_idx]
not_chosen += [mid_front[i] for i in rm_idx]

print(len(chosen))
for i in range(len(mid_front) - k):
idx = self.indicator(mid_front, ref)
not_chosen.append(mid_front.pop(idx))

chosen += mid_front

# rm_idx = set(range(len(mid_front))) - set(keep_idx)
# print keep_idx
# print rm_idx
# chosen += [mid_front[i] for i in keep_idx]
# not_chosen += [mid_front[i] for i in rm_idx]

print("mid front size", self.mid_front_size)

cp, cc, ccov = self.cp, self.cc, self.ccov
d, ptarg, pthresh = self.d, self.ptarg, self.pthresh
Expand Down
2 changes: 1 addition & 1 deletion deap/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .constraint import *
from .crossover import *
from .emo import *
from .hv import *
from .indicator import *
from .init import *
from .migration import *
from .mutation import *
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env python
import sys
from distutils.core import setup
from distutils.core import setup, Extension
try:
from distutils.command.build_py import build_py_2to3 as build_py
except ImportError:
from distutils.command.build_py import build_py

import deap

hv_module = Extension("deap.tools.hv", sources=["deap/tools/_hv.c", "deap/tools/hv.cpp"])

setup(name='deap',
version=deap.__revision__,
description='Distributed Evolutionary Algorithms in Python',
Expand All @@ -30,6 +32,6 @@
'Topic :: Scientific/Engineering',
'Topic :: Software Development',
],
ext_modules = [],
ext_modules = [hv_module],
cmdclass = {'build_py': build_py}
)

0 comments on commit 8a9c00f

Please sign in to comment.