def generate_testing_point(single_formula, category, dimension, number, lower_bound, large_bound):
    number_of_point = int(math.pow(number, (1.0 / dimension)))
    output = []
    if number_of_point == 1:
        for i in range(number):
            point = []
            for j in range(dimension):
                value = np.random.uniform(lower_bound, large_bound)
                point.append(value)
            output.append(point)
    else:
        step = (large_bound - lower_bound) / float(number_of_point)
        x_list = []
        for i in range(number_of_point):
            x_list.append(lower_bound + i * step)
        output = list(product(x_list, repeat=dimension))

    label_list = []
    point_list = []
    for i in output:
        i = list(i)
        formula_tester = lt.FormulaLabelTester(single_formula)
        if category == formula.POLYHEDRON:
            is_true = formula_tester.polycircle_model(single_formula.get_formula()[0],
                                                      single_formula.get_formula()[1], i)
        else:
            is_true = formula_tester.polynomial_model(single_formula.get_formula()[:-1], i,
                                                      single_formula.get_formula()[-1])

        if is_true:
            label_list.append([1.0])
        else:
            label_list.append([0.0])
        point_list.append(i)
    return point_list, label_list
Ejemplo n.º 2
0
def generate_polyhedron_points(formu, to_be_appended_random_points_number,
                               lower_bound, upper_bound):
    formu = formu.get_formula()
    dim = len(formu[0][0])
    outputX = []
    outputY = []

    for i in range(to_be_appended_random_points_number):
        generated_point = []
        for j in range(dim):
            generated_point.append(random.uniform(lower_bound, upper_bound))

        # k = random.randint(2, 3)
        # if k % 2 == 0:
        #     center = random.randint(0, len(formu[0]) - 1)
        #     for i in range(dim):
        #         generated_point.append(random.uniform(int(formu[0][center][i]) - 10, int(formu[0][center][i]) + 10))
        # else:
        #     for i in range(dim):
        #         generated_point.append(random.uniform(-10, 10))
        formula_tester = lt.FormulaLabelTester()
        flag = formula_tester.polycircle_model(formu[0], formu[1],
                                               generated_point)
        outputX.append(generated_point)

        if (flag):
            outputY.append([1])
        else:
            outputY.append([0])
    return outputX, outputY
def generate_random_points_for_polynomial(single_formula, lower_bound, upper_bound, num):
    formula_tester = lt.FormulaLabelTester(single_formula)
    data_list = []
    label_list = []

    coefficient_list = single_formula.get_formula()[:-1]
    y = single_formula.get_formula()[-1]
    while len(data_list) < num:
        point = []
        variable_num = len(coefficient_list)
        for i in range(variable_num):
            point.append(random.randint(lower_bound, upper_bound))

        label = formula_tester.polynomial_model(coefficient_list, point, y)
        data_list.append(point)
        label_list.append([label])

    return data_list, label_list
def generate_partitioned_random_points_for_sphere(single_formula, lower_bound, upper_bound,
                                                  positive_num, negative_num):  # [[[12,0],[-12,0]],[4,4]]
    formu_list = single_formula.get_formula()
    dim = len(formu_list[0][0])

    positive_list = []
    negative_list = []
    while len(positive_list) < positive_num or len(negative_list) < negative_num:
        data_point = []

        center = random.choice(formu_list[0])
        index = formu_list[0].index(center)
        radius = formu_list[1][index]
        move = math.sqrt(radius ** 2 / dim)

        r = random.uniform(0, 1)

        point = []
        for i in range(dim):
            length = random.uniform(0, move)
            if r > 0.5:
                step = length
                value = center[i] + step
            else:
                value = random.uniform(lower_bound, upper_bound)
            point.append(value)

        formula_tester = lt.FormulaLabelTester(single_formula)
        label = formula_tester.polycircle_model(formu_list[0], formu_list[1], point)

        if label:
            if len(positive_list) < positive_num:
                positive_list.append(point)
        else:
            if len(negative_list) < negative_num:
                negative_list.append(point)

    return positive_list, negative_list
def generate_random_points_for_sphere(single_formula, lower_bound, upper_bound,
                                      data_point_number):  # [[[12,0],[-12,0]],[4,4]]
    formu_list = single_formula.get_formula()
    dim = len(formu_list[0][0])

    data_list = []
    label_list = []
    for k in range(data_point_number):
        data_point = []
        point = []
        if k % 3 == 0:
            center = random.randint(0, len(formu_list[0]) - 1)
            for i in range(dim):
                point.append(
                    random.uniform(int(formu_list[0][center][i]) - 300, int(formu_list[0][center][i]) + 300))
        else:
            for i in range(dim):
                point.append(random.uniform(lower_bound, upper_bound))

        data_list.append(point)
        formula_tester = lt.FormulaLabelTester(single_formula)
        label = formula_tester.polycircle_model(formu_list[0], formu_list[1], point)
        label_list.append([label])
    return data_list, label_list
