Ejemplo n.º 1
0
def S2TMB_p(data, target):
    # step 1:find the PC set
    _, kVar = np.shape(data)
    pc_t = []
    o_set = [i for i in range(kVar) if i != target]
    for x in o_set:
        Z = set([target,x]).union(pc_t)
        DAG = optimal_network(Z, data)
        pc_t = [i for i in range(kVar) if DAG[target, i] == 1 or DAG[i, target] == 1]

    # step 2: remove false PC nodes and find spouses
    spouses_t = []
    varis_set = [i for i in range(kVar) if i != target and i not in pc_t]
    for x in varis_set:
        Z = set([target, x]).union(set(pc_t)).union(set(spouses_t))
        DAG = optimal_network(Z, data)
        pc_t = [i for i in range(kVar) if DAG[target, i] == 1 or DAG[i, target] == 1]
        sp = [i for i in range(kVar) for j in range(kVar) if i != target and DAG[target, j] == 1 and DAG[i, j] == 1]
        spouses_t = set(spouses_t).union(sp)

    # step 3: shrink spouses
    var_set = spouses_t.copy()
    spouses_t = []
    for x in var_set:
        Z = set([target, x]).union(pc_t).union(spouses_t)
        DAG = optimal_network(Z, data)
        pc_t = [i for i in range(kVar) if DAG[target, i] == 1 or DAG[i, target] == 1]
        spouses_t = [i for i in range(kVar) for j in range(kVar) if i != target and DAG[target, j] == 1 and DAG[i, j] == 1]

    MB = list(set(pc_t).union(set(spouses_t)))
    return pc_t, MB
Ejemplo n.º 2
0
def find_potential_neighbors(data, target):
    number, kVar = np.shape(data)
    O_set = [i for i in range(kVar) if i != target]
    ht_set = []
    for v in O_set:
        Z = list(set(ht_set).union(set([target, v])))
        A = optimal_network(Z, data)
        ht_set = [
            i for i in range(kVar)
            if i != target and A[i, target] == 1 or A[target, i] == 1
        ]
    return ht_set
Ejemplo n.º 3
0
def find_potential_spouses(data, target, ht_set):
    _, kVar = np.shape(data)
    ht_neighbors = []
    for x in ht_set:
        vari_set = find_neighbors(data, x)
        ht_neighbors = set(ht_neighbors).union(set(vari_set))
    O_set = set(ht_neighbors).difference(set(ht_set).union(set([target])))
    st_set = []
    for v in O_set:
        Z = set([target, v]).union(ht_neighbors).union(st_set)
        A = optimal_network(Z, data)
        st_set = [
            i for i in range(kVar) for j in range(kVar)
            if i != target and A[target, j] == 1 and A[i, j] == 1
        ]

    return st_set