更改

第369行: 第369行:     
[[文件:图4空间因果涌现(抵消退化).png|无框|居左|400x400像素]]
 
[[文件:图4空间因果涌现(抵消退化).png|无框|居左|400x400像素]]
 +
 +
python代码实现:
 +
def calc_bn_ei(micro_mech, micro, edges, elem_group, mech_group):
 +
    """
 +
    Calculate the effective information of boolean network in micro and macro level, given the micro mechanism and
 +
    coarse-graining methods.
 +
 +
    Parameters
 +
    ----------
 +
    micro_mech: boolean function, e.g., {'00': [0.7, 0.3], '01': [0.7, 0.3], '10': [0.7, 0.3], '11': [0, 1]} the
 +
            value means the probability of transferring to '0' and '1', correspondingly.
 +
    micro: the number of micro elements
 +
    edges: a list of tuple. the list means the input micro elements. e.g., edges[1] = (2, 3) means
 +
            the input of elements[1] is [2] and [3]
 +
    elem_group: the coarse-graining methods of micro elements, e.g., [(0, 1), (2, 3)] means coarse-graining
 +
            elements[0],[1] to be a macro element, and the [2] and [3] to be another.
 +
    mech_group: the coarse-graining method of micro_mech, e.g.,  mech_group = {'00': '0', '01': '0', '10': '0',
 +
            '11': '1'}
 +
 +
    Returns
 +
    -------
 +
    the EI value of micro and macro level.
 +
 +
    Example
 +
    -------
 +
    micro_mech = {'00': [0.7, 0.3], '01': [0.7, 0.3], '10': [0.7, 0.3], '11': [0, 1]}
 +
    micro = 4
 +
    edges = [(2, 3), (2, 3), (0, 1), (0, 1)]
 +
    elem_group = [(0, 1), (2, 3)]
 +
    mech_group = {'00': '0', '01': '0', '10': '0', '11': '1'}
 +
    micro_ei, macro_ei = calc_bn_ei(micro_mech, micro, edges, elem_group, mech_group)
 +
 +
    """
 +
    Nmi = 2 ** micro
 +
    node_list = list(itertools.product(['0', '1'], repeat=micro))
 +
    S_m = torch.zeros((Nmi, Nmi), dtype=torch.float)
 +
    for i, pre in enumerate(node_list):
 +
        for j, tmp in enumerate(node_list):
 +
            tr_pr = 1
 +
            for z in range(micro):
 +
                srce1 = pre[edges[z][0]]
 +
                srce2 = pre[edges[z][1]]
 +
                tr_pr *= micro_mech[srce1 + srce2][int(tmp[z])]
 +
            S_m[i][j] = tr_pr
 +
 +
    unique = set(mech_group.values())
 +
    Nma = len(unique) ** len(elem_group)
 +
    group = torch.zeros((Nmi, Nma), dtype=torch.float)
 +
    for i, item in enumerate(node_list):
 +
        Sma = ''
 +
        for elem in elem_group:
 +
            Smi = ''.join(item[idx] for idx in elem)
 +
            Sma += mech_group[Smi]
 +
        group[i, int(Sma, base=len(unique))] = 1
 +
 +
    S_M = group.t() @ S_m @ group
 +
    S_M = S_M / torch.sum(S_M, axis=1).unsqueeze(1)
 +
 +
    micro_ei = effective_information(S_m)
 +
    macro_ei = effective_information(S_M)
 +
 +
    return micro_ei, macro_ei
    
=== 时间因果涌现 ===
 
=== 时间因果涌现 ===
5,443

个编辑