更改

第256行: 第256行:     
即存在着0.19比特的因果涌现,或用有效性度量得到0.595的因果涌现。
 
即存在着0.19比特的因果涌现,或用有效性度量得到0.595的因果涌现。
 +
 +
python:<syntaxhighlight lang="python3">
 +
def calc_tpm(micro_tpm, group):
 +
    """
 +
    Parameters
 +
    ----------
 +
    micro_tpm: the transition probability matrix of system in micro level.
 +
    group: the coarse-graining methods (e.g., group = [(0, 1, 2), (3,)]: the micro states 0,1,2 are grouped into macro state 0, and the micro state 3 is grouped into macro state 1.
 +
 +
    Returns
 +
    -------
 +
    micro_ei, macro_ei: the EI value of micro, macro TPM.
 +
    macro_tpm: the transition probability matrix of system in macro level
 +
 +
   
 +
    """
 +
    # the number of micro/macro states
 +
    Nmi = micro_tpm.shape[0]
 +
    Nma = len(group)
 +
   
 +
    # generate the mapping matrix from micro to macro
 +
    mapping = torch.zeros((Nmi, Nma), dtype=torch.float)
 +
    for j in range(Nma):
 +
        for i in group[j]:
 +
            mapping[i][j] = 1
 +
 +
    # apply the mapping matrix to micro_tpm, and get the macro_tpm
 +
    macro_tpm = mapping.t() @ micro_tpm @ mapping
 +
 +
    # calculate the EI of micro_tpm, macro_tpm
 +
    micro_ei = effective_information(micro_tpm)
 +
    macro_ei = effective_information(macro_tpm)
 +
 +
    return micro_ei, macro_ei, macro_tpm
 +
 +
 +
micro_tpm = torch.tensor([[1/3, 1/3, 1/3, 0], [1/3, 1/3, 1/3, 0], [1/3, 1/3, 1/3, 0], [0, 0, 0, 1]])
 +
group = [(0, 1, 2), (3,)]
 +
micro_ei, macro_ei, macro_tpm = calc_tpm(micro_tpm, group)
 +
</syntaxhighlight>
    
== 变量角度的因果涌现 ==
 
== 变量角度的因果涌现 ==
5,443

个编辑