示例#1
0
def evaluation(
    method,
    path,
    all_number_Para,
    target_list,
    real_graph_path,
    is_discrete,
    filenumber=10,
    alaph=0.01,
):
    # pre_set variables is zero
    length_target_list = len(target_list)
    real_p, real_c, real_s = real_p_c_s(all_number_Para, real_graph_path)
    num_re, num_undirect = 0, 0
    num_miss, num_extra = 0, 0
    for m in range(filenumber):
        completePath = path + str(m + 1) + ".csv"
        data = pd.read_csv(completePath)
        get_p, get_c, undirected = [[]] * length_target_list, [[]] * \
            length_target_list, [[]] * length_target_list
        print(get_p)
        for i, target in enumerate(target_list):
            if method == "PCDbyPCD":
                P, c, undirected[i] = PCDbyPCD(data, target, alaph,
                                               is_discrete)
            elif method == "MBbyMB":
                P, c, undirected[i] = MBbyMB(data, target, alaph, is_discrete)
            elif method == "CMB":
                P, c, undirected[i] = CMB(data, target, alaph, is_discrete)
            else:
                raise Exception("method input error!")
            get_p[i] = P
            get_c[i] = c

        for n, target in enumerate(target_list):

            reverse_direction = list(
                (set(real_p[target]).intersection(set(get_c[n]))).union(
                    set(real_c[target]).intersection(set(get_p[n]))))
            num_re += len(reverse_direction)

            print(undirected)
            undirected_direction = list(undirected[n])
            num_undirect += len(undirected_direction)

            miss_direction = list(
                (set(real_p[target]).difference(set(get_p[n]))).union(
                    set(real_c[target]).difference(set(get_c[n]))))
            num_miss += len(miss_direction)

            extra_direction = list(
                ((set(get_p[n]).difference(real_p[target])).union(
                    set(get_c[n]).difference(set(real_c[target])))))
            num_extra += len(extra_direction)
    commonDivisor = length_target_list * filenumber

    return num_undirect / commonDivisor, num_re / commonDivisor, num_miss / commonDivisor, num_extra / commonDivisor
示例#2
0
def example(method, data, list_target, alpha, is_discrete):
    file = open("../output/outputLSL.txt", "w+")
    if method == "PCDbyPCD":
        start_time = time.process_time()
        for target in list_target:
            parents, children, undirected = PCDbyPCD(data, target, alpha,
                                                     is_discrete)
            file.write(
                str(target) + " parents: " + str(parents) + " ,children: " +
                str(children) + " ,undirected: " + str(undirected) + ".\n")
            print(
                str(target) + " parents: " + str(parents) + " ,children: " +
                str(children) + " ,undirected: " + str(undirected))
        end_time = time.process_time()
    elif method == "MBbyMB":
        start_time = time.process_time()
        for target in list_target:
            parents, children, undirected = MB_by_MB(data, target, alpha,
                                                     is_discrete)
            file.write(
                str(target) + " parents: " + str(parents) + " ,children: " +
                str(children) + " ,undirected: " + str(undirected) + ".\n")
            print(
                str(target) + " parents: " + str(parents) + " ,children: " +
                str(children) + " ,undirected: " + str(undirected))
        end_time = time.process_time()
    elif method == "CMB":
        start_time = time.process_time()
        for target in list_target:
            parents, children, undirected = CMB(data, target, alpha,
                                                is_discrete)
            file.write(
                str(target) + " parents: " + str(parents) + " ,children: " +
                str(children) + " ,undirected: " + str(undirected) + ".\n")
            print(
                str(target) + " parents: " + str(parents) + " ,children: " +
                str(children) + " ,undirected: " + str(undirected))
        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()
示例#3
0
def evaluation_nocache(
    method,
    path,
    all_number_Para,
    target_list,
    real_graph_path,
    is_discrete,
    filenumber=10,
    alaph=0.01,
):
    # pre_set variables is zero
    length_target_list = len(target_list)
    real_p, real_c, real_s = real_p_c_s(all_number_Para, real_graph_path)
    num_re, num_undirect = 0, 0
    num_miss, num_extra = 0, 0
    num_true = 0
    all_time = 0
    num_ci = 0
    for m in range(filenumber):
        completePath = path + str(m + 1) + ".csv"
        data = pd.read_csv(completePath)
        get_p, get_c, get_un = [[]] * length_target_list, [[]] * \
            length_target_list, [[]] * length_target_list

        for i, target in enumerate(target_list):
            if method == "PCDbyPCD":
                start_time = time.process_time()
                parents, children, PC, undirected, n_c = PCDbyPCD(
                    data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "MBbyMB":
                start_time = time.process_time()
                parents, children, PC, undirected, n_c = MBbyMB(
                    data, target, alaph, is_discrete)
                end_time = time.process_time()
            elif method == "CMB":
                start_time = time.process_time()
                parents, children, PC, undirected, n_c = CMB(
                    data, target, alaph, is_discrete)
                end_time = time.process_time()
            else:
                raise Exception("method input error!")
            get_p[i] = parents
            get_c[i] = children
            get_un[i] = undirected
            all_time += end_time - start_time
            num_ci += n_c

        print("use time:", all_time)

        for n, target in enumerate(target_list):

            true_diection = list(
                (set(real_p[target]).intersection(set(get_p[n]))).union(
                    set(real_c[target]).intersection(set(get_c[n]))))
            num_true += len(true_diection)

            reverse_direction = list(
                (set(real_p[target]).intersection(set(get_c[n]))).union(
                    set(real_c[target]).intersection(set(get_p[n]))))
            num_re += len(reverse_direction)

            undirected_direction = list(get_un[n])
            num_undirect += len(undirected_direction)

            miss_direction = list(
                ((set(real_p[target]).difference(set(get_p[n]))).union(
                    set(real_c[target]).difference(set(get_c[n])))).difference(
                        set(reverse_direction).union(undirected_direction)))
            num_miss += len(miss_direction)

            extra_direction = list(
                ((set(get_p[n]).difference(real_p[target])).union(
                    set(get_c[n]).difference(set(real_c[target])))))
            num_extra += len(extra_direction)

    commonDivisor = length_target_list * filenumber

    return num_true / commonDivisor, num_re / commonDivisor, num_miss / commonDivisor, num_extra / commonDivisor, num_undirect / commonDivisor, num_ci / commonDivisor, all_time / commonDivisor