| 第429行: |
第429行: |
| | the EI value of micro and macro level. | | the EI value of micro and macro level. |
| | """ | | """ |
| | + | # generate the statue list of boolean nodes, based on the number of micro elements |
| | Nmi = 2 ** micro | | Nmi = 2 ** micro |
| | node_list = list(itertools.product(['0', '1'], repeat=micro)) | | node_list = list(itertools.product(['0', '1'], repeat=micro)) |
| | S_m = torch.zeros((Nmi, Nmi), dtype=torch.float) | | S_m = torch.zeros((Nmi, Nmi), dtype=torch.float) |
| | + | |
| | + | # calculate the transition probability matrix of micro level |
| | for i, pre in enumerate(node_list): | | for i, pre in enumerate(node_list): |
| | for j, tmp in enumerate(node_list): | | for j, tmp in enumerate(node_list): |
| 第441行: |
第444行: |
| | S_m[i][j] = tr_pr | | S_m[i][j] = tr_pr |
| | | | |
| | + | # calculate the grouping matrix from micro to macro level, based on the elem_group and mech_group. |
| | unique = set(mech_group.values()) | | unique = set(mech_group.values()) |
| | Nma = len(unique) ** len(elem_group) | | Nma = len(unique) ** len(elem_group) |
| 第451行: |
第455行: |
| | group[i, int(Sma, base=len(unique))] = 1 | | group[i, int(Sma, base=len(unique))] = 1 |
| | | | |
| | + | # calculate the transition probability matrix of macro level |
| | S_M = group.t() @ S_m @ group | | S_M = group.t() @ S_m @ group |
| | S_M = S_M / torch.sum(S_M, axis=1).unsqueeze(1) | | S_M = S_M / torch.sum(S_M, axis=1).unsqueeze(1) |
| | | | |
| | + | # calculate the EI of micro and macro level |
| | micro_ei = effective_information(S_m) | | micro_ei = effective_information(S_m) |
| | macro_ei = effective_information(S_M) | | macro_ei = effective_information(S_M) |
| | | | |
| | return micro_ei, macro_ei | | return micro_ei, macro_ei |
| | + | |
| | | | |
| | # Example:提高确定性实例 | | # Example:提高确定性实例 |
| 第466行: |
第473行: |
| | mech_group = {'00': '0', '01': '0', '10': '0', '11': '1'} | | 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) | | micro_ei, macro_ei = calc_bn_ei(micro_mech, micro, edges, elem_group, mech_group) |
| − |
| |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | | | |