예제 #1
0
def test_direction_cone_of_circle_west(debug=False):
    circle = Point(0, 0).buffer(1)
    cone = ops.direction_cone(circle, (0, -1), pi / 2, 5)

    assert Point(0.5, -1).within(cone)

    if debug:
        plt.figure()
        axes = plt.subplot(111)
        plot_utils.plot(axes, circle, color='lightcoral')
        plot_utils.plot(axes, cone, color='lightblue', marker='x')
        plt.show()
예제 #2
0
def test_direction_cone_of_triangle_south(debug=False):
    triangle = Polygon([(0, 0), (0.5, 1), (1, 0)])
    cone = ops.direction_cone(triangle, (0, -1), pi / 2, 2)

    assert Point(0.5, -1).within(cone)

    if debug:
        plt.figure()
        axes = plt.subplot(111)
        plot_utils.plot(axes, triangle, color='lightcoral')
        plot_utils.plot(axes, cone, color='lightblue', marker='x')
        plt.show()
예제 #3
0
def test_outer_inner_buffer_square(debug=False):
    square = Polygon([(-1, -1), (-1, 1), (1, 1), (1, -1)])
    oi_buffer = ops.outer_inner_buffer(square, 0.2)

    assert Point(0.9, 0.9).within(oi_buffer)

    if debug:
        plt.figure()
        axes = plt.subplot(111)
        plot_utils.plot(axes, square, color='lightgrey', marker='x')
        plot_utils.plot(axes, oi_buffer, color='lightcoral', marker='+')
        plt.show()
예제 #4
0
def test_outer_inner_buffer_circle(debug=False):
    circle = Point(0, 0).buffer(1)
    oi_buffer = ops.outer_inner_buffer(circle, 0.2)

    assert Point(0.49 * 2**0.5, 0.49 * 2**0.5).within(oi_buffer)

    if debug:
        plt.figure()
        axes = plt.subplot(111)
        plot_utils.plot(axes, circle, color='lightgrey', marker='x')
        plot_utils.plot(axes, oi_buffer, color='lightcoral', marker='+')
        plt.show()
예제 #5
0
def test_medial_line_of_polygon_3(debug=False):
    polygon = Polygon([(1, 1), (2, 1.5), (0, 3), (-1, 4), (-2, 3), (-0.5, 2)])

    medial_line = ops.medial_line(polygon)

    assert medial_line.within(polygon)

    if debug:
        plt.figure()
        axes = plt.subplot(111)
        plot_utils.plot(axes, polygon, color='lightgrey', marker='x')
        plot_utils.plot(axes, medial_line, color='lightcoral')
        plt.show()
예제 #6
0
def test_medial_line_of_polygon_2(debug=False):
    polygon = Point(1, 1).buffer(2).union(Point(2, 2).buffer(2))

    medial_line = ops.medial_line(polygon)

    assert medial_line.within(polygon)

    if debug:
        plt.figure()
        axes = plt.subplot(111)
        plot_utils.plot(axes, polygon, color='lightgrey', marker='x')
        plot_utils.plot(axes, medial_line, color='lightcoral')
        plt.show()
예제 #7
0
def test_medial_line_of_polygon_1(debug=False):
    polygon = Polygon([(1, 1), (1, 1.5), (1, 2), (1, 3), (2, 3), (2, 2), (2, 1.5), (2, 1), (1.5, 1.5)])

    medial_line = ops.medial_line(polygon)

    assert medial_line.touches(Point(1.5, 2))
    assert medial_line.touches(Point(1.25, 1.75))
    assert medial_line.touches(Point(1.5, 2.5))
    assert medial_line.touches(Point(1.5, 2))
    assert medial_line.touches(Point(1.75, 1.75))

    if debug:
        plt.figure()
        axes = plt.subplot(111)
        plot_utils.plot(axes, polygon, color='lightgrey', marker='x')
        plot_utils.plot(axes, medial_line, color='lightcoral')
        plt.show()
예제 #8
0
def test_between_triangles(debug=False):
    left = Polygon([(1, 1), (2, 2), (3, 1)])
    right = Polygon([(4, 2), (5, 1), (6, 2)])

    between_result = between(left, right)

    assert between_result.equals(Polygon([(2, 2), (3, 1), (5, 1), (4, 2)]))

    if debug:
        plt.figure()
        axes = plt.subplot(111)
        plot_utils.plot(axes, left, color='lightcoral')
        plot_utils.plot(axes, right, color='lightblue')
        plot_utils.plot(axes, between_result, color='lightgrey')
        plt.show()
예제 #9
0
# cols_to_merge_with_name = ["threads_per_datapoint", "datapoints_per_block"]
cols_to_merge_with_name = ["datapoints_per_block"]

col_x_axis = "threads_per_datapoint"
cols_y_axis = ["train time"]