def generate_partitioned_random_points_for_polynomial(single_formula, lower_bound, upper_bound, positive_num,
                                                      negative_num):
    formula_tester = lt.FormulaLabelTester(single_formula)
    positive_list = []
    negative_list = []

    coefficient_list = single_formula.get_formula()[:-1]
    y = single_formula.get_formula()[-1]
    while len(positive_list) < positive_num or len(negative_list) < negative_num:
        point = []
        variable_num = len(coefficient_list)
        for i in range(variable_num):
            point.append(random.randint(lower_bound, upper_bound))

        label = formula_tester.polynomial_model(coefficient_list, point, y)

        if label:
            if len(positive_list) < positive_num:
                positive_list.append(point)
        else:
            if len(negative_list) < negative_num:
                negative_list.append(point)

    return positive_list, negative_list
Ejemplo n.º 7
0
def generate_polynomial_points(single_formula,
                               to_be_appended_random_points_number,
                               lower_bound, upper_bound):
    single_formula = single_formula.get_formula()
    coefficientList = single_formula[:-1]
    y = single_formula[-1]
    outputX = []
    outputY = []
    for i in range(to_be_appended_random_points_number):
        xList = []
        variableNum = len(coefficientList)
        for j in range(variableNum):
            xList.append(random.randint(lower_bound, upper_bound))

        formula_tester = lt.FormulaLabelTester(single_formula)
        flag = formula_tester.polynomial_model(coefficientList, xList, y)
        outputX.append(xList)

        if (flag):
            outputY.append([1])
        else:
            outputY.append([0])

    return outputX, outputY
Ejemplo n.º 8
0
upper_bound = 1000

learning_rate = 0.01
training_epochs = 1000
parts_num = 5

data_point_number = 200
util.reset_random_seed()

train_set_x, train_set_y, test_set_x, test_set_y = formula_data_point_generation.generate_partitioned_data(
    parent_formula, category,
    lower_bound,
    upper_bound,
    50, 50)

label_tester = lt.FormulaLabelTester(parent_formula)
point_number_limit = 200
util.reset_random_seed()
model_folder = "models/test-method/test-branch"
model_file = "test-branch"

util.reset_random_seed()
train_acc, test_acc = benchmark.generate_accuracy(train_set_x, train_set_y, test_set_x, test_set_y, learning_rate,
                                                  training_epochs, lower_bound, upper_bound, model_folder, model_file)

child_label_tester = lt.FormulaLabelTester(child_formula)
train_set_x1, train_set_y1, _, _ = formula_data_point_generation.generate_partitioned_data(
    child_formula, category,
    -400,
    400,
    0, 20)
Ejemplo n.º 9
0
    #             else:
    #                 ws.write(i, j, str(col))
    #         else:
    #             ws.write(i, j, col)

    # print()


index = 0
for f in formula_list:
    start_time = time.time()
    util.reset_random_seed()
    print(f.get_formula())
    train_set_x, train_set_y, test_set_x, test_set_y = formula_data_point_generation.generate_partitioned_data(
        f, category, lower_bound, upper_bound, 50, 50)
    label_tester = lt.FormulaLabelTester(f)
    point_number_limit = 100
    util.reset_random_seed()
    tf.reset_default_graph()
    train_acc_list, test_acc_list, data_point_number_list, appended_point_list = mal.generate_accuracy(
        train_set_x[0:50], train_set_y[0:50], test_set_x, test_set_y,
        learning_rate, training_epochs, lower_bound, upper_bound, False,
        label_tester, point_number_limit, model_folder, model_file)

    tf.reset_default_graph()
    util.reset_random_seed()
    index += 1
    train_acc, test_acc = benchmark.generate_accuracy(
        train_set_x, train_set_y, test_set_x, test_set_y, learning_rate,
        training_epochs, lower_bound, upper_bound, model_folder, model_file)
    end_time = time.time()
Ejemplo n.º 10
0
upper_bound = 1000

learning_rate = 0.01
training_epochs = 1000
parts_num = 5

data_point_number = 200
util.reset_random_seed()

train_set_x, train_set_y, test_set_x, test_set_y = formula_data_point_generation.generate_partitioned_data(
    parent_formula, category,
    lower_bound,
    upper_bound,
    50, 50)

label_tester = lt.FormulaLabelTester(parent_formula)
point_number_limit = 200
util.reset_random_seed()
model_folder = "models/test-method/test-branch"
model_file = "test-branch"

# util.reset_random_seed()
# train_acc, test_acc = benchmark.train(train_set_x, train_set_y, test_set_x, test_set_y, learning_rate,
#                                                   training_epochs, lower_bound, upper_bound, model_folder, model_file)


positive_x = []
for i in range(len(train_set_x)):
    point = train_set_x[i]
    if train_set_y[i][0] == 1:
        positive_x.append(point)