更改

添加3,350字节 、 2025年12月21日 (日) 16:04
第564行: 第564行:  
'''信息原子的数值计算'''
 
'''信息原子的数值计算'''
    +
部分信息分解示例和dit库
 +
为了将这些概念联系在一起,让我们看看一些例子。当涉及到信息理论概念时,dit是这些实验的绝佳工具。这是一个由创建自定义概率分布,然后对它们进行测量的lib组成。这个库中有几个功能,可以在他们的Github或官方文档页面上找到它们。
 +
对于所有示例,我们可以想到两个特征X_1和X_2,它们都是二进制的,目标变量Y是具有这些特征的布尔运算。所有测量部分信息的形式都将由Williams和Beer [1]提供,但其他作者提出的其他形式也在dit中实施。
 +
独特信息
 +
在这个例子中,假设目标变量Y由图给出。4.请注意,输出总是等于特征X_1,这使得特征X_2完全无关紧要。
 +
图4:AND门的图和唯一的信息来源。
 +
图4:AND门的图和唯一的信息来源。
 +
出于这个原因,X_1和X_2提供的关于Y的信息完全集中在X_1中。在我们迄今为止发展的形式主义中,我们可以说关于Y的信息是X_1独有的。
 +
在dit库中,我们可以创建这个:
 +
import dit                    # importing dit library
 +
from dit.pid import PID_WB    # importing the PID measure we want to use
   −
本部分为张江老师提供的建议:PID框架中的信息原子在数学上的定义式在百科中体现了之后,还可以考虑增加对PID框架信息原子的算法、程序包的介绍,可以引介一些算法、程序包、放上一些例子和效果。
+
# creating a probability distribution of AND gate
 +
dist_unique = dit.Distribution(["000", "010", "101", "111"], [1/4, 1/4, 1/4, 1/4])
    +
print(PID_WB(dist_unique))
    +
"""
 +
Out:
 +
+--------+--------+--------+
 +
| I_min  |  I_r  |  pi  |
 +
+--------+--------+--------+
 +
| {0:1}  | 1.0000 | 0.0000 |
 +
|  {0}  | 1.0000 | 1.0000 |
 +
|  {1}  | 0.0000 | 0.0000 |
 +
| {0}{1} | 0.0000 | 0.0000 |
 +
+--------+--------+--------+
 +
"""
 +
dit对信息类型进行编码如下:
 +
{0:1}:X_1和X_2之间的协同信息
 +
{0}:X_1提供的唯一信息
 +
{1}:X_2提供的唯一信息
 +
{0}{1}:X_1和X_2提供的冗余信息
 +
我们可以通过输出看到,提供的唯一部分信息(“pi”列)来自X_1。
 +
冗余信息
 +
下一个示例用于显示冗余信息。在这里,X_1、X_2和Y都相等,如图5所示,因此X_1和X_2提供的关于Y的冗余信息是最大的。
 +
图5:完全冗余的信息。
 +
图5:完全冗余的信息。
 +
使用dit,代码如下:
 +
import dit                    # importing dit library
 +
from dit.pid import PID_WB    # importing the PID measure we want to use
   −
https://towardsdatascience.com/what-is-partial-information-decomposition-and-how-features-interact-a713456a1029/<nowiki/>链接中提到了作为信息论实验的Dit库
+
# creating a redundant probability distribution
 +
dist_redundant = dit.Distribution(["000", "111"], [1/2, 1/2])
 +
print(PID_WB(d_redundant))
 +
 
 +
"""
 +
Out:
 +
+--------+--------+--------+
 +
| I_min  |  I_r  |  pi  |
 +
+--------+--------+--------+
 +
| {0:1}  | 1.0000 | 0.0000 |
 +
|  {0}  | 1.0000 | 0.0000 |
 +
|  {1}  | 1.0000 | 0.0000 |
 +
| {0}{1} | 1.0000 | 1.0000 |
 +
+--------+--------+--------+
 +
"""
 +
正如我们所看到的,X_1和X_2提供的关于Y的唯一信息是多余的,换句话说,两者都提供。
 +
协同信息
 +
协同信息的一个经典例子是XOR门。XOR门的图表如图所示。6.
 +
图6:具有完全协同信息的XOR门
 +
图6:具有完全协同信息的XOR门
 +
通过这个分布注意到,只有当我们同时知道X_1和X_2时,我们才能知道目标变量Y。没有X_1和X_2,就不可能知道Y,只是因为对于X_1的每个值,我们都有Y的两个值;X_2也是如此。代码indit是:
 +
import dit                    # importing dit library
 +
from dit.pid import PID_WB    # importing the PID measure we want to use
    +
# creating a probability distribution of XOR gate
 +
dist_syn = dit.Distribution(["000", "011", "101", "110"], [1/4]*4)
 +
print(dist_syn)
   −
James et al., (2018). dit: a Python package for discrete information theory. Journal of Open Source Software, 3(25), 738, <nowiki>https://doi.org/10.21105/joss.00738</nowiki>
+
"""
 +
Out:
 +
+--------+--------+--------+
 +
| I_min  |  I_r  |  pi  |
 +
+--------+--------+--------+
 +
| {0:1}  | 1.0000 | 1.0000 |
 +
|  {0}  | 0.0000 | 0.0000 |
 +
|  {1}  | 0.0000 | 0.0000 |
 +
| {0}{1} | 0.0000 | 0.0000 |
 +
+--------+--------+--------+
 +
"""
 +
不出所料,X_1和X_2传达的关于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
  
175

个编辑