def setUp(self):
     self.r = [4, 4]
     self.hv2d_eq_0 = hypervolume([[3, 1], [2, 2], [1, 3]])  # LC in [0,1,2]
     self.hv2d_eq_1 = hypervolume([[2.5, 1], [2, 2], [1, 3]])  # LC = 1
     self.hv2d_0 = hypervolume([[3.5, 1], [2, 2], [1, 3]])
     self.hv2d_1 = hypervolume([[3, 1], [2.5, 2.5], [1, 3]])
     self.hv2d_2 = hypervolume([[3, 1], [2, 2], [1, 3.5]])
 def setUp(self):
     self.r = [4, 4]
     self.hv2d_eq_0 = hypervolume([[3, 1], [2, 2], [1, 3]])  # LC in [0,1,2]
     self.hv2d_eq_1 = hypervolume([[2.5, 1], [2, 2], [1, 3]])  # LC = 1
     self.hv2d_0 = hypervolume([[3.5, 1], [2, 2], [1, 3]])
     self.hv2d_1 = hypervolume([[3, 1], [2.5, 2.5], [1, 3]])
     self.hv2d_2 = hypervolume([[3, 1], [2, 2], [1, 3.5]])
    def test4d_duplicate(self):
        hv = hypervolume([[1, 1, 1, 1], [1, 1, 1, 1]])
        self.assertEqual(
            hv.compute(r=(2, 2, 2, 2), algorithm=hv_algorithm.hv4d()), 1)
        self.assertEqual(
            hv.compute(r=(2, 2, 2, 2), algorithm=hv_algorithm.fpl()), 1)

        # Duplicate and dominated
        hv = hypervolume([[1, 1, 1, 1], [1, 1, 1, 1], [0, 0, 0, 0]])
        self.assertEqual(
            hv.compute(r=(2, 2, 2, 2), algorithm=hv_algorithm.hv4d()), 16)
        self.assertEqual(
            hv.compute(r=(2, 2, 2, 2), algorithm=hv_algorithm.fpl()), 16)
    def test4d_duplicate(self):
        hv = hypervolume([[1, 1, 1, 1], [1, 1, 1, 1]])
        self.assertEqual(
            hv.compute(r=(2, 2, 2, 2), algorithm=hv_algorithm.hv4d()), 1)
        self.assertEqual(
            hv.compute(r=(2, 2, 2, 2), algorithm=hv_algorithm.fpl()), 1)

        # Duplicate and dominated
        hv = hypervolume([[1, 1, 1, 1], [1, 1, 1, 1], [0, 0, 0, 0]])
        self.assertEqual(
            hv.compute(r=(2, 2, 2, 2), algorithm=hv_algorithm.hv4d()), 16)
        self.assertEqual(
            hv.compute(r=(2, 2, 2, 2), algorithm=hv_algorithm.fpl()), 16)
    def test3d_extreme(self):
        """
        Combine extreme points together.
        Mixing small and large contributions in a single front
        """

        # Reset the set S.
        # 3 duplicate points
        R = (0, 0, 0)
        S = ((-1, -1, -1), ) * 3
        self.assertContribs(S, R, (0, ) * 3)

        # Adding a point far away
        S += ((-1000, ) * 3, )
        self.assertContribs(S, R, (0, 0, 0, 999999999))

        # Adding an even further point
        S += ((-10000, ) * 3, )
        self.assertContribs(S, R, (0, 0, 0, 0, 999000000000))

        # Tiny box on top of a large one
        S = ((-1000.001, -0.001, -0.001), (-1000, -1000, -1000))
        R = (0, 0, 0)
        hv = hypervolume(S)
        ans = (0.000000001, 999999999.999)
        c = list(hv.contributions(R))
        # Round contribution to 9th decimal place as the double type is loosing
        # the exact accuracy
        c[0] = round(c[0], 9)
        self.assertEqual(tuple(c), ans)
