def evolve(image_class, pop_class, pairs, mutation_probability):
    """
    :param image_class: (class object)
    :param pop_class: (class object)
    :param pairs: (numpy array with dimensions (n_pairs, 2, 2, 2)) pairs of lines
    :param mutation_probability: (float)
    :return: (numpy array) loss functions for the population
    """
    pop_class.exterminate()
    slopes = map(image_class.slope, pairs)
    loss_func = map(lambda s: loss(np.array(s[0]), np.array(s[1])), slopes)

    pop_class.add_parents(pairs, loss_func, 200)
    pop_class.add_children(image_class.mutation, p_mutate=mutation_probability)
    pop_slopes = map(image_class.slope, pop_class.population)
    pop_loss = map(lambda s: loss(np.array(s[0]), np.array(s[1])), pop_slopes)
    return pop_loss
示例#2
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)