def GenerateLabel(data_path, name_list_path, time_message_path,
                  timeout_message_path):
    with open(data_path, "r") as csvfile:
        data = list(csv.reader(csvfile))

    name_list = []
    time_message = {}
    timeout_message = {}
    for line in data:
        name_list.append(line[0])
        time_dic = {}
        timeout_dic = {}
        for index in range(len(utils.method_list)):
            if line[index +
                    1] == "timeout" or line[index +
                                            1] == "failed" or line[index +
                                                                   1] == "0.0":
                time_dic[utils.method_list[index]] = 3600.0
                timeout_dic[utils.method_list[index]] = True
            else:
                time_dic[utils.method_list[index]] = float(line[index + 1])
                timeout_dic[utils.method_list[index]] = False
        time_message[line[0]] = time_dic
        timeout_message[line[0]] = timeout_dic

    utils.WriteJson(name_list, name_list_path)
    utils.WriteJson(time_message, time_message_path)
    utils.WriteJson(timeout_message, timeout_message_path)
def GenerateLabelForOneMethod(data_path, name_list_path, time_dic_path,
                              timeout_dic_path, method):
    method_list = utils.method_list
    with open(data_path, "r") as csvfile:
        data = list(csv.reader(csvfile))[1:]

    name_list = []
    time_dic = {}
    timeout_dic = {}
    for line in data:
        name = line[0]
        name_list.append(name)
        index = method_list.index(method) + 1
        if line[index] == "timeout" or line[index] == "failed" or line[
                index] == "0.0" or line[index] == "0":
            time_dic[name] = 3600.0
            timeout_dic[name] = True
        else:
            time_dic[name] = float(line[index])
            timeout_dic[name] = False

    utils.WriteJson(name_list, name_list_path)
    utils.WriteJson(time_dic, time_dic_path)
    utils.WriteJson(timeout_dic, timeout_dic_path)
    return name_list, time_dic, timeout_dic
def StatisticSamples(test_label_dic_path, statistic_name_dic_path):
    test_label_dic = utils.ReadJson(test_label_dic_path)
    statistic_name_dic = {}
    for method in utils.method_list:
        statistic_name_dic[method] = []
    for name in test_label_dic.keys():
        statistic_name_dic[test_label_dic[name]].append(name)
    utils.WriteJson(statistic_name_dic, statistic_name_dic_path)
def GenerateLabel(data_path, name_list_path, label_dic_path):
    with open(data_path, "r") as csvfile:
        data = list(csv.reader(csvfile))

    name_list = []
    label_dic = {}
    for line in data:
        method = "None"
        time = float(sys.maxsize)
        for index in range(len(utils.method_list)):
            if line[index +
                    1] != "timeout" and line[index + 1] != "failed" and line[
                        index + 1] != "0.0" and float(line[index + 1]) < time:
                time = float(line[index + 1])
                method = utils.method_list[index]
        if method != "None":
            name_list.append(line[0])
            label_dic[line[0]] = method
        else:
            print(line[0])
    utils.WriteJson(name_list, name_list_path)
    utils.WriteJson(label_dic, label_dic_path)
def Predict(name_list_path, model_path, layer, method):
    name_list = utils.ReadJson(name_list_path)
    if layer == 0:
        encoding_dic_dir = utils.encoding_dic_dir_0
    elif layer == 1:
        encoding_dic_dir = utils.encoding_dic_dir_1
    elif layer == 2:
        encoding_dic_dir = utils.encoding_dic_dir_2
    vec_list = utils.GetVecListFromDic(encoding_dic_dir, name_list)
    model = utils.Load_pkl(model_path)
    predict_time_list = model.predict(vec_list)
    time_predict = predict_time_list.tolist()
    time_predict_path = utils.time_predict_path + "predict_" + method + "_" + str(layer) + ".json"
    utils.WriteJson(time_predict, time_predict_path)
    return time_predict
def GenerateEncodingDic(encoding_dir, encoding_dic_dir):
    encoding_dic = {}
    file_name_list = os.listdir(encoding_dir)
    for file_name in file_name_list:
        aig_name = file_name.split(".vector")[0]
        file_path = os.path.join(encoding_dir, file_name)
        assert (os.path.isfile(file_path))
        vector = []
        with open(file_path, encoding='utf-8') as fp:
            line = fp.readlines()[0].split("[")[1].split("]")[0]
            items = line.split(", ")
            for item in items:
                vector.append(int(item))
            fp.close()
        encoding_dic[aig_name] = vector
    utils.WriteJson(encoding_dic, encoding_dic_dir)
