Bayesian models of cognition have gained considerable traction in computational neuroscience and psychiatry. Their scopes are now expected to expand rapidly to artificial intelligence, providing general inference frameworks to support embodied, adaptable, and energy-efficient autonomous agents. A central theory in this domain is predictive coding, which posits that learning and behaviour are driven by hierarchical probabilistic inferences about the causes of sensory inputs. Biological realism constrains these networks to rely on simple local computations in the form of precision-weighted predictions and prediction errors. This can make this framework highly efficient, but its implementation comes with unique challenges on the software development side. Embedding such models in standard neural network libraries often becomes limiting, as these libraries' compilation and differentiation backends can force a conceptual separation between optimization algorithms and the systems being optimized. This critically departs from other biological principles such as self-monitoring, self-organisation, cellular growth and functional plasticity. In this paper, we introduce \texttt{pyhgf}: a Python package backed by JAX and Rust for creating, manipulating and sampling dynamic networks for predictive coding. We improve over other frameworks by enclosing the network components as transparent, modular and malleable variables in the message-passing steps. The resulting graphs can implement arbitrary computational complexities as beliefs propagation. But the transparency of core variables can also translate into inference processes that leverage self-organisation principles, and express structure learning, meta-learning or causal discovery as the consequence of network structural adaptation to surprising inputs. The code, tutorials and documentation are hosted at: https://github.com/ilabcode/pyhgf.
翻译:认知的贝叶斯模型在计算神经科学与精神病学领域已获得广泛关注。其应用范围正迅速扩展至人工智能领域,为具身化、自适应且高能效的自主智能体提供通用推理框架。该领域的核心理论是预测编码,该理论认为学习与行为由对感官输入成因的层次化概率推断所驱动。生物现实性要求此类网络依赖简单的局部计算,即精度加权的预测与预测误差。这使得该框架具备高效潜力,但其软件实现面临独特挑战。将此类模型嵌入标准神经网络库常受局限,因为这些库的编译与微分后端可能强制优化算法与被优化系统在概念上分离。这显著背离了其他生物学原理,如自我监控、自组织、细胞生长与功能可塑性。本文介绍 \texttt{pyhgf}:一个基于 JAX 和 Rust 的 Python 工具包,用于创建、操作和采样预测编码动态网络。本框架通过将网络组件封装为消息传递步骤中透明、模块化且可塑的变量实现改进。所得图结构可实现任意计算复杂度的置信传播。核心变量的透明性还可转化为利用自组织原则的推理过程,并将结构学习、元学习或因果发现表达为网络结构对意外输入的自适应结果。代码、教程与文档托管于:https://github.com/ilabcode/pyhgf。