| 第565行: |
第565行: |
| | | | |
| | 部分信息分解示例和dit库 | | 部分信息分解示例和dit库 |
| − | 为了将这些概念联系在一起,让我们看看一些例子。当涉及到信息理论概念时,dit是这些实验的绝佳工具。这是一个由创建自定义概率分布,然后对它们进行测量的lib组成。这个库中有几个功能,可以在他们的Github或官方文档页面上找到它们。
| + | 当涉及到信息理论概念时,dit是这些实验的绝佳工具。这是一个在你创建的自定义概率分布上进行测量的库(Https://Github.com/Dit/Dit)。 |
| − | 对于所有示例,我们可以想到两个特征X_1和X_2,它们都是二进制的,目标变量Y是具有这些特征的布尔运算。所有测量部分信息的形式都将由Williams和Beer [1]提供,但其他作者提出的其他形式也在dit中实施。
| + | 首先我们有两个源变量<math>X_1</math>和<math>X_2</math>(它们都是二进制的)和一个目标变量Y,Y是关于这些源变量的布尔运算。所有测量部分信息的形式都将由Williams和Beer提供,但其他作者提出的其他形式也可以在dit中进行。 |
| − | 独特信息
| + | |
| − | 在这个例子中,假设目标变量Y由图给出。4.请注意,输出总是等于特征X_1,这使得特征X_2完全无关紧要。
| + | 1.独特信息 |
| − | 图4:AND门的图和唯一的信息来源。
| + | |
| − | 图4:AND门的图和唯一的信息来源。
| + | 在这个例子中,假设目标变量Y由下表给出。请注意,输出总是等于<math>X_1</math>,这使得特征<math>X_2</math>完全无关紧要。 |
| − | 出于这个原因,X_1和X_2提供的关于Y的信息完全集中在X_1中。在我们迄今为止发展的形式主义中,我们可以说关于Y的信息是X_1独有的。
| + | {| class="wikitable" |
| | + | |- |
| | + | |<math>X_1</math>||<math>X_2</math>||<math>Y</math> |
| | + | |- |
| | + | |0||0||0 |
| | + | |- |
| | + | |0||1||0 |
| | + | |- |
| | + | |1||0||1 |
| | + | |- |
| | + | |1||1||1 |
| | + | |} |
| | + | 因此,<math>X_1</math>和<math>X_2</math>提供的关于Y的信息完全集中在<math>X_1</math>中,我们可以说关于Y的信息是X_1独有的。 |
| | + | |
| | 在dit库中,我们可以创建这个: | | 在dit库中,我们可以创建这个: |
| | + | |
| | import dit # importing dit library | | import dit # importing dit library |
| | + | |
| | from dit.pid import PID_WB # importing the PID measure we want to use | | from dit.pid import PID_WB # importing the PID measure we want to use |
| | + | |
| | | | |
| | # creating a probability distribution of AND gate | | # creating a probability distribution of AND gate |
| | + | |
| | dist_unique = dit.Distribution(["000", "010", "101", "111"], [1/4, 1/4, 1/4, 1/4]) | | dist_unique = dit.Distribution(["000", "010", "101", "111"], [1/4, 1/4, 1/4, 1/4]) |
| | | | |
| | print(PID_WB(dist_unique)) | | print(PID_WB(dist_unique)) |
| | + | |
| | | | |
| | """ | | """ |
| | + | |
| | Out: | | Out: |
| | + | |
| | +--------+--------+--------+ | | +--------+--------+--------+ |
| | + | |
| | | I_min | I_r | pi | | | | I_min | I_r | pi | |
| | + | |
| | +--------+--------+--------+ | | +--------+--------+--------+ |
| | + | |
| | | {0:1} | 1.0000 | 0.0000 | | | | {0:1} | 1.0000 | 0.0000 | |
| | + | |
| | | {0} | 1.0000 | 1.0000 | | | | {0} | 1.0000 | 1.0000 | |
| | + | |
| | | {1} | 0.0000 | 0.0000 | | | | {1} | 0.0000 | 0.0000 | |
| | + | |
| | | {0}{1} | 0.0000 | 0.0000 | | | | {0}{1} | 0.0000 | 0.0000 | |
| | + | |
| | +--------+--------+--------+ | | +--------+--------+--------+ |
| | + | |
| | """ | | """ |
| | + | |
| | dit对信息类型进行编码如下: | | dit对信息类型进行编码如下: |
| − | {0:1}:X_1和X_2之间的协同信息 | + | |
| − | {0}:X_1提供的唯一信息 | + | {0:1}:<math>X_1</math>和<math>X_2</math>之间的协同信息 |
| − | {1}:X_2提供的唯一信息 | + | |
| − | {0}{1}:X_1和X_2提供的冗余信息 | + | {0}:<math>X_1</math>提供的唯一信息 |
| | + | |
| | + | {1}:<math>X_2</math>提供的唯一信息 |
| | + | |
| | + | {0}{1}:<math>X_1</math>和<math>X_2</math>提供的冗余信息 |
| | + | |
| | 我们可以通过输出看到,提供的唯一部分信息(“pi”列)来自X_1。 | | 我们可以通过输出看到,提供的唯一部分信息(“pi”列)来自X_1。 |
| − | 冗余信息 | + | |
| − | 下一个示例用于显示冗余信息。在这里,X_1、X_2和Y都相等,如图5所示,因此X_1和X_2提供的关于Y的冗余信息是最大的。
| + | 2.冗余信息 |
| − | 图5:完全冗余的信息。
| + | |
| − | 图5:完全冗余的信息。
| + | 下一个示例用于显示冗余信息。在这里,<math>X_1</math>、<math>X_2</math>和Y都相等,如下表所示,因此<math>X_1</math>和<math>X_2</math>提供的关于Y的冗余信息是最大的。 |
| | + | {| class="wikitable" |
| | + | |- |
| | + | |<math>X_1</math>||<math>X_2</math>||<math>Y</math> |
| | + | |- |
| | + | |0||0||0 |
| | + | |- |
| | + | |1||1||1 |
| | + | |} |
| | + | |
| | 使用dit,代码如下: | | 使用dit,代码如下: |
| | + | |
| | import dit # importing dit library | | import dit # importing dit library |
| | + | |
| | from dit.pid import PID_WB # importing the PID measure we want to use | | from dit.pid import PID_WB # importing the PID measure we want to use |
| | + | |
| | | | |
| | # creating a redundant probability distribution | | # creating a redundant probability distribution |
| | + | |
| | dist_redundant = dit.Distribution(["000", "111"], [1/2, 1/2]) | | dist_redundant = dit.Distribution(["000", "111"], [1/2, 1/2]) |
| | + | |
| | print(PID_WB(d_redundant)) | | print(PID_WB(d_redundant)) |
| | + | |
| | | | |
| | """ | | """ |
| | + | |
| | Out: | | Out: |
| | + | |
| | +--------+--------+--------+ | | +--------+--------+--------+ |
| | + | |
| | | I_min | I_r | pi | | | | I_min | I_r | pi | |
| | + | |
| | +--------+--------+--------+ | | +--------+--------+--------+ |
| | + | |
| | | {0:1} | 1.0000 | 0.0000 | | | | {0:1} | 1.0000 | 0.0000 | |
| | + | |
| | | {0} | 1.0000 | 0.0000 | | | | {0} | 1.0000 | 0.0000 | |
| | + | |
| | | {1} | 1.0000 | 0.0000 | | | | {1} | 1.0000 | 0.0000 | |
| | + | |
| | | {0}{1} | 1.0000 | 1.0000 | | | | {0}{1} | 1.0000 | 1.0000 | |
| | + | |
| | +--------+--------+--------+ | | +--------+--------+--------+ |
| | + | |
| | """ | | """ |
| − | 正如我们所看到的,X_1和X_2提供的关于Y的唯一信息是多余的,换句话说,两者都提供。
| + | |
| − | 协同信息 | + | 正如我们所看到的,X_1和X_2提供的关于Y的信息是冗余的,换句话说,两者都提供。 |
| − | 协同信息的一个经典例子是XOR门。XOR门的图表如图所示。6.
| + | |
| − | 图6:具有完全协同信息的XOR门
| + | 3.协同信息 |
| − | 图6:具有完全协同信息的XOR门
| + | |
| − | 通过这个分布注意到,只有当我们同时知道X_1和X_2时,我们才能知道目标变量Y。没有X_1和X_2,就不可能知道Y,只是因为对于X_1的每个值,我们都有Y的两个值;X_2也是如此。代码indit是:
| + | 协同信息的一个经典例子是XOR门,如下表所示。 |
| | + | {| class="wikitable" |
| | + | |- |
| | + | |<math>X_1</math>||<math>X_2</math>||<math>Y</math> |
| | + | |- |
| | + | |0||0||0 |
| | + | |- |
| | + | |0||1||1 |
| | + | |- |
| | + | |1||0||1 |
| | + | |- |
| | + | |1||1||0 |
| | + | |} |
| | + | 通过这个分布注意到,只有当我们同时知道<math>X_1</math>和<math>X_2</math>时,我们才能知道目标变量Y。没有<math>X_1</math>和<math>X_2</math>,就不可能知道Y。因为对于<math>X_1</math>的每个值,我们都有Y的两个值;<math>X_2</math>也是如此。 |
| | + | |
| | + | 代码indit是: |
| | + | |
| | import dit # importing dit library | | import dit # importing dit library |
| | + | |
| | from dit.pid import PID_WB # importing the PID measure we want to use | | from dit.pid import PID_WB # importing the PID measure we want to use |
| | + | |
| | | | |
| | # creating a probability distribution of XOR gate | | # creating a probability distribution of XOR gate |
| | + | |
| | dist_syn = dit.Distribution(["000", "011", "101", "110"], [1/4]*4) | | dist_syn = dit.Distribution(["000", "011", "101", "110"], [1/4]*4) |
| | + | |
| | print(dist_syn) | | print(dist_syn) |
| | + | |
| | | | |
| | """ | | """ |
| | + | |
| | Out: | | Out: |
| | + | |
| | +--------+--------+--------+ | | +--------+--------+--------+ |
| | + | |
| | | I_min | I_r | pi | | | | I_min | I_r | pi | |
| | + | |
| | +--------+--------+--------+ | | +--------+--------+--------+ |
| | + | |
| | | {0:1} | 1.0000 | 1.0000 | | | | {0:1} | 1.0000 | 1.0000 | |
| | + | |
| | | {0} | 0.0000 | 0.0000 | | | | {0} | 0.0000 | 0.0000 | |
| | + | |
| | | {1} | 0.0000 | 0.0000 | | | | {1} | 0.0000 | 0.0000 | |
| | + | |
| | | {0}{1} | 0.0000 | 0.0000 | | | | {0}{1} | 0.0000 | 0.0000 | |
| | + | |
| | +--------+--------+--------+ | | +--------+--------+--------+ |
| | + | |
| | """ | | """ |
| − | 不出所料,X_1和X_2传达的关于Y的唯一信息是{0:1},这是协同信息。
| + | |
| | + | 不出所料,<math>X_1</math>和<math>X_2</math>传达的关于Y的唯一信息是{0:1},这是协同信息。 |
| | + | |
| | | | |
| | | | |
| − | https://towardsdatascience.com/what-is-partial-information-decomposition-and-how-features-interact-a713456a1029/<nowiki/>链接中提到了作为信息论实验的Dit库
| |
| | 还有专门实现PID计算的pietromarchesi库:https://github.com/pietromarchesi/pidpy | | 还有专门实现PID计算的pietromarchesi库:https://github.com/pietromarchesi/pidpy |
| | | | |