for col_y_axis in cols_y_axis:
    lines = {}
    # print(col_y_axis)
    for idx, _ in enumerate(csv["name"]):
        line_name = plot_utils.get_line_name(idx, csv, cols_to_merge_with_name)

        if line_name not in lines:
            lines[line_name] = {'x': [], 'y': []}

        lines[line_name]['x'].append(csv[col_x_axis][idx])
        lines[line_name]['y'].append(csv[col_y_axis][idx])

    plot_utils.adapt_baselines(lines)

    ax = plt.subplot(1, 1, 1)
    ax.set_xscale('log', basex=2)

    plot_utils.plot(lines, col_x_axis, col_y_axis, ax)

plt.show(block=False)

raw_input("press enter to close")

plt.close("all")
            y=labels,
            batch_size=batch_size,
            num_epochs=1,
            shuffle=False)
        eval_results = mnist_classifier.evaluate(input_fn=eval_input_fn)
        accuracy = eval_results["accuracy"]
        if eval_results["accuracy"] < 0.95:
            raise ValueError("Accuracy is {:5}% which is low".format(accuracy*100))
    
    # Generate adversarial images
    images, adv_images = generate_adversarial_images(
                              mnist_classifier,
                              images, labels,
                              old_label, new_label,
                              n_to_modify, reg_lambda,
                              one_pixel)
    
    # Infer the classes
    classes     = predict(mnist_classifier, images)
    adv_classes = predict(mnist_classifier, adv_images)
   
    # Compute the deltas
    deltas = adv_images - images
    
    # Plot and save the figure
    fig = plot(images, deltas, adv_images, classes, adv_classes)

    if not os.path.exists('images/'):
        os.mkdir('images/')
    fig.savefig('images/example.png' if not one_pixel else 'images/one_pixel_example.png')
예제 #11
0
out_accuracy_model_file = os.path.abspath(os.path.join(out_dir, 'model_accuracy.png'))

out_recall_file = os.path.abspath(os.path.join(out_dir, 'positive_recall.png'))
neg_recall_file = os.path.abspath(os.path.join(out_dir, 'negative_recall.png'))

out_fscore_file = os.path.abspath(os.path.join(out_dir, 'positive_fscore.png'))
neg_fscore_file = os.path.abspath(os.path.join(out_dir, 'negative_fscore.png'))

out_acc_file = os.path.abspath(os.path.join(out_dir, 'accuracy.png'))
pos_precision_acc = numpy.mean(metrics_pos_precision_scores, axis=0)
# prec_y_data_list.append(pos_precision_acc)


# prec_y_data_list
plot(epochs_arr, metrics_pos_precision_scores, 'Positive Precision', 'Epoch', 'Precision', epochs_num, out_prec_file, lw_lst, alpha_lst, fold_pos_prec_mean)

plot(epochs_arr, metrics_neg_precision_scores, 'Negative Precision', 'Epoch', 'Precision', epochs_num, neg_prec_file, lw_lst, alpha_lst, fold_neg_prec_mean)

plot(epochs_arr, metrics_acc_scores, 'Accuracy', 'Epoch', 'Accuracy', epochs_num, out_acc_file, lw_lst, alpha_lst, fold_accuracy_mean, [70, 101])

plot(epochs_arr, metrics_pos_recall_scores, 'Positive Recall', 'Epoch', 'Recall', epochs_num, out_recall_file, lw_lst, alpha_lst, fold_pos_recall_mean)

plot(epochs_arr, metrics_neg_recall_scores, 'Negative Recall', 'Epoch', 'Recall', epochs_num, neg_recall_file, lw_lst, alpha_lst, fold_neg_recall_mean)

plot(epochs_arr, metrics_pos_fscore_scores, 'Positive F-score', 'Epoch', 'F-score', epochs_num, out_fscore_file, lw_lst, alpha_lst, fold_pos_fscore_mean)

plot(epochs_arr, metrics_neg_fscore_scores, 'Negative F-score', 'Epoch', 'F-score', epochs_num, neg_fscore_file, lw_lst, alpha_lst, fold_neg_fscore_mean)


예제 #12
0
cols_to_merge_with_name = ["datapoints_per_block"]

col_x_axis = "threads_per_datapoint"
cols_y_axis = ["train time"]


for col_y_axis in cols_y_axis:
    lines = {}
    # print(col_y_axis)
    for idx, _ in enumerate(csv["name"]):
        line_name = plot_utils.get_line_name(idx, csv, cols_to_merge_with_name)

        if line_name not in lines:
            lines[line_name] = {'x':[], 'y':[]}

        lines[line_name]['x'].append(csv[col_x_axis][idx])
        lines[line_name]['y'].append(csv[col_y_axis][idx])

    plot_utils.adapt_baselines(lines)

    ax = plt.subplot(1, 1, 1)
    ax.set_xscale('log', basex=2)

    plot_utils.plot(lines, col_x_axis, col_y_axis, ax)

plt.show(block=False)

raw_input("press enter to close")

plt.close("all")
예제 #13
0
 def plot(self, start=0, time=None, **plot_kwargs):
     if time is None:
         fin = len(self.array)
     else:
         fin = start + time * self.rate
     plot(self.array[start:fin], **plot_kwargs)