更改

第370行: 第370行:  
[[文件:图4空间因果涌现(抵消退化).png|无框|居左|400x400像素]]
 
[[文件:图4空间因果涌现(抵消退化).png|无框|居左|400x400像素]]
   −
python代码实现:
+
布尔网络EI计算python代码:<syntaxhighlight lang="python3">
 +
import torch
 +
import itertools
 +
 
 +
def Entropia(a):
 +
    b = torch.nonzero(a > 0).squeeze(1)
 +
    return -torch.sum(a[b]*torch.log2(a[b]))
 +
 
 +
 
 +
def effective_information(G1):
 +
    """
 +
    Calculate EI value of transition probability matrix
 +
    :param G1: TPM matrix
 +
    :return: EI value
 +
    """
 +
    N = G1.shape[0]
 +
    G = torch.zeros_like(G1)
 +
    nozero_number = 0
 +
    for i in range(N):
 +
        if torch.sum(G1[i]) != 0:
 +
            G[i] = G1[i] / torch.sum(G1[i])
 +
            nozero_number += 1
 +
    Wout = torch.zeros(N)
 +
    Win = torch.zeros(N)
 +
 
 +
    for i in range(N):
 +
        if torch.sum(G[i]) != 0:
 +
            Wout[i] = torch.tensor(Entropia(G[i]))
 +
 
 +
    for i in range(N):
 +
        for j in range(N):
 +
            if G[i][j] != 0:
 +
                Win[j] += G[i][j] / nozero_number
 +
    Wout_average = torch.sum(Wout) / nozero_number
 +
    Win_entropy = Entropia(Win)
 +
    return Win_entropy - Wout_average
 +
 
 +
 
 
def calc_bn_ei(micro_mech, micro, edges, elem_group, mech_group):
 
def calc_bn_ei(micro_mech, micro, edges, elem_group, mech_group):
 
     """
 
     """
第391行: 第428行:  
     -------
 
     -------
 
     the EI value of micro and macro level.
 
     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
 
     Nmi = 2 ** micro
第431行: 第458行:     
     return micro_ei, macro_ei
 
     return micro_ei, macro_ei
 +
 +
# 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)
 +
 +
</syntaxhighlight>
    
=== 时间因果涌现 ===
 
=== 时间因果涌现 ===
5,443

个编辑