Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Functional programming for modular Bayesian inference

Published: 30 July 2018 Publication History
  • Get Citation Alerts
  • Abstract

    We present an architectural design of a library for Bayesian modelling and inference in modern functional programming languages. The novel aspect of our approach are modular implementations of existing state-of-the-art inference algorithms. Our design relies on three inherently functional features: higher-order functions, inductive data-types, and support for either type-classes or an expressive module system. We provide a performant Haskell implementation of this architecture, demonstrating that high-level and modular probabilistic programming can be added as a library in sufficiently expressive languages. We review the core abstractions in this architecture: inference representations, inference transformations, and inference representation transformers. We then implement concrete instances of these abstractions, counterparts to particle filters and Metropolis-Hastings samplers, which form the basic building blocks of our library. By composing these building blocks we obtain state-of-the-art inference algorithms: Resample-Move Sequential Monte Carlo, Particle Marginal Metropolis-Hastings, and Sequential Monte Carlo Squared. We evaluate our implementation against existing probabilistic programming systems and find it is already competitively performant, although we conjecture that existing functional programming optimisation techniques could reduce the overhead associated with the abstractions we use. We show that our modular design enables deterministic testing of inherently stochastic Monte Carlo algorithms. Finally, we demonstrate using OCaml that an expressive module system can also implement our design.

    Supplementary Material

    WEBM File (a83-scibior.webm)

    References

    [1]
    Martín Abadi, Ashish Agarwal, Paul Barham, Eugene Brevdo, Zhifeng Chen, Craig Citro, Greg S. Corrado, Andy Davis, Jeffrey Dean, Matthieu Devin, Sanjay Ghemawat, Ian Goodfellow, Andrew Harp, Geoffrey Irving, Michael Isard, Yangqing Jia, Rafal Jozefowicz, Lukasz Kaiser, Manjunath Kudlur, Josh Levenberg, Dan Mané, Rajat Monga, Sherry Moore, Derek Murray, Chris Olah, Mike Schuster, Jonathon Shlens, Benoit Steiner, Ilya Sutskever, Kunal Talwar, Paul Tucker, Vincent Vanhoucke, Vijay Vasudevan, Fernanda Viégas, Oriol Vinyals, Pete Warden, Martin Wattenberg, Martin Wicke, Yuan Yu, and Xiaoqiang Zheng. 2015. TensorFlow: Large-Scale Machine Learning on Heterogeneous Systems. (2015). https://www.tensorflow.org/ Software available from tensorflow.org.
    [2]
    Nathanael L. Ackerman, Cameron E. Freer, and Daniel M. Roy. 2011. Noncomputable Conditional Distributions. In LiCS. http://ieeexplore.ieee.org/document/5970208/
    [3]
    Chrisophe Andrieu, Arnaud Doucet, and Roman Holenstein. 2010. Particle Markov chain Monte Carlo methods. Journal of the Royal Statistical Society 72 (2010), 269–342. www.stats.ox.ac.uk/~doucet/andrieu_doucet_holenstein_PMCMC.pdf
    [4]
    David Barber. 2012. Bayesian Reasoning and Machine Learning. Cambridge University Press.
    [5]
    Christopher Bishop. 2006. Pattern Recognition and Machine Learning. Springer-Verlag New York. http://www.springer.com/ gb/book/9780387310732
    [6]
    Mario Blažević. 2011. Coroutine Pipelines. The Monad Reader (2011), 29–50. Issue 19.
    [7]
    Jacques Carette, Oleg Kiselyov, and Chung-Chieh Shan. 2009. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. Journal of Functional Programming 19, 5 (2009), 509–543.
    [8]
    Bob Carpenter, Andrew Gelman, Matthew D. Hoffman, Daniel Lee, Ben Goodrich, Michael Betancourt, Marcus Brubaker, Jiqiang Guo, Peter Li, and Allen Riddell. 2017. Stan: A probabilistic programming language. Journal of Statistical Software 76 (2017).
    [9]
    Manuel M. T. Chakravarty, Gabriele Keller, Sean Lee, Trevor L. McDonell, and Vinod Grover. 2011. Accelerating Haskell Array Codes with Multicore GPUs. In DAMP.
    [10]
    Nicolas Chopin, Pierre E. Jacob, and Omiros Papaspiliopoulos. 2013. SMC2: an efficient algorithm for sequential analysis of state space models. Journal of the Royal Statistical Society Series B: Statistical Methodology 75 (2013), 397–426. Issue 3.
    [11]
    Duncan Coutts, Roman Leshchinskiy, and Don Stewart. 2007. Stream fusion: from lists to streams to nothing at all. In Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming, ICFP 2007, Freiburg, Germany, October 1-3, 2007, Ralf Hinze and Norman Ramsey (Eds.). ACM, 315–326.
    [12]
    Arthur P. Dempster, Nan M. Laird, and Donald B. Rubin. 1977. Maximum likelihood from incomplete data via the EM algorithm. Journal of the Royal Statistical Society Series B: Statistical Methodology 39 (1977), 1–38. Issue 1. https: //mathscinet.ams.org/mathscinet-getitem?mr=0501537
    [13]
    Arnaud Doucet and Adam M. Johansen. 2011. A Tutorial on Particle Filtering and Smoothing: Fifteen years later. In The Oxford Handbook of Nonlinear Filtering, Dan Crisan and Boris Rozovskii (Eds.). Oxford University Press, Chapter 8.
    [14]
    Walter Gilks and Carlo Berzuini. 2001. Following a moving target - Monte Carlo inference for dynamic Bayesian models. Journal of the Royal Statistical Society 63 (2001), 127–146. www.mathcs.emory.edu/~whalen/Papers/BNs/MonteCarlo-DBNs. pdf
    [15]
    W. R. Gilks, A. Thomas, and D. J. Spiegelhalter. 1994. A Language and Program for Complex Bayesian Modelling. Journal of the Royal Statistical Society. Series D 43 (1994).
    [16]
    Noah Goodman, Vikash Mansinghka, Daniel Roy, Keith Bonawitz, and Joshua Tenenbaum. 2008. Church: a language for generative models. In UAI. http://cocolab.stanford.edu/papers/GoodmanEtAl2008-UncertaintyInArtificialIntelligence.pdf
    [17]
    Noah Goodman and Andreas Stuhlmüller. 2014. Design and Implementation of Probabilistic Programming Languages. http://dippl.org . (2014).
    [18]
    Chris Heunen, Ohad Kammar, Sam Staton, and Hongseok Yang. 2017. A convenient category for higher-order probability theory. In LiCS. http://ieeexplore.ieee.org/document/8005137/
    [19]
    Sheng Liang and Paul Hudak. 1996. Modular Denotational Semantics for Compiler Construction. In ESOP.
    [20]
    David J. C. MacKay. 2003. Information Theory, Inference and Learning Algorithms. Cambridge University Press. www. inference.org.uk/itila/book.html
    [21]
    Vikash Mansinghka, Daniel Selsam, and Yura Perov. 2014. Venture: a higher-order probabilistic programming platform with programmable inference. arXiv:1404.0099. (2014).
    [22]
    Tom Minka, John Winn, J. Guiver, S. Webster, Y. Zaykov, B. Yangel, A. Spengler, and J. Bronskill. 2014. Infer.NET 2.6. Microsoft Research Cambridge. http://research.microsoft.com/infernet. (2014).
    [23]
    Lawrence M. Murray. 2013. Bayesian State-Space Modelling on High-Performance Hardware Using LibBi. arXiv:1306.3277. (2013).
    [24]
    Radford M. Neal. 2010. MCMC using Hamiltonian dynamics. In Handbook of Markov Chain Monte Carlo. Chapman and Hall.
    [25]
    Aditya V. Nori, Chung-Kil Hur, Sriram K. Rajamani, and Selva Samuel. 2014. R2: An Efficient MCMC Sampler for Probabilistic Programs. In AAAI.
    [26]
    Anand Patil, David Huard, and Christopher J. Fonnesbeck. 2010. PyMC: Bayesian Stochastic Modelling in Python. Journal of Statistical Software 35 (2010).
    [27]
    Avi Pfeffer. 2001. IBAL: A Probabilistic Rational Programming Language. In IJCAI.
    [28]
    Avi Pfeffer. 2015. Practical Probabilistic Programming. Manning. https://www.manning.com/books/ practical-probabilistic-programming
    [29]
    Rajesh Ranganath, Sean Gerrish, and David Blei. 2014. Black-Box Variational Inference. In AISTATS. http://www.jmlr.org/ proceedings/papers/v33/ranganath14.html
    [30]
    Daniel Ritchie, Andreas Stuhlmüller, and Noah D. Goodman. 2016. C3: Lightweight Incrementalized MCMC for Probabilistic Programs using Continuations and Callsite Caching. In AISTATS. http://proceedings.mlr.press/v51/ritchie16.html
    [31]
    Adam Ścibior, Zoubin Ghahramani, and Andrew Gordon. 2015. Practical Probabilistic Programming with Monads. In Haskell. http://dl.acm.org/citation.cfm?id=2804317
    [32]
    Adam Ścibior, Ohad Kammar, Matthijs Vákár, Sam Staton, Hongseok Yang, Yufei Cai, Klaus Ostermann, Sean K. Moss, Chris Heunen, and Zoubin Ghahramani. 2018. Denotational Validation of Higher-Order Bayesian Inference. Proceedings of the ACM on Programming Languages 2 (2018).
    [33]
    Sam Staton. 2017. Commutative semantics for probabilistic programming. In Proc. ESOP 2017.
    [34]
    David Tolpin, Jan-Willem van de Meent, and Frank Wood. 2015. Probabilistic Programming in Anglican. In Machine Learning and Knowledge Discovery in Databases, Albert Bifet, Michael May, Bianca Zadrozny, Ricard Gavalda, Dino Pedreschi, Francesco Bonchi, Jaime Cardoso, and Myra Spiliopoulou (Eds.). Lecture Notes in Computer Science, Vol. 9286. Springer International Publishing, 308–311.
    [35]
    Dustin Tran, Matthew D. Hoffman, Rif A. Saurous, Eugene Brevdo, Kevin Murphy, and David M. Blei. 2017. Deep Probabilistic Programming. In ICLR.
    [36]
    Liang Wang. 2017. Owl: A General-Purpose Numerical Library in OCaml. arXiv:1707.09616. (2017).
    [37]
    Leo White, Frédéric Bour, and Jeremy Yallop. 2015. Modular Implicits. ACM Workshop on ML 2014 post-proceedings. (September 2015).
    [38]
    David Wingate, Andreas Stuhlmüller, and Noah Goodman. 2011. Lightweight Implementations of Probabilistic Programming Languages Via Transformational Compilation. In AISTATS. https://web.stanford.edu/~ngoodman/papers/ lightweight-mcmc-aistats2011.pdf The published version contains a serious bug in the algorithm description, which was fixed in Revision 3 available from the authors page.
    [39]
    Frank Wood, Jan-Willem van de Meent, and Vikash Mansinghka. 2014. A New Approach to Probabilistic Programming Inference. In AISTATS. http://www.robots.ox.ac.uk/~fwood/assets/pdf/Wood-AISTATS-2014.pdf
    [40]
    Robert Zinkov and Chung-chieh Shan. 2017. Composing inference algorithms as program transformations. In UAI.

    Cited By

    View all
    • (2024)Probabilistic Programming with Programmable Variational InferenceProceedings of the ACM on Programming Languages10.1145/36564638:PLDI(2123-2147)Online publication date: 20-Jun-2024
    • (2024)Suspension Analysis and Selective Continuation-Passing Style for Universal Probabilistic Programming LanguagesProgramming Languages and Systems10.1007/978-3-031-57267-8_12(302-330)Online publication date: 5-Apr-2024
    • (2023)Effect Handlers for Programmable InferenceProceedings of the 16th ACM SIGPLAN International Haskell Symposium10.1145/3609026.3609729(44-58)Online publication date: 30-Aug-2023
    • Show More Cited By

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image Proceedings of the ACM on Programming Languages
    Proceedings of the ACM on Programming Languages  Volume 2, Issue ICFP
    September 2018
    1133 pages
    EISSN:2475-1421
    DOI:10.1145/3243631
    Issue’s Table of Contents
    This work is licensed under a Creative Commons Attribution International 4.0 License.

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 30 July 2018
    Published in PACMPL Volume 2, Issue ICFP

    Permissions

    Request permissions for this article.

    Check for updates

    Badges

    Author Tags

    1. Anglican
    2. Bayesian inference
    3. Markov Chain Monte Carlo
    4. Monte Carlo samplers
    5. Sequential Monte Carlo
    6. WebPPL
    7. functional programming
    8. higher-order functions
    9. inductive types
    10. machine learning
    11. module systems
    12. monad transformers
    13. monads
    14. probabilistic programming
    15. type-classes

    Qualifiers

    • Research-article

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)298
    • Downloads (Last 6 weeks)43

    Other Metrics

    Citations

    Cited By

    View all
    • (2024)Probabilistic Programming with Programmable Variational InferenceProceedings of the ACM on Programming Languages10.1145/36564638:PLDI(2123-2147)Online publication date: 20-Jun-2024
    • (2024)Suspension Analysis and Selective Continuation-Passing Style for Universal Probabilistic Programming LanguagesProgramming Languages and Systems10.1007/978-3-031-57267-8_12(302-330)Online publication date: 5-Apr-2024
    • (2023)Effect Handlers for Programmable InferenceProceedings of the 16th ACM SIGPLAN International Haskell Symposium10.1145/3609026.3609729(44-58)Online publication date: 30-Aug-2023
    • (2023)Reflecting on Random GenerationProceedings of the ACM on Programming Languages10.1145/36078427:ICFP(322-355)Online publication date: 31-Aug-2023
    • (2023)Verified Density Compilation for a Probabilistic Programming LanguageProceedings of the ACM on Programming Languages10.1145/35912457:PLDI(615-637)Online publication date: 6-Jun-2023
    • (2022)Modular probabilistic models via algebraic effectsProceedings of the ACM on Programming Languages10.1145/35476356:ICFP(381-410)Online publication date: 31-Aug-2022
    • (2019)Reproducible parallel simulation experiments via pure functional programmingProceedings of the 23rd IEEE/ACM International Symposium on Distributed Simulation and Real Time Applications10.5555/3395101.3395149(268-275)Online publication date: 7-Oct-2019
    • (2019)Reproducible parallel simulation experiments via pure functional programming2019 IEEE/ACM 23rd International Symposium on Distributed Simulation and Real Time Applications (DS-RT)10.1109/DS-RT47707.2019.8958655(1-8)Online publication date: Oct-2019
    • (2019)Weakest Preexpectation Semantics for Bayesian InferenceEngineering Trustworthy Software Systems10.1007/978-3-030-55089-9_3(44-121)Online publication date: 21-Apr-2019

    View Options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Get Access

    Login options

    Full Access

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media