haskell-numerics / random-fu

A suite of Haskell libraries for representing, manipulating, and sampling random variables
42 stars 21 forks source link

Add instances for tuples #12

Open neongreen opened 11 years ago

neongreen commented 11 years ago

What is the rationale behind not including a simple instance for tuples?

instance (Distribution StdUniform a, Distribution StdUniform b) => 
         Distribution StdUniform (a, b) where
  rvar _ = (,) <$> stdUniform <*> stdUniform

Among other reasons, it is useful when the need to generate more than one random variable arises:

((var1, var2, var3), gen') = sampleState stdUniform gen
mokus0 commented 11 years ago

I don't think there's any particular reason for it; I just haven't had the need so it didn't occur to me. I don't know how much time I have to dig into this at the moment, but if you have a patch I'd be happy to apply it.

neongreen commented 11 years ago

Sure! Just thought there could be something about it that I didn’t understand. I’ll submit a pull request in a day or two.

neongreen commented 11 years ago

However, I wasn’t able to write a generic CDF instance for a tuple. Is it possible to do without having something like prob :: Distribution d t => d t -> t -> Double, which would return the probability of a given element being selected? If no, should I try and add a Probability typeclass?

mokus0 commented 11 years ago

I don't think a meaningful one is really possible under the current definition of the CDF interface since it is explicitly not a joint CDF. I don't think I'd worry too much about that. And I'm not exactly against introducing a Probability concept, but I think it's hard to define in a way that applies equally well to discrete, continuous and multidimensional variables. Statistical calculations of that nature are also already pretty well-handled by the statistics package, which I think complements this one pretty nicely.