I have created a class which represents a statistical simulation. One aspect of that is a distribution of p-values, and the class contains methods characterizing that distribution:
class Simulation:
...
def pdf_p(self, p):
...
def cdf_p(self, p):
...
def ppf_p(self, P):
...
def rvs_p(self, size):
...
I would now like to expose that distribution also as a scipy.stats
-style distribution object. To do so, the __init__
method of my class contains a statement
self.p = PValueDist(self.pdf_p, self.cdf_p, self.ppf_p, self.rvs_p)
where the class PValueDist
is defined as
from scipy.stats import rv_continuous
class PValueDist (rv_continuous):
def __init__(self, pdf, cdf, ppf, rvs):
self._pdf = pdf
self._cdf = cdf
self._ppf = ppf
self._rvs = rvs
super().__init__(self)
This seems to work, but I'm wondering whether it is the right or canonical way to do it?
Of course I could also make Simulation
a subclass of rv_continuous
and rename my methods. However, the simulation comprises several different distributions, and identifying the simulation with one of them doesn't seem semantically correct.