Beispiel #6
0
    def get_hypervolume(self, reference=None):

        if reference is None:
            reference = [1000.0] * len(self.funs)

        hv = hypervolume(self.pop)
        return hv.compute(r=reference)
    def test3d_extreme(self):
        """
        Combine extreme points together.
        Mixing small and large contributions in a single front
        """

        # Reset the set S.
        # 3 duplicate points
        R = (0, 0, 0)
        S = ((-1, -1, -1),) * 3
        self.assertContribs(S, R, (0,) * 3)

        # Adding a point far away
        S += ((-1000,) * 3,)
        self.assertContribs(S, R, (0, 0, 0, 999999999))

        # Adding an even further point
        S += ((-10000,) * 3,)
        self.assertContribs(S, R, (0, 0, 0, 0, 999000000000))

        # Tiny box on top of a large one
        S = ((-1000.001, -0.001, -0.001), (-1000, -1000, -1000))
        R = (0, 0, 0)
        hv = hypervolume(S)
        ans = (0.000000001, 999999999.999)
        c = list(hv.contributions(R))
        # Round contribution to 9th decimal place as the double type is loosing
        # the exact accuracy
        c[0] = round(c[0], 9)
        self.assertEqual(tuple(c), ans)
    def test_correct_out(self):
        # simple 3D test
        hv = hypervolume([[1, 1, 1], [2, 2, 2, ]])
        self.assertEqual(hv.compute(r=[3, 3, 3]), 8)

        # simple 2D test
        hv = hypervolume([[1, 2], [2, 1]])
        self.assertEqual(hv.compute(r=[3, 3]), 3)

        # point on the border of refpoint (2D)
        hv = hypervolume([[1, 2], [2, 1]])
        self.assertEqual(hv.compute([2, 2]), 0)

        # points on the border of refpoint (3D)
        hv = hypervolume([[1, 2, 1], [2, 1, 1]])
        self.assertEqual(hv.compute([2, 2, 2]), 0)
 def test_gettersetter(self):
     hv = hypervolume([[1, 2, 3], [4, 5, 6]])
     self.assertTrue(hv.get_verify())
     self.assertTrue(hv.get_copy_points())
     hv.set_verify(False)
     hv.set_copy_points(False)
     self.assertTrue(hv.get_verify() is False)
     self.assertTrue(hv.get_copy_points() is False)
 def test_tuple_ctor(self):
     # test that hypervolume can be computed using a tuple as well
     hv = hypervolume(((1, 1, 1), (
         2,
         2,
         2,
     )))
     self.assertEqual(hv.compute(r=(3, 3, 3)), 8)
 def test_gettersetter(self):
     hv = hypervolume([[1, 2, 3], [4, 5, 6]])
     self.assertTrue(hv.get_verify())
     self.assertTrue(hv.get_copy_points())
     hv.set_verify(False)
     hv.set_copy_points(False)
     self.assertTrue(hv.get_verify() is False)
     self.assertTrue(hv.get_copy_points() is False)
    def test_hv4d(self):
        hv3d = hypervolume(self.ps3d_0)
        hv4d = hypervolume(self.ps4d_0)

        self.assertEqual(
            1.0, hv4d.compute(self.r4d_0, algorithm=hv_algorithm.hv4d()))
        self.assertRaises(ValueError,
                          hv3d.compute,
                          r=self.r3d_0,
                          algorithm=hv_algorithm.hv4d())
        self.assertRaises(ValueError,
                          hv3d.compute,
                          r=self.r4d_0,
                          algorithm=hv_algorithm.hv4d())
        self.assertRaises(ValueError,
                          hv4d.compute,
                          r=self.r3d_0,
                          algorithm=hv_algorithm.hv4d())
 def assertContribs(self, S, R, ans):
     """
     This method is an assertion that given hypervolume problem constructed from S, with a reference point R
     Returns a valid answer to the "contributions" feature both for the contributions method and the explicit call
     for the exclusive hypervolume as well.
     """
     hv = hypervolume(S)
     self.assertEqual(hv.contributions(R), ans)
     self.assertEqual(tuple(hv.exclusive(i, R) for i in range(len(S))), ans)
 def assertContribs(self, S, R, ans):
     """
     This method is an assertion that given hypervolume problem constructed from S, with a reference point R
     Returns a valid answer to the "contributions" feature both for the contributions method and the explicit call
     for the exclusive hypervolume as well.
     """
     hv = hypervolume(S)
     self.assertEqual(hv.contributions(R), ans)
     self.assertEqual(tuple(hv.exclusive(i, R) for i in range(len(S))), ans)
 def test_refpoint_not_dom(self):
     # refpoint must be at least weakly dominated by every point (assuming
     # minimization problem)
     hv = hypervolume([[1, 3], [2, 2], [3, 1]])
     # equal to some other point
     self.assertRaises(ValueError, hv.compute, [3, 1])
     # refpoint dominating some points
     self.assertRaises(ValueError, hv.compute, [1.5, 1.5])
     # refpoint dominating all points
     self.assertRaises(ValueError, hv.compute, [0, 0])
 def test_refpoint_not_dom(self):
     # refpoint must be at least weakly dominated by every point (assuming
     # minimization problem)
     hv = hypervolume([[1, 3], [2, 2], [3, 1]])
     # equal to some other point
     self.assertRaises(ValueError, hv.compute, [3, 1])
     # refpoint dominating some points
     self.assertRaises(ValueError, hv.compute, [1.5, 1.5])
     # refpoint dominating all points
     self.assertRaises(ValueError, hv.compute, [0, 0])
    def test_correct_out(self):
        # simple 3D test
        hv = hypervolume([[1, 1, 1], [
            2,
            2,
            2,
        ]])
        self.assertEqual(hv.compute(r=[3, 3, 3]), 8)

        # simple 2D test
        hv = hypervolume([[1, 2], [2, 1]])
        self.assertEqual(hv.compute(r=[3, 3]), 3)

        # point on the border of refpoint (2D)
        hv = hypervolume([[1, 2], [2, 1]])
        self.assertEqual(hv.compute([2, 2]), 0)

        # points on the border of refpoint (3D)
        hv = hypervolume([[1, 2, 1], [2, 1, 1]])
        self.assertEqual(hv.compute([2, 2, 2]), 0)
