Beispiel #1
0
def main():
    # initialization
    pic = CorrectImage()
    pic.add_path('data')
    pic.add_image('initial.png')

    pic.hough_transform(vary=False, plot=False)  # set vary True to change edge filters, plot True for visualizations
    pair = pic.line_pair(16)
    slopes = map(pic.slope, pair)
    loss_func = map(lambda s: loss(np.array(s[0]), np.array(s[1])), slopes)

    # print pair
    print loss_func
    print health(loss_func, metric='arc_length'), '\n'

    pop = Population()
    pop.add_parents(pair, loss_func, 4)
    pop.add_children(pic.mutation, p_mutate=0.01)
def main():
    pop = Population()
    pic = CorrectImage()

    pic.add_path('data')
    pic.add_image('initial.png')

    pic.hough_transform(vary=False, plot=False)  # set vary True to change edge filters, plot True for visualizations
    pair = pic.line_pair(800)

    total = 0
    mean = []
    avg_angle, count = 0, 0
    for _ in xrange(500):
        loss_func = evolve(pic, pop, pairs=pair, mutation_probability=0.01)

        pop_health = health(loss_func, metric='arc_length')
        total += pop_health
        mean.append(total / (_ + 1))

        pair = pop.population

        if _ % 100 == 0:
            print "Generation {0} health: \t{1}".format(_, pop_health), total / (_ + 1)
            # draw(pair)

        if (_ + 1) > 300:
            count += 1
            avg_angle += abs(np.mean(loss_func))
    avg_angle /= count
    print(avg_angle)

    plt.clf()
    plt.plot(range(500), mean)
    plt.savefig('plots/generational_performance.png')
    plt.show()