Exemple #1
0
def example(method, data, list_target, alpha, is_discrete, k=0):
    file = open("../output/mb.txt", "w+")
    if method == "MMMB":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = MMMB(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "IAMB":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = IAMB(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "inter_IAMB":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = inter_IAMB(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "fast_IAMB":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = fast_IAMB(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "GSMB":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = GSMB(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "HITON_MB":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = HITON_MB(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "semi_HITON_MB":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = semi_HITON_MB(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "PCMB":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = PCMB(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "IPCMB":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = IPC_MB(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "STMB":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = STMB(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "IAMBnPC":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = IAMBnPC(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "interIAMBnPC":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = interIAMBnPC(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "BAMB":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = BAMB(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "FBEDk":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = FBED(data, target, k, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "MBOR":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = MBOR(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "LRH":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = LRH(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "KIAMB":
        start_time = time.process_time()
        for target in list_target:
            MB, ci_num = KIAMB(data, target, alpha, k, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "TIE":
        start_time = time.process_time()
        for target in list_target:
            MB = TIE(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    elif method == "TIE_p":
        start_time = time.process_time()
        for target in list_target:
            MB = TIE_p(data, target, alpha, is_discrete)
            file.write("the MB of " + str(target) + " is:" + str(MB) + "\n")
            print("the MB of " + str(target) + " is:" + str(MB))
        end_time = time.process_time()
    else:
        raise Exception("method input error!")

    print("the running time is: " + str(end_time - start_time))
    file.write("the running time is: " + str(end_time - start_time) + "\n")
    file.close()
Exemple #2
0
 print(target)
 print(method)
 if method == "MMMB":
     MB, ci_num = MMMB(data, target, alaph, is_discrete)
 elif method == "IAMB":
     MB, ci_num = IAMB(data, target, alaph, is_discrete)
 elif method == "IAMBnPC":
     MB, ci_num = IAMBnPC(data, target, alaph, is_discrete)
 elif method == "inter_IAMB":
     MB, ci_num = inter_IAMB(data, target, alaph, is_discrete)
 elif method == "interIAMBnPC":
     MB, ci_num = interIAMBnPC(data, target, alaph, is_discrete)
 elif method == "fast_IAMB":
     MB, ci_num = fast_IAMB(data, target, alaph, is_discrete)
 elif method == "GSMB":
     MB, ci_num = GSMB(data, target, alaph, is_discrete)
 elif method == "HITON_MB":
     MB, ci_num = HITON_MB(data, target, alaph, is_discrete)
 elif method == "PCMB":
     MB, ci_num = PCMB(data, target, alaph, is_discrete)
 elif method == "IPCMB":
     MB, ci_num = IPC_MB(data, target, alaph, is_discrete)
 elif method == "STMB":
     MB, ci_num = STMB(data, target, alaph, is_discrete)
 elif method == "IAMBnPC":
     MB, ci_num = IAMBnPC(data, target, alaph, is_discrete)
 elif method == "BAMB":
     MB, ci_num = BAMB(data, target, alaph, is_discrete)
 elif method == "FBEDk":
     MB, ci_num = FBED(data, target, k, alaph, is_discrete)
 elif method == "MBOR":
def evaluation(method,
               path,
               all_number_Para,
               target_list,
               real_graph_path,
               is_discrete,
               filenumber=10,
               alaph=0.01,
               k=1):

    # pre_set variables is zero
    Precision = 0
    Recall = 0
    F1 = 0
    Distance = 0
    use_time = 0
    ci_number = 0
    realmb, realpc = realMB(all_number_Para, real_graph_path)
    length_targets = len(target_list)
    for m in range(filenumber):
        completePath = path + str(m + 1) + ".csv"
        data = pd.read_csv(completePath)
        number, kVar = np.shape(data)
        ResMB = [[]] * length_targets
        # print("\ndata set is: " + str(m+1) + ".csv")
        for i, target in enumerate(target_list):
            # print("target is: " + str(target))
            if method == "MMMB":
                start_time = time.process_time()
                MB, ci_num = MMMB(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "IAMB":
                start_time = time.process_time()
                MB, ci_num = IAMB(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "KIAMB":
                start_time = time.process_time()
                MB, ci_num = KIAMB(data, target, alaph, k, is_discrete)
                end_time = time.process_time()
            elif method == "IAMBnPC":
                start_time = time.process_time()
                MB, ci_num = IAMBnPC(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "inter_IAMB":
                start_time = time.process_time()
                MB, ci_num = inter_IAMB(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "interIAMBnPC":
                start_time = time.process_time()
                MB, ci_num = interIAMBnPC(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "fast_IAMB":
                start_time = time.process_time()
                MB, ci_num = fast_IAMB(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "GSMB":
                start_time = time.process_time()
                MB, ci_num = GSMB(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "HITON_MB":
                start_time = time.process_time()
                MB, ci_num = HITON_MB(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "PCMB":
                start_time = time.process_time()
                MB, ci_num = PCMB(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "IPCMB":
                start_time = time.process_time()
                MB, ci_num = IPC_MB(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "STMB":
                start_time = time.process_time()
                MB, ci_num = STMB(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "IAMBnPC":
                start_time = time.process_time()
                MB, ci_num = IAMBnPC(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "BAMB":
                start_time = time.process_time()
                MB, ci_num = BAMB(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "FBEDk":
                start_time = time.process_time()
                MB, ci_num = FBED(data, target, k, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "MBOR":
                start_time = time.process_time()
                MB, ci_num = MBOR(data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "LRH":
                start_time = time.process_time()
                MB, ci_num = LRH(data, target, alaph, is_discrete)
                end_time = time.process_time()
            else:
                raise Exception("method input error!")

            use_time += (end_time - start_time)
            ResMB[i] = MB
            ci_number += ci_num

        for n, target in enumerate(target_list):
            # print("target is: " + str(target) + " , n is: " + str(n))
            true_positive = list(
                set(realmb[target]).intersection(set(ResMB[n])))
            length_true_positive = len(true_positive)
            length_RealMB = len(realmb[target])
            length_ResMB = len(ResMB[n])
            if length_RealMB == 0:
                if length_ResMB == 0:
                    precision = 1
                    recall = 1
                    F1 += 1
                else:
                    F1 += 0
                    precision = 0
                    recall = 0
            else:
                if length_ResMB != 0:
                    precision = length_true_positive / length_ResMB
                    recall = length_true_positive / length_RealMB
                    if precision + recall != 0:
                        F1 += 2 * precision * recall / (precision + recall)
                else:
                    F1 += 0
                    precision = 0
                    recall = 0
            distance = ((1 - precision)**2 + (1 - recall)**2)**0.5
            Distance += distance
            Precision += precision
            Recall += recall

        # print("current average Precision is: " + str(Precision / ((m+1) * (numberPara))))
        # print("current average Recall is: " + str(Recall / ((m+1) * (numberPara))))

    commonDivisor = length_targets * filenumber

    # 标准差

    return F1 / commonDivisor, Precision / commonDivisor, Recall / commonDivisor, Distance / \
        commonDivisor, ci_number / commonDivisor, use_time / commonDivisor