Beispiel #18
0
def hvContribution(Pop, Zmin, a):

    hvCont = np.zeros(Pop.NPop)
    indND = np.where(Pop.rank == 1)[0]
    NDobj = Pop.obj[indND] * a + Zmin
    ref = NDobj.max(axis=0) * 1.1
    hv = hypervolume(NDobj.tolist())
    for i in np.arange(len(indND)):
        hvCont[indND[i]] = hv.exclusive(i, ref.tolist())

    Pop.hvCont = hvCont
    def test_hv4d(self):
        hv3d = hypervolume(self.ps3d_0)
        hv4d = hypervolume(self.ps4d_0)

        self.assertEqual(
            1.0, hv4d.compute(self.r4d_0, algorithm=hv_algorithm.hv4d()))
        self.assertRaises(
            ValueError,
            hv3d.compute,
            r=self.r3d_0,
            algorithm=hv_algorithm.hv4d())
        self.assertRaises(
            ValueError,
            hv3d.compute,
            r=self.r4d_0,
            algorithm=hv_algorithm.hv4d())
        self.assertRaises(
            ValueError,
            hv4d.compute,
            r=self.r3d_0,
            algorithm=hv_algorithm.hv4d())
    def test_pop_ctor(self):
        # constructs the hypervolume object from a population object, expects
        # to not raise any error
        prob = problem.zdt(2)
        pop = population(prob, 100)

        # construction from a population object
        hypervolume(pop)

        # setting verification flag to False
        hypervolume(pop, False)

        # setting verification flag to True
        hypervolume(pop, True)
    def test_pop_ctor(self):
        # constructs the hypervolume object from a population object, expects
        # to not raise any error
        prob = problem.zdt(2)
        pop = population(prob, 100)

        # construction from a population object
        hypervolume(pop)

        # setting verification flag to False
        hypervolume(pop, False)

        # setting verification flag to True
        hypervolume(pop, True)
 def setUp(self):
     self.r = [4, 4]
     # all are equal (take first -> idx = 0)
     self.hv2d = hypervolume([[3, 1], [2, 2], [1, 3]])
     # all are equal (take first -> idx = 0)
     self.hv2d_2 = hypervolume([[3.1, 1], [2, 2], [1, 3]])
 def test4d_dominated(self):
     hv = hypervolume([[1, 1, 1, 1], [2, 2, 2, 2]])
     self.assertEqual(
         hv.compute(r=(3, 3, 3, 3), algorithm=hv_algorithm.hv4d()), 16)
     self.assertEqual(
         hv.compute(r=(3, 3, 3, 3), algorithm=hv_algorithm.fpl()), 16)
 def test4d_edge(self):
     hv = hypervolume([[1, 1, 1, 3], [2, 2, 2, 3]])
     self.assertEqual(
         hv.compute(r=(3, 3, 3, 3), algorithm=hv_algorithm.hv4d()), 0)
     self.assertEqual(
         hv.compute(r=(3, 3, 3, 3), algorithm=hv_algorithm.fpl()), 0)
 def setUp(self):
     self.r = [4, 4]
     # all are equal (take first -> idx = 0)
     self.hv2d = hypervolume([[3, 1], [2, 2], [1, 3]])
     # all are equal (take first -> idx = 0)
     self.hv2d_2 = hypervolume([[3.1, 1], [2, 2], [1, 3]])
 def test_tuple_ctor(self):
     # test that hypervolume can be computed using a tuple as well
     hv = hypervolume(((1, 1, 1), (2, 2, 2,)))
     self.assertEqual(hv.compute(r=(3, 3, 3)), 8)
 def setUp(self):
     self.hv2d = hypervolume([[3, 1], [2, 2], [1, 3]])
 def test4d_edge(self):
     hv = hypervolume([[1, 1, 1, 3], [2, 2, 2, 3]])
     self.assertEqual(
         hv.compute(r=(3, 3, 3, 3), algorithm=hv_algorithm.hv4d()), 0)
     self.assertEqual(
         hv.compute(r=(3, 3, 3, 3), algorithm=hv_algorithm.fpl()), 0)
