Use Hypervolume to Evaluate Solutions

Algorithm


In [1]:
import numpy as np

In [65]:
def calculate_2d_hv(solution_set):
    '''
    ::para: solution_set: points set that contians all points in the front(normalized solutions)
    ::return: the hypervolume for all the solutions
    '''
    tmp = solution_set[np.argsort(solution_set[:,0],kind='mergesort')]
    #print(tmp)
    hv = 0
    pervious = 0
    for vec in tmp:
        # vec = np.array(vec)[0]
        # print(vec)
        hv += (vec[0] - pervious)*vec[1]
        pervious = vec[0]
    return hv

In [71]:
def calculate_contribution(total_hv, solution_set, solution_idx):
    '''
    ::param: total_hv of the solution set
    ::param: solution_set
    ::solutoin_idx: the index of solution to be calculated
    '''
    tmp = np.delete(solution_set, (solution_idx), axis = 0)
    contribution = total_hv - calculate_2d_hv(tmp)
    return contribution

Section One


In [66]:
solutions1 = np.array([[1,8],[9,1],[4,7],[8,4],[6,6]])
solutions2 = np.array([[1,8],[9,1],[4,7],[6,6]])
hv01 = calculate_2d_hv(solutions1)
hv02 = calculate_2d_hv(solutions2)
print("hypervolume of figure. 04 (a): %d\nhypervolume of figure. 04 (b): %d" % (hv01,hv02))


hypervolume of figure. 04 (a): 50
hypervolume of figure. 04 (b): 44

Section Two


In [70]:
data200 = np.loadtxt('200points.dat', skiprows=1, delimiter=',')

In [84]:
total_hv = calculate_2d_hv(data200)
print("before selection: %f" % total_hv)


before selection: 4.403850

In [77]:
contri = list()
for i in range(len(data200)):
    contri.append(calculate_contribution(total_hv, data200, i))
selected = data200[np.argsort(contri)[-100:]]

In [80]:
print(selected, len(selected))


[[ 2.94952488  0.99759448]
 [ 2.94919682  0.99763823]
 [ 2.94493675  0.99826407]
 [ 2.94395232  0.99842411]
 [ 2.96539831  0.99612606]
 [ 2.934026    1.00039816]
 [ 2.96488476  0.99615604]
 [ 2.97445345  0.99574578]
 [ 2.93297005  1.00064874]
 [ 2.95969057  0.99651939]
 [ 2.94468999  0.99830365]
 [ 2.95558786  0.99689072]
 [ 2.93427038  1.00034106]
 [ 2.91773176  1.00525486]
 [ 2.92430639  1.00303209]
 [ 2.93374491  1.00046384]
 [ 2.96219873  0.99633014]
 [ 2.91786623  1.00520575]
 [ 2.94868279  0.99770808]
 [ 2.90301037  1.01167369]
 [ 2.92729306  1.00214291]
 [ 2.97172546  0.99583334]
 [ 2.95765686  0.99669373]
 [ 2.96116877  0.99640453]
 [ 2.95848775  0.99662024]
 [ 2.94600487  0.99809682]
 [ 2.92416883  1.00307465]
 [ 2.93807411  0.99951124]
 [ 2.92586374  1.00255942]
 [ 2.93475986  1.0002284 ]
 [ 2.90278387  1.01178885]
 [ 2.92660618  1.00234103]
 [ 2.96941829  0.99592459]
 [ 2.93768263  0.99959207]
 [ 2.95268011  0.99720377]
 [ 2.95343781  0.99711818]
 [ 2.93059015  1.00124478]
 [ 2.92762375  1.00204909]
 [ 2.95071268  0.99744117]
 [ 2.90350962  1.0114212 ]
 [ 2.94684315  0.9979707 ]
 [ 2.94322801  0.99854594]
 [ 2.91704512  1.00550902]
 [ 2.91127348  1.00781512]
 [ 2.9110322   1.00791848]
 [ 2.92993307  1.00141692]
 [ 2.9392724   0.99927109]
 [ 2.93571997  1.0000124 ]
 [ 2.82257056  1.0903883 ]
 [ 2.90153646  1.01243365]
 [ 2.8222611   1.09084797]
 [ 2.91581678  1.00597394]
 [ 2.94103813  0.99893451]
 [ 2.83577728  1.07191753]
 [ 2.88673568  1.02134919]
 [ 2.83542562  1.07238019]
 [ 2.90065169  1.01290095]
 [ 2.91898012  1.0048039 ]
 [ 2.90437269  1.01099062]
 [ 2.88729906  1.02096581]
 [ 2.83740759  1.06979263]
 [ 2.91450167  1.00648725]
 [ 2.84440112  1.06106508]
 [ 2.86100483  1.04284811]
 [ 2.92210174  1.0037359 ]
 [ 2.85919571  1.04466355]
 [ 2.89839745  1.01412785]
 [ 2.88466835  1.02278745]
 [ 2.89660549  1.01514149]
 [ 2.88313341  1.02388668]
 [ 2.8027091   1.12232232]
 [ 2.8380208   1.06900203]
 [ 2.90727234  1.00959921]
 [ 2.89344263  1.01701438]
 [ 2.8621583   1.04171193]
 [ 2.85801935  1.04586613]
 [ 2.89076972  1.018682  ]
 [ 2.84351754  1.06213295]
 [ 2.86714792  1.03698766]
 [ 2.76546431  1.19470632]
 [ 2.86862755  1.0356456 ]
 [ 2.82095432  1.09280193]
 [ 2.87967443  1.02646434]
 [ 2.84626985  1.05883932]
 [ 2.82367969  1.08875132]
 [ 2.80466962  1.11895263]
 [ 2.87524891  1.02996671]
 [ 2.83359361  1.07481718]
 [ 2.85326099  1.05090868]
 [ 2.80154514  1.12434435]
 [ 2.80990076  1.1101923 ]
 [ 2.76693487  1.19156766]
 [ 2.81538105  1.10137844]
 [ 2.7630136   1.19998324]
 [ 2.99541044  0.99554724]
 [ 2.78248358  1.15973127]
 [ 2.71618009  1.31010318]
 [ 2.73131371  1.272874  ]
 [ 2.69310117  1.3687098 ]
 [ 2.63536501  1.51545441]] 100

In [83]:
print("after selection: %f" % calculate_2d_hv(selected))


after selection: 4.403847