更改

添加308字节 、 2026年9月11日 (星期五)
第969行: 第969行:  
部分信息分解示例和dit库
 
部分信息分解示例和dit库
 
当涉及到信息理论概念时,dit<ref name="James_dit">{{cite journal|author1=James R. G.|author2=Emenheiser J.|author3=Crutchfield J. P.|title=dit: a Python package for discrete information theory|journal=Journal of Open Source Software|year=2018|volume=3|issue=25|page=738|url=https://doi.org/10.21105/joss.00738}}</ref>
 
当涉及到信息理论概念时,dit<ref name="James_dit">{{cite journal|author1=James R. G.|author2=Emenheiser J.|author3=Crutchfield J. P.|title=dit: a Python package for discrete information theory|journal=Journal of Open Source Software|year=2018|volume=3|issue=25|page=738|url=https://doi.org/10.21105/joss.00738}}</ref>
−
是这些实验的绝佳工具。这是一个在你创建的自定义概率分布上进行测量的库(Https://Github.com/Dit/Dit)。
+
是这些实验的绝佳工具。这是一个在你创建的自定义[[概率分布]]上进行测量的库(Https://Github.com/Dit/Dit)。
−
首先我们有两个源变量<math>X_1</math>和<math>X_2</math>(它们都是二进制的)和一个目标变量<math>Y</math>,<math>Y</math>是关于这些源变量的布尔运算。所有测量部分信息的形式都将由Williams和Beer(2010)<ref name="Paul" />提供,但其他作者提出的其他形式也可以在dit中进行。
+
首先我们有两个[[源变量]]<math>X_1</math>和<math>X_2</math>(它们都是二进制的)和一个[[目标变量]]<math>Y</math>,<math>Y</math>是关于这些源变量的[[布尔运算]]。所有测量部分信息的形式都将由Williams和Beer(2010)<ref name="Paul" />提供,但其他作者提出的其他形式也可以在dit中进行。
   −
1.特有信息
+
1.[[特有信息]]
    
在这个例子中,假设目标变量<math>Y</math>由下表给出。请注意,输出总是等于<math>X_1</math>,因此<math>X_2</math>完全无关紧要。
 
在这个例子中,假设目标变量<math>Y</math>由下表给出。请注意,输出总是等于<math>X_1</math>,因此<math>X_2</math>完全无关紧要。
第991行: 第991行:  
在dit库中,我们可以创建这个:
 
在dit库中,我们可以创建这个:
   −
<pre>import dit                    # importing dit library
+
<syntaxhighlight lang="python" line>
 +
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
第1,003行: 第1,004行:       −
"""
      
Out:
 
Out:
第1,023行: 第1,023行:  
+--------+--------+--------+
 
+--------+--------+--------+
   −
"""</pre>
+
</syntaxhighlight>
    
dit对信息类型进行编码如下:
 
dit对信息类型进行编码如下:
   −
{0:1}:<math>X_1</math>和<math>X_2</math>之间的协同信息
+
{0:1}:<math>X_1</math>和<math>X_2</math>之间的[[协同信息]]
    
{0}:<math>X_1</math>提供的唯一信息
 
{0}:<math>X_1</math>提供的唯一信息
第1,033行: 第1,033行:  
{1}:<math>X_2</math>提供的唯一信息
 
{1}:<math>X_2</math>提供的唯一信息
   −
{0}{1}:<math>X_1</math>和<math>X_2</math>提供的冗余信息
+
{0}{1}:<math>X_1</math>和<math>X_2</math>提供的[[冗余信息]]
    
我们可以通过输出看到,提供的唯一部分信息(“pi”列)来自<math>X_1</math>。
 
我们可以通过输出看到,提供的唯一部分信息(“pi”列)来自<math>X_1</math>。
第1,050行: 第1,050行:     
使用dit,代码如下:
 
使用dit,代码如下:
−
 
+
<syntaxhighlight lang="python" line>
−
<pre>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
第1,062行: 第1,062行:  
print(PID_WB(dist_redundant))
 
print(PID_WB(dist_redundant))
   −
  −
"""
      
Out:  
 
Out:  
第1,083行: 第1,081行:  
+--------+--------+--------+
 
+--------+--------+--------+
   −
"""</pre>
+
</syntaxhighlight>
    
正如我们所看到的,<math>X_1</math>和<math>X_2</math>提供的关于<math>Y</math>的信息是冗余的,换句话说,两者都提供。
 
正如我们所看到的,<math>X_1</math>和<math>X_2</math>提供的关于<math>Y</math>的信息是冗余的,换句话说,两者都提供。
第1,106行: 第1,104行:  
代码是:
 
代码是:
   −
<Pre>import dit                    # importing dit library
+
<syntaxhighlight lang="python" line>
 +
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
第1,117行: 第1,116行:  
print(PID_WB(dist_syn))
 
print(PID_WB(dist_syn))
   −
  −
"""
      
Out:
 
Out:
第1,138行: 第1,135行:  
+--------+--------+--------+
 
+--------+--------+--------+
   −
"""</pre>
+
</syntaxhighlight>
    
<math>X_1</math>和<math>X_2</math>传达的关于<math>Y</math>的唯一信息是{0:1},这是协同信息。
 
<math>X_1</math>和<math>X_2</math>传达的关于<math>Y</math>的唯一信息是{0:1},这是协同信息。
第1,146行: 第1,143行:  
首先在python里导入dit.pit:
 
首先在python里导入dit.pit:
   −
<pre>In [1]: from dit.pid import *</pre>
+
<syntaxhighlight lang="python" line>In [1]: from dit.pid import *</syntaxhighlight>
    
随后给出一个分布:
 
随后给出一个分布:
   −
<pre>In [2]: d = dit.Distribution(['000', '011', '102', '113'], [1/4]*4)</pre>
+
<syntaxhighlight lang="python" line>In [2]: d = dit.Distribution(['000', '011', '102', '113'], [1/4]*4)</syntaxhighlight>
    
用给出的分布进行PID分解(更改“PID_"后面角标即可使用其他PID分解方法):
 
用给出的分布进行PID分解(更改“PID_"后面角标即可使用其他PID分解方法):
   −
<pre>In [3]: PID_WB(d)</pre>
+
<syntaxhighlight lang="python" line>In [3]: PID_WB(d)</syntaxhighlight>
    
输出结果:
 
输出结果:
   −
<pre>Out[13]:  
+
<syntaxhighlight lang="python" line>Out[13]:  
    
+--------+--------+--------+
 
+--------+--------+--------+
第1,174行: 第1,171行:  
| {0}{1} | 1.0000 | 1.0000 |
 
| {0}{1} | 1.0000 | 1.0000 |
   −
+--------+--------+--------+</pre>
+
+--------+--------+--------+</syntaxhighlight>
    
另外还有专门实现PID计算的pietromarchesi库:https://github.com/pietromarchesi/pidpy
 
另外还有专门实现PID计算的pietromarchesi库:https://github.com/pietromarchesi/pidpy
216

个编辑