problem.directions[:] = DIRECTIONS
    
    # Experimenter with NSGAII, NSGAIII and SPEA2
    algorithms = [(NSGAII, {"population_size":POPSIZE}),
                (NSGAIII, {"population_size":POPSIZE, "divisions_outer":12}),
                (SPEA2, {"population_size":POPSIZE})
                ]

    # Multi-processing (4 parallel processes)
    with ProcessPoolEvaluator(4) as evaluator:
        results = experiment(algorithms, problem, nfe=FEs, seeds=n_reps , evaluator=evaluator, display_stats=True)

        # As of Platypus v1.0.4, NSGA-III works only with minimization objectives
        # Converting first objective (Apoptosis) back to positive
        for alg in ["NSGAII", "NSGAIII", "SPEA2"]:
            for run in range(len(results[alg]["Problem"])):
                for ind in range(len(results[alg]["Problem"][0])):
                    results[alg]["Problem"][run][ind].objectives[0] = -results[alg]["Problem"][run][ind].objectives[0]
                    results[alg]["Problem"][run][ind].problem.directions[0] = 1

        # Save results in pickle
        import pickle
        pickle.dump(results, open("res_3obj_"+str(n_reps)+"reps.p", "wb"))
        
        # Calculate Hypervolume
        hyp = Hypervolume(minimum=[-1.0, -1.0, 0], maximum=[1.0, 1.0, 16])
        hyp_result = calculate(results, hyp, evaluator=evaluator)
        display(hyp_result, ndigits=3)
        with open("hypervolume_3obj_"+str(n_reps)+"reps.txt", 'w') as f:
            print(hyp_result, file=f)
Ejemplo n.º 2
0
plt.legend(numpoints=1)
# plt.xlim(0, 50);
plt.xlabel("Compilation Time(in ms)")
plt.ylabel("Execution Time(in ms)")
plt.title(
    "Comparision of Compilation and Execution time \n of various compiler optimization approaches"
)

# # Hypervolume

# In[ ]:

from platypus import Hypervolume, experiment, calculate, display

hyp = Hypervolume(minimum=[0, 0, 0], maximum=[1, 1, 1])
hyp_result = calculate(results, hyp)
display(hyp_result, ndigits=5)

print(hyp_result)

# # Compilation and Execution time of Optimization levels

# In[1012]:

import matplotlib.pyplot as plt
import numpy as np
import collections
fig = plt.figure()

X = np.arange(4)
fig = plt.figure()
Ejemplo n.º 3
0
from platypus import NSGAII, Problem, Real, nondominated, Hypervolume, calculate


def belegundu(vars):
    x = vars[0]
    y = vars[1]
    return [-2 * x + y, 2 * x + y], [-x + y - 1, x + y - 7]


problem = Problem(2, 2, 2)
problem.types[:] = [Real(0, 5), Real(0, 3)]
problem.constraints[:] = "<=0"
problem.function = belegundu

algorithm = NSGAII(problem)
algorithm.run(10000)

feasible_solutions = [s for s in algorithm.result if s.feasible]
nondominated_solutions = nondominated(algorithm.result)

hyp = Hypervolume(minimum=[0, 0, 0], maximum=[1, 1, 1])
hyp_result = calculate(algorithm.result, hyp)
print(hyp_result)
pass
Ejemplo n.º 4
0
    }

    for i in range(num_iter):
        algorithm = NSGAII(SVM(), population_size=pop)

        for j in tqdm(range(generations_amount),
                      desc="Iteration " + str(i + 1)):
            algorithm.step()
            # Defining structure to pass as parameter to class Hypervolume
            nsga_results = OrderedDict()
            nsga_results["NSGAII"] = {}
            nsga_results["NSGAII"]["SVM"] = [algorithm.result]

            # calculate the hypervolume indicator
            hyp = Hypervolume(minimum=[0, 0, 0], maximum=[1, 1, 1])
            hyp_result = calculate(nsga_results, hyp)
            hypervolume = np.mean(
                list(hyp_result["NSGAII"]["SVM"]["Hypervolume"]))
            hypervolumes[i].append(hypervolume)

        nondominated_results = nondominated(algorithm.result)
        # display(hipervolume, ndigits=3)
        solution = nondominated_results[0]
        features = solution.variables[0]
        for s in nondominated_results:
            if abs(s.objectives[0] -
                   s.objectives[1]) < abs(solution.objectives[0] -
                                          solution.objectives[1]):
                solution = s
                features = s.variables[0]
Ejemplo n.º 5
0
from platypus import NSGAII, NSGAIII, DTLZ2, Hypervolume, experiment, calculate, display

if __name__ == "__main__":
    algorithms = [NSGAII, (NSGAIII, {"divisions_outer":12})]
    problems = [DTLZ2(3)]

    # run the experiment
    results = experiment(algorithms, problems, nfe=10000, seeds=10)

    # calculate the hypervolume indicator
    hyp = Hypervolume(minimum=[0, 0, 0], maximum=[1, 1, 1])
    hyp_result = calculate(results, hyp)
    display(hyp_result, ndigits=3)