Exemple #7
0
def StatisticAvgEncodingTime(log_path, time_path):
    dic = {}
    with open(log_path, 'r') as file_obj:
        data = file_obj.read()
        file_obj.close()
    lines = data.split("\n")
    num = int(len(lines) / 2)
    for i in range(num):
        name_message = lines[2 * i]
        time_message = lines[2 * i + 1]
        name = name_message.split("../networks_aag/")[1].split(".aag")[0]
        temp_time = time_message.split("user\t")[1].split("s")[0]
        minute = float(temp_time.split("m")[0])
        second = float(temp_time.split("m")[1])
        time = minute * 60 + second
        dic[name] = time
    utils.WriteJson(dic, time_path)
    return dic
Exemple #8
0
def RandomForest(embedded_dir,
                 train_name_list,
                 test_name_list,
                 train_time_message,
                 test_time_message,
                 time_predict_path,
                 layer,
                 max_depth,
                 min_samples_split=2,
                 min_samples_leaf=1):
    time_model_path = utils.time_model_path
    train_vec_list = utils.GetVecList(embedded_dir, train_name_list)
    test_vec_list = utils.GetVecList(embedded_dir, test_name_list)
    time_predict_message = {}
    for method in utils.method_list:
        whole_time_model_path = time_model_path + method + "_model_" + layer + ".pkl"
        train_time_list = GetTimeList(train_name_list, train_time_message,
                                      method)
        test_time_list = GetTimeList(test_name_list, test_time_message, method)
        model = RandomForestRegressor(n_estimators=100,
                                      criterion="mae",
                                      max_depth=max_depth,
                                      min_samples_split=min_samples_split,
                                      min_samples_leaf=min_samples_leaf)
        model.fit(train_vec_list, train_time_list)
        utils.Save_pkl(model, whole_time_model_path)
        predict_time_list = model.predict(test_vec_list)
        time_predict_message[method] = predict_time_list.tolist()

        print("Traing Score:%f" % model.score(train_vec_list, train_time_list))
        print("Testing Score:%f" % model.score(test_vec_list, test_time_list))
        # trees = model.estimators_
        # dot_data = tree.export_graphviz(trees[0],
        #                         out_file = None,
        #                         feature_names = list(range(len(train_vec_list[0]))),
        #                         class_names = train_time_list,
        #                         filled = True,
        #                         rounded = True
        #                        )
        # graph = pydotplus.graph_from_dot_data(dot_data)
        # graph.write_pdf(utils.time_result_path + method + "_" + layer + ".pdf")
    utils.WriteJson(time_predict_message, time_predict_path)
def RandomForest(embedded_dir, train_name_list, test_name_list, train_time_message, test_time_message,
                time_predict_path, layer, max_depth, min_samples_split=2, min_samples_leaf=1):
    time_model_path = utils.time_model_path
    train_vec_list = utils.GetVecList(embedded_dir, train_name_list)
    test_vec_list = utils.GetVecList(embedded_dir, test_name_list)
    time_predict_message = {}
    for method in utils.method_list:
        whole_time_model_path = time_model_path + method + "_model_" + layer + ".pkl"
        train_time_list = GetTimeList(train_name_list, train_time_message, method)
        test_time_list = GetTimeList(test_name_list, test_time_message, method)
        model = RandomForestRegressor(n_estimators=100, criterion="mae", max_depth=max_depth, min_samples_split=min_samples_split, min_samples_leaf=min_samples_leaf)
        model.fit(train_vec_list, train_time_list)
        utils.Save_pkl(model, whole_time_model_path)
        predict_time_list = model.predict(test_vec_list)
        time_predict_message[method] = predict_time_list.tolist()

        print("Traing Score:%f" % model.score(train_vec_list, train_time_list))
        print("Testing Score:%f" % model.score(test_vec_list, test_time_list))

    utils.WriteJson(time_predict_message, time_predict_path)
