[Haskell-cafe] Uncertainty analysis library?

Tom Nielsen tanielsen at gmail.com
Mon Mar 21 22:41:37 CET 2011


> The danger here is, of course, the side-condition of independence, which can
> make inhabitants of that type very difficult to reason about. e.g. x + x and
> 2*x in that world are very different.

Yes. I was surprised (maybe i shouldn't have been):

sampler = do
  x <- gauss 0.0 1.0
  y <- gauss 0.0 1.0
  return $ (2*x, x+y)

main = do
  xys <- take 100000 `fmap` runSamplerIO sampler
  print $ runStat
     (both (before varF fst) (before varF snd)) $
                   xys

=> (3.9988971177326498,2.0112123117664975)
that is,  (variance of 2*x, variance of x+y)

The problem is that when you say x+x you don't really mean it; you
mean something like liftM2(+) xdist xdist in a probability monad. Had
I changed "x+y" to "x+x", I would obviously have gotten identical
variances. So maybe referential transparency is not lost after all.

Tom



More information about the Haskell-Cafe mailing list