I'd been doing my own convolutions of distributions for some calculations, decided to use built-ins.


p5 = TransformedDistribution[py + pz, 
  {Distributed[py, BinomialDistribution[7, .2]], 
   Distributed[pz, BinomialDistribution[7, .3]]}]

PDF[p5, 5]

getting the PDF takes an inordinate amount of time (as in 30+ seconds on the laptop I'm on at the moment, faster on my real machines of course, but still slow.)

I'm guessing it is using DiscreteConvolve under the covers, which is itself inordinately slow IMO, but I'm pondering if I'm missing something obvious in the use of TransformedDistribution.

Any ideas (or explanations) for the slowness appreciated.

  • 1
    $\begingroup$ On my 64-bit Windows 7 machine this takes about .7 seconds for version 8.0.4 and 9.0.1. What system are you using? $\endgroup$ – Andy Ross Mar 16 '13 at 22:42
  • $\begingroup$ PDF[p5, 5] takes 2.4 seconds on my rather elderly iMac. $\endgroup$ – m_goldberg Mar 16 '13 at 22:46
  • 1
    $\begingroup$ @Andy & m_goldberg: There was a typo in original example, argument to PDF I used was 5, rather than 2. I am on 9.0.1, but as I said timing was on a crippled laptop, it is a few seconds on my normal machines, but that still seems awfully low. I'm getting the feeling though that this is just a slow operation, and for real work I'm better off doing explicit optimized convolutions of the individual PDFs. Btw, thanks for cleaning up post if one of you did it... $\endgroup$ – HeyCarNut Mar 16 '13 at 22:50
  • $\begingroup$ My timings didn't change by using 5 instead of 2. That said, I'm on a machine with 32GB memory with a fairly fast (4.3GHz) cpu. $\endgroup$ – Andy Ross Mar 16 '13 at 22:56
  • $\begingroup$ Read my comment again. I tested with PDF[p5, 5]. $\endgroup$ – m_goldberg Mar 16 '13 at 23:06

Looking under the covers it creates (as expected) a piecewise function by sum for tuples of each possible combination of m summing to n for each n in PDF[dist,n], so it just needs horsepower.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.