Beispiel #29
0
    def compute_hypervolume(self, pop):
        if pop.champion.f[0] == self._UNFEASIBLE:
            raise Exception('Input population contains only unfeasible individuals')
        hv = hypervolume(pop)

        return (hv.compute(self._compute_ref_point()) * DAY2SEC / AU)
Beispiel #30
0
#
# alg = algorithm.nsga_II(gen = 100, cr = 0.95, eta_c = 10, m = 0.01, eta_m = 50)
# pop = population(prob, pop_size) #Genero poblacion inicial aleatoria del problema ZDT
# pop2 = population(prob, pop_size)
valores_pdistance=[]
valores_hv=[]
for i in range(rep):
    pop = population(prob, pop_size) #Genero poblacion inicial aleatoria del problema ZDT
    pop = alg.evolve(pop) #Poblacion final al ejecutar el algoritmo
    # pop3 = alg3.evolve(pop3)
    pop=eliminar_dominadas(pop) #Dejo solo las soluciones no dominadas de la poblacion final
    pop.plot_pareto_fronts() #Pinto las soluciones en el grafic
    # pop3.plot_pareto_fronts()

    valores_pdistance=valores_pdistance+[prob.p_distance(pop)] #Obtengo de la poblacion no dominada
    hv= hypervolume(pop) #Obtengo de la poblacion no dominada el hipervolumen
    ref_point = hv.get_nadir_point(0.1)
    valores_hv=valores_hv+[hv.compute(r=ref_point)] #Computo el hipervolumen especificando la referencia


#Obtengo la media y desviacion tipica de la distancia generacional y el hipervolumen
print 'mean p-distance SPEA'
print numpy.mean(valores_pdistance)
print 'standard deviation p-distance SPEA'
print numpy.std(valores_pdistance)
print 'mean hypervolume SPEA'
print numpy.mean(valores_hv)
print 'standard deviation hypervolume SPEA'
print numpy.std(valores_hv)

plt.show()
 def setUp(self):
     self.hv2d = hypervolume([[3, 1], [2, 2], [1, 3]])
Beispiel #32
0
 def compute_hypervolume(self, pop):
     if pop.champion.f[0] == self._UNFEASIBLE:
         raise Exception(
             'Input population contains only unfeasible individuals')
     hv = hypervolume(pop)
     return (hv.compute(self._compute_ref_point()) * DAY2SEC / AU)
 def test4d_dominated(self):
     hv = hypervolume([[1, 1, 1, 1], [2, 2, 2, 2]])
     self.assertEqual(
         hv.compute(r=(3, 3, 3, 3), algorithm=hv_algorithm.hv4d()), 16)
     self.assertEqual(
         hv.compute(r=(3, 3, 3, 3), algorithm=hv_algorithm.fpl()), 16)
Beispiel #34
0
import numpy as np
from metrics3 import hv2DContribution
from PyGMO.util import hypervolume

N = 10
hvCont = np.zeros(N)
points = np.random.random((N,2))
points = np.sort(points,axis=0)
points[:,1] = points[:,1][::-1]
ref = points.max(axis=0)*1.1
hv = hypervolume(points.tolist())
for i in np.arange(N):
    hvCont[i] = hv.exclusive(i,ref.tolist())

hvCont2 = hv2DContribution(points,ref)

diff = np.sqrt(np.sum((hvCont - hvCont2)**2)/N)

print diff
print hvCont
print hvCont2