楼主: majianthu
1238 3

[程序分享] copent包0.2版已在CRAN发布 [推广有奖]

  • 0关注
  • 8粉丝

讲师

12%

还不是VIP/贵宾

-

威望
0
论坛币
1473 个
通用积分
444.8383
学术水平
75 点
热心指数
60 点
信用等级
58 点
经验
2566 点
帖子
75
精华
1
在线时间
639 小时
注册时间
2020-5-12
最后登录
2025-4-24

楼主
majianthu 发表于 2021-3-21 17:33:53 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
copent包0.2版已在CRAN发布,同时在github发布。可从CRAN或github安装。
原来的0.1版提供copula熵估计,可进行统计独立性测试。
0.2版又增加了基于copula熵估计的条件独立性测试传递熵(Transfer Entropy)估计两个功能,分别由 ci 和 transent 两个函数实现。
欢迎大家使用,并提出宝贵意见。

CRAN:
https://cran.r-project.org/web/packages/copent/index.html
GitHub:
https://github.com/majianthu/copent

此包的python版本同时更新到0.2版,增加了同样功能的同名函数。已在PyPI上发布。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Open COPE CRAN CRA Pen

已有 4 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
Sunknownay + 3 + 3 + 3 精彩帖子
tulipsliu + 5 + 5 + 5 精彩帖子
cheetahfly + 50 精彩帖子
llb_321 + 5 精彩帖子

总评分: 论坛币 + 55  学术水平 + 8  热心指数 + 8  信用等级 + 8   查看全部评分

沙发
tulipsliu 在职认证  发表于 2021-3-22 07:17:18
一定支持, 我可以下载源代码看不?
通过 git for windows ,
用 Rstudio 版本控制下载项目;

check , build  , 看看代码。

藤椅
tulipsliu 在职认证  发表于 2021-3-22 07:20:42
源代码是这个。

  1. ##################################################################################
  2. ###  Estimating Copula Entropy and Transfer Entropy
  3. ###  2021-03-20
  4. ###  by MA Jian (Email: majian03@gmail.com)
  5. ###
  6. ###  Parameters
  7. ###   x                : N * d data, N samples, d dimensions
  8. ###   k         : kth nearest neighbour, parameter for kNN entropy estimation
  9. ###   dt        : distance type [1: 'Euclidean', others: 'Maximum distance']
  10. ###   lag        : time lag
  11. ###
  12. ###  References
  13. ###  [1] Ma Jian, Sun Zengqi. Mutual information is copula entropy.
  14. ###      arXiv:0808.0845, 2008.
  15. ###  [2] Kraskov A, St\"ogbauer H, Grassberger P. Estimating mutual information.
  16. ###      Physical review E, 2004, 69(6): 066138.
  17. ###  [3] Ma Jian. Estimating Transfer Entropy via Copula Entropy.
  18. ###      arXiv preprint arXiv:1910.04375, 2019.
  19. ##################################################################################
  20. copent<-function(x,k=3,dt=2){
  21.   xc = construct_empirical_copula(x)
  22.   -entknn(xc,k,dt)
  23. }

  24. construct_empirical_copula<-function(x){
  25.   dimx = dim(as.matrix(x));
  26.   rx = dimx[1];
  27.   lx = dimx[2];
  28.   
  29.   xrank = x
  30.   for(i in 1:lx){
  31.     xrank[,i] = rank(x[,i])
  32.   }
  33.   
  34.   xrank / rx
  35. }

  36. entknn<-function(x,k=3,dt=2){
  37.   x = as.matrix(x)
  38.   # get the dimension of data x
  39.   N = dim(x)[1];
  40.   d = dim(x)[2];
  41.   
  42.   g1 = digamma(N) - digamma(k);
  43.   
  44.   if (dt == 1){        # euciledean distance
  45.     cd = pi^(d/2) / 2^d / gamma(1+d/2);       
  46.     distx = as.matrix(dist(x));
  47.   }
  48.   else {        # maximum distance
  49.     cd = 1;
  50.     distx = as.matrix(dist(x,method = "maximum"));
  51.   }
  52.   
  53.   logd = 0;
  54.   for(i in 1:N){
  55.     distx[i,] = sort(distx[i,]);
  56.     logd = logd + log( 2 * distx[i,k+1] ) * d / N;
  57.   }
  58.   
  59.   g1 + log(cd) + logd
  60. }

  61. ci<-function(x,y,z,k=3,dt=2){
  62.   xyz = cbind(x,y,z)
  63.   xz  = cbind(x,z)
  64.   yz  = cbind(y,z)
  65.   
  66.   copent(xyz,k,dt) - copent(xz,k,dt) - copent(yz,k,dt)
  67. }

  68. transent<-function(x,y,lag=1,k=3,dt=2){
  69.   xl = length(x)
  70.   yl = length(y)
  71.   if (xl > yl){
  72.     l = yl
  73.   }
  74.   else {
  75.     l = xl
  76.   }
  77.   x1 = x[1:(l-lag)]
  78.   x2 = x[(lag+1):l]
  79.   y1 = y[1:(l-lag)]

  80.   ci(x2,y1,x1,k,dt)
  81. }
复制代码


您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-7 20:39