This question is part of the theory / part of the implementation. Estimated Assumption: I am using the monad-bayes library to represent probability distributions as monads. The distribution p (a | b) can be represented as a function MonadDist m => b -> m a.
Suppose I have a conditional probability distribution s :: MonadDist m => [Char] -> m Char. I want to get a new probability distribution sUnrolled :: [Char] -> m [Char]defined mathematically (I think) as:
sUnrolled(chars|st) =
| len(chars)==1 -> s st
| otherwise -> s(chars[-1]|st++chars[:-1]) * sUnrolled(chars[:-1]|st)
Intuitively, this is the distribution that you will get by taking st :: [Char], taking a sample of char cfrom s st, loading st++[c]back into sand so on. I believe that iterateM smore or less what I want. To make this a distribution that we could really take a look at, let's say that if we hit a certain character, we will stop. Then it works iterateMaybeM.
Theory of the Question. For various reasons, it would be very useful if I could express this distribution in more general terms, for example, in a way that is generalized to the stochastic construction of a tree taking into account the stochastic coalgebra. It seems that I have some kind of anamorphism here (I understand that the mathematical definition looks like a catamorphism, but in the code I want to build lines, not deconstruct them in probability), but I can not completely parse the details, not at least due to the presence of a probabilistic monad.
Practical question: It would also be useful to implement this in Haskell in a way that used a recursion schema library, for example.
source
share