Example #1
0
def anal_Am(np_pmf, pmf_index, sys_index, m):
    """ Analytic A_m """
    m_ind = len(pmf_index[0]) - 2 - m
    if m_ind < 0:
        print("require seq_len > 1+m")
        return None

    s_ind = pmf_index[sys_index][:, [-2, -1]].flatten()
    e_ind = np.delete(pmf_index, sys_index, axis=0)[:, m_ind:-1].flatten()
    se_ind = np.concatenate((s_ind, e_ind))

    margin_index = np.delete(pmf_index.flatten(), se_ind)
    margin_pmf = prob.numpy_margin(np_pmf, margin_index)

    x_ind = [list(se_ind).index(x) for x in s_ind][0:len(sys_index)]
    y_ind = [list(se_ind).index(x)
             for x in s_ind][len(sys_index):2 * len(sys_index)]

    # print("indices")
    # print(pmf_index)
    # print(se_ind)
    # print(total_ind)

    # inf.numpy_conditional_mutual_information()

    return inf.numpy_conditional_mutual_information(margin_pmf, x_ind, y_ind)
Example #2
0
def anal_step_cond_MI(np_pmf, pmf_index, xind, yind, zind=()):
    """ I(X;Y|Z), z optional """

    xy_index = list(itt.chain(*xind, *yind, *zind))

    margin_index = np.delete(pmf_index.flatten(), xy_index)
    margin_pmf = prob.numpy_margin(np_pmf, margin_index)

    XIND = [list(xy_index).index(x) for x in list(itt.chain(*xind))]
    YIND = [list(xy_index).index(x) for x in list(itt.chain(*yind))]

    if zind == ():
        return inf.numpy_mutual_information(margin_pmf, XIND, YIND)

    return inf.numpy_conditional_mutual_information(margin_pmf, XIND, YIND)
Example #3
0
def anal_IF(np_pmf, pmf_index, x_index):
    """ Analytic IF(X->Y) = I(Y_{n+1}:X_{n}|Y_{n}) """

    pmf_index = np.array(pmf_index)
    X_n = pmf_index[x_index][:, -2].flatten()
    Y_n = np.delete(pmf_index, x_index, axis=0)[:, -2].flatten()
    Y_n1 = np.delete(pmf_index, x_index, axis=0)[:, -1].flatten()
    flat_ind = np.sort(np.concatenate((X_n, Y_n, Y_n1)))

    margin_index = np.delete(pmf_index.flatten(), flat_ind)
    margin_pmf = prob.numpy_margin(np_pmf, margin_index)

    x_ind = [list(flat_ind).index(x) for x in X_n]
    y_ind = [list(flat_ind).index(y) for y in Y_n1]

    return inf.numpy_conditional_mutual_information(margin_pmf, x_ind, y_ind)
Example #4
0
def seq_IF(data, flow_from_index, flow_to_index, t_shift=1):
    """ IF(E->S) =  I(S_{n+1} : E_{n}|S_{n}) 
    
    Parameters
    ----------
    data : array_like
        rows represent variables columns represent time steps
    flow_from_index : list
        index for X in IF(X->Y)
    flow_to_index : list
        index for Y in IF(X->Y)
    """

    var_index = [flow_to_index, flow_from_index]
    step_index = [[t_shift, 0], [0]]

    seq_data, seq_index = seq_maker(data,
                                    var_index,
                                    step_index,
                                    return_index=True)
    seq_pmf = prob.numpy_pmf(seq_data)

    return inf.numpy_conditional_mutual_information(seq_pmf, seq_index[0],
                                                    seq_index[2])
Example #5
0
def seq_Am(data, sys_index, env_index, m, t_shift=1):
    """ I(S_{n+1} ; S_{n} | E_{n}, E_{n-1}, ... ,E_{n-m}) 
    
    Parameters
    ----------
    data : array_like
        rows represent variables columns represent time steps
    sys_index : list
        index for S in data
    env_index : list
        index for E in data
    """

    var_index = [sys_index, env_index]
    step_index = [[t_shift, 0], list(range(0, -(m + 1), -1))]

    seq_data, seq_index = seq_maker(data,
                                    var_index,
                                    step_index,
                                    return_index=True)
    seq_pmf = prob.numpy_pmf(seq_data)

    return inf.numpy_conditional_mutual_information(seq_pmf, seq_index[0],
                                                    seq_index[1])