def calc_hypervol(ref=[], front=[], minimize=True, **kwargs): """Calculate hypervolume metrics of a Pareto set, given a reference point. Parameters ---------- ref : {1D-array-like}, shape (n_objectives, ) The reference point. front : {array-like, sparse matrix}, shape (n_optimals, n_objectives) The Pareto optimals on which to calculate hypervolume. Returns ------- hypevol : scalar, the calculated hypervolume between the reference point and the Pareto optimals. """ # return distance if single objective if front.shape[1] == 1: return np.subtract(front.ravel() - ref).sum() elif front.shape[1] == 2: _fs = front[ front[:, 0].argsort()[::-1] ] return _calc_hypervol(ref=ref, front=_fs, minimize=minimize, **kwargs) else: pass return hypervolume(front, ref)
def test_2d(): front = np.loadtxt( os.path.join(os.path.dirname(__file__), 'fixtures', 'CF7.dat')) ref = np.array([1.1, 1.1]) hv1 = wfg(front, ref) hv2 = hv.hypervolume(front, ref) assert abs(hv1 - hv2) <= 1e-12
def calculateHypervolume(d2Points, d1Reference): """Returns the Hypervolume Indicator (total area contained by the Pareto Front). d2Points -- a 2D array of locations (each row is a location) d1Reference -- a D-element list specifying the nadir point (e.g. [5, 5, 5, 5]) Returns a float for the Hypervolume Indicator value """ return hv.hypervolume(d2Points, d1Reference)
def my_nsga2(n, nbgen, evaluate, ref_point=np.array([1, 1]), IND_SIZE=5, weights=(-1.0, -1.0)): """NSGA-2 NSGA-2 :param n: taille de la population :param nbgen: nombre de generation :param evaluate: la fonction d'évaluation :param ref_point: le point de référence pour le calcul de l'hypervolume :param IND_SIZE: la taille d'un individu :param weights: les poids à utiliser pour la fitness (ici ce sera (-1.0,) pour une fonction à minimiser et (1.0,) pour une fonction à maximiser) """ creator.create("MaFitness", base.Fitness, weights=weights) creator.create("Individual", list, fitness=creator.MaFitness) toolbox = base.Toolbox() paretofront = tools.ParetoFront() # à compléter # Pour récupérer l'hypervolume, nous nous contenterons de mettre les différentes aleur dans un vecteur s_hv qui sera renvoyé par la fonction. pointset = [np.array(ind.fitness.getValues()) for ind in paretofront] s_hv = [hv.hypervolume(pointset, ref_point)] # Begin the generational process for gen in range(1, nbgen): if (gen % 10 == 0): print("+", end="", flush=True) else: print(".", end="", flush=True) # à completer pointset = [np.array(ind.fitness.getValues()) for ind in paretofront] s_hv.append(hv.hypervolume(pointset, ref_point)) return population, paretofront, s_hv
def compute_hvolume(obj: np.ndarray, ref: np.ndarray=None) -> float: assert len(obj.shape) == 2 if ref is None: ref = np.ones(obj.shape[1]) valid = np.all(np.less(obj, ref), axis=1) obj = obj[valid] obj = obj[non_dominated_selection(obj)] hv = hypervolume(obj, ref) return hv