Inference algorithms for probabilistic programming are complex imperative programs with many moving parts. Efficient inference often requires customising an algorithm to a particular probabilistic model or problem, sometimes called inference programming. Most inference frameworks are implemented in languages that lack a disciplined approach to side effects, which can result in monolithic implementations where the structure of the algorithms is obscured and inference programming is hard. Functional programming with typed effects offers a more structured and modular foundation for programmable inference, with monad transformers being the primary structuring mechanism explored to date. This paper presents an alternative approach to programmable inference, based on algebraic effects, building on recent work that used algebraic effects to represent probabilistic models. Using effect signatures to specify the key operations of the algorithms, and effect handlers to modularly interpret those operations for specific variants, we develop three abstract algorithms, or inference patterns, representing three important classes of inference: Metropolis-Hastings, particle filtering, and guided optimisation. We show how our approach reveals the algorithms' high-level structure, and makes it easy to tailor and recombine their parts into new variants. We implement the three inference patterns as a Haskell library, and discuss the pros and cons of algebraic effects vis-a-vis monad transformers as a structuring mechanism for modular imperative algorithm design. It should be possible to reimplement our library in any typed functional language able to emulate effects and effect handlers.
翻译:用于概率性编程的推算算法是具有许多移动部分的复杂必要程序。 高效推算通常要求将算法定制为特定概率模型或问题,有时称为推算程序。 多数推算框架的实施语言缺乏对副作用的纪律处理方法,这可能导致单一性实施,使算法的结构变得模糊不清,推论程序程序编制程序非常困难。 具有排版效果的功能性编程为可编程推断法提供了更结构化和模块化的基础, 调制器是迄今为止探索的主要结构化机制。 本文以升格效果为基础, 提出了一种可编程性设计推断法的替代方法。 以最近使用的算法效果模型代表了概率性模型。 使用效果签名来指定算法结构的关键操作, 和效果处理器对特定变法的操作进行模块化解释, 我们开发了三种抽象的算法, 代表了三种重要的推论类别: 美度- 哈斯调, 粒过滤, 和导算的变法性设计方法, 显示我们的新变法和变法方法, 显示我们的新变法。</s>