コード例 #1
0
    def _select_best(self, pop):
        """Select the best indiividuals of the population.

        :param pop: The population
        :type pop: Any iterable type
        :return: The best individuals found
        :rtype: :py:class:`~deap.tools.HallOfFame` of individuals
        """
        hof = ParetoFront()
        hof.update(pop)
        return hof
コード例 #2
0
def binary_hypervolume_ratio(A, B):
    AB = ParetoFront()
    AB.update(A.items)
    AB.update(B.items)

    fitAB = np.array([fit.values for fit in AB.keys])
    fitA = np.array([fit.values for fit in A.keys])
    ref = np.max(fitAB, axis=0) + 1

    hvAB = hv.hypervolume(fitAB, ref)
    hvA = hv.hypervolume(fitA, ref)

    return hvA / hvAB
コード例 #3
0
ファイル: gptsne_mo.py プロジェクト: algunion/gptsne
def main():
    pop = toolbox.population(n=pop_size)
    stats_fit = tools.Statistics(lambda ind: ind.fitness.values[0])
    stats_size = tools.Statistics(lambda ind: ind.fitness.values[1])
    mstats = tools.MultiStatistics(fitness=stats_fit, size=stats_size)
    mstats.register("min", np.min, axis=0)
    mstats.register("median", np.median, axis=0)
    mstats.register("max", np.max, axis=0)
    # varAnd or varOr
    hof = ParetoFront()
    this_moead = gptsne_moead.GPTSNEMOEAD(tsnedata.data_t,
                                          pop,
                                          toolbox,
                                          len(pop),
                                          cxpb,
                                          mutpb,
                                          tsnedata,
                                          ngen=NGEN,
                                          stats=mstats,
                                          halloffame=hof,
                                          verbose=True,
                                          adapative_mute_ERC=False)
    pop, logbook, hof = this_moead.execute()

    return pop, mstats, hof, logbook
コード例 #4
0
ファイル: gpmal_nc.py プロジェクト: yingbi7460/gpmalmo
def main():
    pop = toolbox.population(n=rd.pop_size)
    stats_cost = tools.Statistics(lambda ind: ind.fitness.values[0])
    stats_num_trees = tools.Statistics(lambda ind: ind.fitness.values[1])
    mstats = tools.MultiStatistics(cost=stats_cost, num_trees=stats_num_trees)
    mstats.register("min", np.min, axis=0)
    mstats.register("median", np.median, axis=0)
    mstats.register("max", np.max, axis=0)
    hof = ParetoFront()
    this_moead = GPMALNCMOEAD(rd.data_t, pop, toolbox, len(pop), rd.cxpb, rd.mutpb, rd,
                              ngen=rd.gens, stats=mstats,
                              halloffame=hof, verbose=True, adapative_mute_ERC=False)
    pop, logbook, hof = this_moead.execute()
    return pop, mstats, hof, logbook
コード例 #5
0
def triple_hypervolume_ratio(A, B, C):
    ABC = ParetoFront()
    ABC.update(A.items)
    ABC.update(B.items)
    ABC.update(C.items)

    fitABC = np.array([fit.values for fit in ABC.keys])
    fitA = np.array([fit.values for fit in A.keys])
    ref = np.max(fitABC, axis=0) + 1

    hvABC = hv.hypervolume(fitABC, ref)
    hvA = hv.hypervolume(fitA, ref)

    return hvA / hvABC
コード例 #6
0
def genetic_algorithm(verbose=False, hack=False):
    pop = toolbox.population(n=MU)
    hof = ParetoFront() # retrieve the best non dominated individuals of the evolution
    
    # Statistics created for compiling four different statistics over the generations
    stats = Statistics(lambda ind: ind.fitness.values)
    stats.register("avg", np.mean, axis=0) # axis=0: compute the statistics on each objective independently
    stats.register("std", np.std, axis=0)
    stats.register("min", np.min, axis=0)
    stats.register("max", np.max, axis=0)
    
    if hack:
        _, logbook, all_generations = \
        eaMuPlusLambda_hack(pop, toolbox, MU, LAMBDA, CXPB, MUTPB, NGEN, stats,
                                  halloffame=hof, verbose=verbose)

        return pop, stats, hof, logbook, all_generations
    else:
        _, logbook = \
        eaMuPlusLambda(pop, toolbox, MU, LAMBDA, CXPB, MUTPB, NGEN, stats,
                                  halloffame=hof, verbose=verbose)

        return pop, stats, hof, logbook
コード例 #7
0
def binary_ternary_hv_ratio(A, B, C):
    AB = ParetoFront()
    AB.update(A.items)
    AB.update(B.items)
    fitAB = np.array([fit.values for fit in AB.keys])

    ABC = ParetoFront()
    ABC.update(AB.items)
    ABC.update(C.items)
    fitABC = np.array([fit.values for fit in ABC.keys])

    AC = ParetoFront()
    AC.update(A.items)
    AC.update(C.items)
    fitAC = np.array([fit.values for fit in AC.keys])

    BC = ParetoFront()
    BC.update(B.items)
    BC.update(C.items)
    fitBC = np.array([fit.values for fit in BC.keys])

    fitA = np.array([fit.values for fit in A.keys])
    fitB = np.array([fit.values for fit in B.keys])
    fitC = np.array([fit.values for fit in C.keys])

    refABC = np.max(fitABC, axis=0) + 1
    refAB = np.max(fitAB, axis=0) + 1
    refAC = np.max(fitAC, axis=0) + 1
    refBC = np.max(fitBC, axis=0) + 1

    hvABC = hv.hypervolume(fitABC, refABC)
    hvAB = hv.hypervolume(fitAB, refAB)
    hvAC = hv.hypervolume(fitAC, refAC)
    hvBC = hv.hypervolume(fitBC, refBC)

    bHV_AB = hv.hypervolume(fitA, refAB) / hvAB
    bHV_AC = hv.hypervolume(fitA, refAC) / hvAC
    bHV_BA = hv.hypervolume(fitB, refAB) / hvAB
    bHV_BC = hv.hypervolume(fitB, refBC) / hvBC
    bHV_CA = hv.hypervolume(fitC, refAC) / hvAC
    bHV_CB = hv.hypervolume(fitC, refBC) / hvBC

    tHV_A = hv.hypervolume(fitA, refABC) / hvABC
    tHV_B = hv.hypervolume(fitB, refABC) / hvABC
    tHV_C = hv.hypervolume(fitC, refABC) / hvABC

    return [tHV_A, tHV_B, tHV_C], [bHV_AB, bHV_AC, bHV_BA, bHV_BC, bHV_CA, bHV_CB]