Exemplo n.º 1
0
def pdf_report(training_data_name,
               training_data_X,
               training_data_y,
               attack_training_set,
               test_set,
               kernel_type,
               prediction_type,
               attack_type,
               bf_alpha,
               budget_factor_alpha_list,
               test_set_y=None):
    dimension = len(training_data_X[0])
    print(
        "---------------------------------------------------------------------------"
    )
    print("[*] Initiating Experiment")
    print("Parameters:")
    print("Training set:             ", training_data_name)
    print("Training data count:      ", len(training_data_X))
    print("Attack data count:        ", len(attack_training_set))
    print("Data dimension:           ", dimension)
    print("Test set size:            ", len(test_set))
    if kernel_type is not None:
        print("Kernel:                   ", kernel_type)
    print("Prediction type:          ", prediction_type)
    print("Attack type:              ", attack_type)
    if budget_factor_alpha_list:
        print("Budget Factor Alpha List: ", budget_factor_alpha_list[0], "..",
              budget_factor_alpha_list[-1])
    print("----------------------------------------------------")
    s = Supervisor()
    name = training_data_name

    print("[*] Training Server Model...")
    s.add_model(name, training_data_X, training_data_y, prediction_type,
                kernel_type)
    print("[*] Starting Test Attack...")

    query_budget = math.ceil(bf_alpha * (dimension + 1))
    if attack_type == "agnostic":
        kernel_type = None
    if True:
        run_time, queries, model = s.attack_with_metrics(name,
                                                         kernel_type,
                                                         attack_type,
                                                         dimension,
                                                         query_budget,
                                                         attack_training_set,
                                                         roundsize=160,
                                                         test_set=test_set)

        print("[*] Attack took ", run_time, " seconds and ", queries,
              " queries.")
        print("[*] Starting Prediction Comparison for test Attack... ")
        a = s.compare_predictions(name,
                                  test_set,
                                  correct_results=test_set_y,
                                  verbose=True)
    if attack_type == "lowd-meek":
        return a[0], queries, run_time
    if not budget_factor_alpha_list:
        return a[0], queries, run_time

    if attack_type not in ["extraction", "lowd-meek", "agnostic"]:
        print("[*] Running query mapping")
        s.plot_error_on_queries("mse", name, kernel_type, attack_type,
                                dimension, budget_factor_alpha_list,
                                attack_training_set, test_set, 16)