def RandomForest(layer, embedded_dir, train_name_list, test_name_list, train_label_list, test_label_list, classify_predict_path,
                model_path, importance_path, max_depth, max_leaf_nodes, min_samples_split=2, min_samples_leaf=1):
    train_vec_list = utils.GetVecList(embedded_dir, train_name_list)
    test_vec_list = utils.GetVecList(embedded_dir, test_name_list)

    model = RandomForestClassifier(n_estimators=100, criterion="entropy", max_depth=None, min_samples_split=min_samples_split, 
                                    min_samples_leaf=min_samples_leaf, max_leaf_nodes=max_leaf_nodes, max_features=None)
    classifier = model.fit(train_vec_list, train_label_list)
    utils.Save_pkl(classifier, model_path)
    

    predictions = classifier.predict_proba(test_vec_list)
    predict_label_list = np.argsort(-predictions, axis=1)
    importance = model.feature_importances_
    utils.WriteJson(importance.tolist(), importance_path)
    print("layer " + layer)
    sum_acc = GetAcc(predict_label_list, test_label_list, utils.choose_top_method_number_1)
    print(sum_acc)
    sum_acc = GetAcc(predict_label_list, test_label_list, utils.choose_top_method_number_2)
    print(sum_acc)
    classify_predict = GeneratePredictResult(test_name_list, predict_label_list, classify_predict_path)
def GeneratePredictResult(test_name_list, predict_label_list, classify_predict_path):
    classify_predict = {}
    method_list = utils.method_list
    for i in range(len(test_name_list)):
        test_name = test_name_list[i]
        temp_predict = []
        for predict in predict_label_list[i]:
            temp_predict.append(method_list[predict])
        classify_predict[test_name] = temp_predict
    utils.WriteJson(classify_predict, classify_predict_path)


    # method_list = utils.method_list
    # choose_top_method_number = utils.choose_top_method_number_1
    # for i in range(choose_top_method_number):
    #     top_i_method_dic = {}
    #     for j in range(len(test_name_list)):
    #         test_name = test_name_list[j]
    #         top_i_method_dic[test_name] = classify_predict[test_name][i]
    #     statistic_dic = utils.Statistic([top_i_method_dic])
    #     print(statistic_dic)

    return classify_predict
        new_directory.append(reverse_item)
        lettermark = False
        firstmark = True
        for i in range(len(reverse_item)):
            if reverse_item[i] != "-":
                if lettermark == False:
                    lettermark = True
                    if firstmark == False:
                        latex_format += "|"
                    else:
                        firstmark = False
                    latex_format += "\\mathtt{"
                latex_format += reverse_item[i]
            else:
                if lettermark == True:
                    lettermark = False
                    latex_format += "}\\verb|"
                latex_format += "-"
        if lettermark == True:
            latex_format += "}"
        else:
            latex_format += "|"
        if index != len(directory) - 1:
            latex_format += ", "

    utils.WriteJson(new_directory, new_directory_path)
    print(latex_format)
    utils.WriteJson(latex_format, latex_format_path)


    
Exemple #13
0
    for method in utils.method_list:
        save_path = utils.time_result_path + method + "_time_predict.pdf"
        plt.figure()
        plt.title(utils.NameMap(method), size=17)
        # plt.xlabel('Sum Time (s)', size=25)
        # plt.ylabel('# Solved Number', size=25)

        for i in range(len(time_predict_label_list)):
            label = time_predict_label_list[i]
            time_predict = time_predict_list[i]
            predict_time_list = time_predict[method]
            predict_name_list = Sort(test_name_list, predict_time_list)
            temp_name_sort_path = utils.time_basic_data_path + method + "_name_sort_" + str(
                2 - i) + ".json"
            utils.WriteJson(predict_name_list, temp_name_sort_path)
            predict_solved_sum_time_list, predict_solved_number_list = GetFigData(
                predict_name_list, method, test_time_message,
                test_timeout_message)
            if label == "0-depth Encoding":
                color = "#9dc6e0"
                color = "#a6a6a6"

            elif label == "1-depth Encoding":
                color = "#6996b3"
                color = "#505050"
            elif label == "2-depth Encoding":
                # color = "#004c6d"
                color = "#000000"
            plt.plot(predict_solved_sum_time_list,
                     predict_solved_number_list,