To implement custom distribution in pymc, pm.CustomDist
can be used by only supplying logp
, but doing so won’t allow for sample_posterior_predictive
. So it might be easier to implement the distribution properly
- So far, every distribution come with
RandomVariable
sub-class. I get that this define random sampling, which can be mapped toscipy.stats
implementation ofrvs
. - This random variable is then used in the main class (sub-class of
Continuous
,PositiveContinuous
, …) via static variable namedrv_op
. I guess this variable will do the magic behind the scene
There are 4
recurring methods I saw in the code
-
dist
classmethod is also simple to implement, but I don’t know the importance of this function -
moment
method - I guess this is where the sampler is going to start sampling? Most distribution implement this using distribution mean, some mode if mean doesn’t exists. AndHalfStudentT
just usesigma
out right. But I am not sure if this method is required -
logp
- Definelogp
, This is required inCustomDist
, so I also think it is required here -
logcdf
- Most distribution have this method implement, but distribution likeTruncatedNormal
didn’t havelogcdf
. So this is not a requirement?
So I want to make sure what method is required, and what method is used to speed-up (and speed up what exactly). Thanks