Bug introduced in 10.4.1 or earlier and somewhat fixed in 12.0.0
This question maybe related to (95436) but neither its answer nor the documentation for ProbabilityDistribution
state whether we may build a discrete probability distribution using a step size $dx$ different from $1$.
Minimum Working Example
Let's say that we want to build a discrete probability distribution (say a prior distribution) for some random variable $X$ which can only take values in the range $[0,1]$. We do know that $Pr(X=\frac{1}{12}) = 0.25$, $Pr(X=\frac{1}{6})=0.5$, $Pr(X=\frac{1}{4})=0.25$ and the probability is zero for all other values.
From reading the documentation one might assume that we can use Piecewise
within ProbabilityDistribution
using a discrete range specification with $dx = \frac{1}{12}$ to build a discrete probability distribution matching our prior information:
priorDistribution = ProbabilityDistribution[
Piecewise[
{
{ 0.25, x == 1/12 },
{ 0.50, x == 1/6 },
{ 0.25, x == 1/4 }
}
],
{ x, 0, 1, 1/12 }
]
But this surprisingly will not work in Version 11.0 :
PDF[priorDistribution, 1/4]
PDF[ProbabilityDistribution[[Piecewise] 0.25 [FormalX]==1/12 0.5 [FormalX]==1/6 0.25 [FormalX]==1/4 0 True ,{[FormalX],0,1,1/12}],0.25]
RandomVariate[ priorDistribution, 10 ]
RandomVariate::noimp: Sampling from ProbabilityDistribution[[Piecewise] 0.25 [FormalX]==1/12 0.5 [FormalX]==1/6 0.25 [FormalX]==1/4 0 True ,{[FormalX],0,1,1/12}] is not implemented.
Am I missing something? It seems that ProbabilityDistribution
only accepts $dx = 1$ (I tried $dx = 2$ for a different range and it also did not work).
Update (Version 12.0.0):
While the above given example still does not work, the limitation with regard to dx has been fixed (at least with regard to dx > 1):
dist = ProbabilityDistribution[
0.25 Boole[ x == 4]
+ 0.50 Boole[ x == 6]
+ 0.25 Boole[ x == 12 ]
,
{ x, 0, 12, 2}
]
PDF[ dist, 4 ]
0.25
Update as of Version 12.3 (and possibly earlier?) and later
The documentation for ProbabilityDistribution
now shows, that for discrete distributions, $dx$ has to be $1$. In the section Possible Issues the documentation states that TransformedDistribution
can be used to build discrete distributions with noninteger support and it in fact uses my very example. ;-)
dist = ProbabilityDistribution[1/6, {x, 1, 11, 2}]
, it appears that it works with calculations likeMean
orVariance
, but not withRandomVariate
. It doesn't work with your example at all. $\endgroup$Piecewise
has been confirmed by WRI today. I just added thebugs
tag and header accordingly. $\endgroup$