Skip to main content
QUICK REVIEW

[论文解读] Py-Tetrad and RPy-Tetrad: A New Python Interface with R Support for Tetrad Causal Search

Joseph Ramsey, Bryan Andrews|PubMed|Aug 13, 2023
Bayesian Modeling and Causal InferenceComputer Science参考文献 2被引用 3
一句话总结

本文介绍了 Py-Tetrad 和 RPy-Tetrad,这是基于 JPype 和 Reticulate 的新型 Python 和 R 接口,可实现对 Tetrad 因果发现框架的无缝访问。通过利用现代且稳定的接口,这些工具克服了旧版库(如 javabridge 和 rjava)的局限性,为 Python 和 R 用户提供了对 Tetrad 最新算法(包括 GRaSP、FGES 和 FCI)的完整访问,显著提升了安装便捷性、跨语言兼容性以及对现代 Python 和 R 用户的持续支持。

ABSTRACT

We give novel Python and R interfaces for the (Java) Tetrad project for causal modeling, search, and estimation. The Tetrad project is a mainstay in the literature, having been under consistent development for over 30 years. Some of its algorithms are now classics, like PC and FCI; others are recent developments. It is increasingly the case, however, that researchers need to access the underlying Java code from Python or R. Existing methods for doing this are inadequate. We provide new, up-to-date methods using the JPype Python-Java interface and the Reticulate Python-R interface, directly solving these issues. With the addition of some simple tools and the provision of working examples for both Python and R, using JPype and Reticulate to interface Python and R with Tetrad is straightforward and intuitive.

研究动机与目标

  • 为应对研究人员日益增长的需求,即从 Python 和 R 中访问 Tetrad 的先进因果发现算法,而 Python 和 R 目前在数据科学和统计研究中占据主导地位。
  • 克服旧有接口(如 javabridge 和 rjava)的局限性,这些接口已过时、不稳定(尤其在 macOS 上),且仅能访问 Tetrad 功能的一小部分。
  • 提供一种现代、可维护且可扩展的接口,使用户能够通过 Python 和 R 完全访问 Tetrad 的整个 Java 代码库,从而促进更广泛的应用与可复现性。
  • 通过实现 Python/R 与 Tetrad 之间的直接数据与图结构转换,简化 Tetrad 在数据科学工作流中的集成,提供内置工具与示例。

提出的方法

  • 作者使用 JPype 库开发了 Py-Tetrad,以实现对 Tetrad 基于 Java 的因果搜索算法的原生 Python 访问。
  • 他们实现了高层级的 TetradSearch 类,抽象了底层的 JPype 调用,使用户无需编写 Java 互操作代码,即可执行图构建、评分选择和算法执行等常见任务。
  • 对于 R 用户,RPy-Tetrad 包利用 Reticulate 与 Py-Tetrad 接口连接,实现 R 与 Python 之间的双向数据共享,并通过 Python 路由连接,降低复杂性并确保一致性。
  • 这些工具包含预打包的实用程序,用于在 Python/R 与 Tetrad 之间转换数据集和图形模型,包括通过 Graphviz 和 DiagrammeR 实现的图可视化支持。
  • 作者提供了最新的、可运行的 Python 和 R 示例,展示了 GRaSP、FGES 和 FCI 等关键算法的使用,支持自助法(bootstrapping)和基于评分的结构学习。
  • 该系统设计为可扩展且可维护,计划支持 pip 和 CRAN 安装,鼓励用户通过 GitHub 问题跟踪系统提供反馈。
Figure 1: Graph for the JPype example in the text for ”Apple Watch Fitbit.”
Figure 1: Graph for the JPype example in the text for ”Apple Watch Fitbit.”

实验结果

研究问题

  • RQ1研究人员如何才能在 Python 和 R 中获得对 Tetrad 因果发现算法的可靠、完整访问?这些算法是用 Java 实现的。
  • RQ2现有接口(如 py-causal 和 r-causal)存在哪些局限性,特别是在依赖项过时和对 Tetrad 完整代码库访问受限方面?
  • RQ3JPype 和 Reticulate 是否能有效用于在 Python 和 R 中创建稳定、可维护且用户友好的 Tetrad Java 框架接口?
  • RQ4在实践中,如何高效且可靠地在 Python/R 与 Tetrad 的 Java 表示之间转换数据和图形模型?
  • RQ5通过用现代替代方案(如 pip 和 CRAN)替换旧接口(如 javabridge 和 rjava),在可用性、可靠性与功能访问方面可实现哪些改进?

主要发现

  • Py-Tetrad 和 RPy-Tetrad 提供了对 Tetrad 最新算法(包括 GRaSP、FGES 和 FCI)的完整访问,这些算法此前在旧工具(如 py-causal 和 r-causal)中不可用。
  • 使用 JPype 消除了 javabridge 常见的安装问题(尤其是在 macOS 上),使接口更加可靠且易于部署。
  • R 用户现在可通过 Reticulate 完全访问 Tetrad 的功能,数据和图可直接在 R 和 Python 之间共享,降低了复杂性并确保了更新的一致性。
  • TetradSearch 类提供了高层级、用户友好的 Tetrad 核心功能访问,无需用户编写低级 JPype 代码,显著提升了非专家用户对工具的可及性。
  • 这些工具支持高级功能,如自助法(例如 30 折重采样)和边频次可视化,结果可通过 Graphviz 和 DiagrammeR 在 R 中显示。
  • 作者报告了积极的初步反馈,计划通过 pip 和 CRAN 简化安装流程,表明其具有广泛采用的巨大潜力。
Figure 2: Plot matrix for the R code ”NASA Airfoil Self-Noise” example; this is displayed in the Plots window in RStudio. The psych package in R produced this plot matrix.
Figure 2: Plot matrix for the R code ”NASA Airfoil Self-Noise” example; this is displayed in the Plots window in RStudio. The psych package in R produced this plot matrix.

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。