Chapter 6. Using Scala and Figaro collections to build up models
This chapter covers
- How to use collections to organize probabilistic models
- The difference between Scala collections and Figaro collections, the roles of each, and how to use them together
- Common modeling patterns that can be expressed using collections, including hierarchical Bayesian modeling, modeling situations with an unknown number of objects, and models defined over a continuous region
In the preceding two chapters, you’ve gained a solid foundation in probabilistic modeling. This chapter focuses on the programming aspect of probabilistic programming and shows you ways that the features of a programming language can help you build probabilistic models. In particular, you’re going to focus on collections.
Collections are one of the most useful features of high-level programming languages, because they let you organize many items of the same type and treat them as a group. For example, if you’re working with lots of integers, you can put them in an array and then write a loop to go through all entries in the array, multiply them by 2, and add them. Or, in functional programming terms, you can write a map function to multiply every entry in the array by 2 and a fold function to perform the addition. The same holds for probabilistic programming; if you have many variables of the same type, you can put them in a collection and operate on them with functions such as map and fold.