Obtain documentation for a module implementing the NSGA-II algorithm
<p>I am attempting to use the implementation of the NSGA-II algorithm in this module <a href="https://github.com/wreszelewski/nsga2" rel="nofollow">https://github.com/wreszelewski/nsga2</a></p>

<p><strong>Question</strong></p>

<p>Where can I find documentation for this module?</p>

<p>The documentation seems to be limited to the examples provided by the author. <a href="https://github.com/wreszelewski/nsga2/tree/master/examples" rel="nofollow">https://github.com/wreszelewski/nsga2/tree/master/examples</a> </p>

<p><strong>Collecting metrics during evolution, then plotting hvr metric per generation</strong></p>

<pre><code>from metrics.problems.zdt import ZDT3Metrics
from nsga2.evolution import Evolution
from nsga2.problems.zdt import ZDT
from nsga2.problems.zdt.zdt3_definitions import ZDT3Definitions
from plotter import Plotter

def print_generation(population, generation_num):
    print("Generation: {}".format(generation_num))

def print_metrics(population, generation_num):
    pareto_front = population.fronts[0]
    metrics = ZDT3Metrics()
    hv = metrics.HV(pareto_front)
    hvr = metrics.HVR(pareto_front)
    print("HV: {}".format(hv))
    print("HVR: {}".format(hvr))

collected_metrics = {}
def collect_metrics(population, generation_num):
    pareto_front = population.fronts[0]
    metrics = ZDT3Metrics()
    hv = metrics.HV(pareto_front)
    hvr = metrics.HVR(pareto_front)
    collected_metrics[generation_num] = hv, hvr

zdt_definitions = ZDT3Definitions()
plotter = Plotter(zdt_definitions)
problem = ZDT(zdt_definitions)
evolution = Evolution(problem, 200, 200)
evolution.register_on_new_generation(plotter.plot_population_best_front)
evolution.register_on_new_generation(print_generation)
evolution.register_on_new_generation(print_metrics)
evolution.register_on_new_generation(collect_metrics)
pareto_front = evolution.evolve()

plotter.plot_x_y(collected_metrics.keys(), map(lambda (hv, hvr): hvr, collected_metrics.values()), 'generation', 'HVR', 'HVR metric for ZDT3 problem', 'hvr-zdt3')
</code></pre>

<p><strong>Collecting metrics during evolution, then plotting hvr metric per generation</strong></p>

<pre><code>import os
import matplotlib.pyplot as pyplot

class Plotter():
    def __init__(self, problem):
        self.directory = 'plots'
        self.problem = problem

    def plot_population_best_front(self, population, generation_number):
        if generation_number % 10 == 0:
            filename = "{}/generation{}.png".format(self.directory, str(generation_number))
            self.__create_directory_if_not_exists()
            computed_pareto_front = population.fronts[0]
            self.__plot_front(computed_pareto_front, filename)

    def plot_x_y(self, x, y, x_label, y_label, title, filename):
        filename = "{}/{}.png".format(self.directory, filename)
        self.__create_directory_if_not_exists()
        figure = pyplot.figure()
        axes = figure.add_subplot(111)
        axes.plot(x, y, 'r')
        axes.set_xlabel(x_label)
        axes.set_ylabel(y_label)
        axes.set_title(title)
        pyplot.savefig(filename)
        pyplot.close(figure)

    def __create_directory_if_not_exists(self):
        if not os.path.exists(self.directory):
            os.makedirs(self.directory)

    def __plot_front(self, front, filename):
        figure = pyplot.figure()
        axes = figure.add_subplot(111)

        computed_f1 = map(lambda individual: individual.objectives[0], front)
        computed_f2 = map(lambda individual: individual.objectives[1], front)
        axes.plot(computed_f1, computed_f2, 'g.')

        perfect_pareto_front_f1, perfect_pareto_front_f2 = self.problem.perfect_pareto_front()
        axes.plot(perfect_pareto_front_f1, perfect_pareto_front_f2, 'r.')

        axes.set_xlabel('f1')
        axes.set_ylabel('f2')
        axes.set_title('Computed Pareto front')
        pyplot.savefig(filename)
        pyplot.close(figure)
</code></pre>

<p>Do they help you? </p>

python module