7 years ago
Showing posts with label scala. Show all posts
Showing posts with label scala. Show all posts
Implementing Probabilistic Modeling Using Monads in F# and Scala
For my induction into Scala, I wanted to translate the probabilistic monad of Chapter 9 of Expert F# (Introducing Language-Oriented Programming). The idea, based on the paper Stochastic Lambda Calculus and Monads of Probability Distributions, is to define a probability monad to compute over distributions of a domain instead of the domain itself. We limit ourselves to distributions over discrete domains characterized by three functions:
Contrast the F# implementation with the Scala implementation. The Scala implementation closely follows the F# one, except for one major frustration: the type inference is not as powerful in Scala, as all function arguments must be declared.
Perhaps, I am missing a few tricks because I am new to Scala. If anyone has any suggestions for improving the Scala implementation, please share.
- sampling
- support
(i.e. a set of values where all elements outside the set have zero chance of being sampled) - expectation of a function over the distribution
(e.g. the probability of selecting elementAby evaluating the functionf(x) = 1ifxequalsAand0otherwise)
Contrast the F# implementation with the Scala implementation. The Scala implementation closely follows the F# one, except for one major frustration: the type inference is not as powerful in Scala, as all function arguments must be declared.
Perhaps, I am missing a few tricks because I am new to Scala. If anyone has any suggestions for improving the Scala implementation, please share.
Cross-posted to the Scala wiki.
Labels:
code,
fsharp,
monads,
probability,
programming,
programming-languages,
scala
Subscribe to:
Posts (Atom)
My Webabouts
-
-
-
Languages As Libraries14 years ago
My Blog List
Blog Archive
Labels
- code (5)
- programming-languages (5)
- fsharp (4)
- logic (2)
- monads (2)
- probability (2)
- programming (2)
- scala (2)
- types (2)
- ai (1)
- cs (1)
- game (1)
- haskell (1)
- lambda-calculus (1)
- python (1)
- tips (1)
