A composite distribution consisting of some math operator between one or two other Distribution objects.
For example:
g = distl.gaussian(10, 2)
u = distl.gaussian(1, 5)
c = g * u
print(c)
or:
import numpy as np
g = distl.gaussian(0, 1)
sin_g = np.sin(g)
print(sin_g)
Currently supported operators include:
- multiplication, division, addition, subtraction
- np.sin, np.cos, np.tan (but not math.sin, etc)
- bitwise and (&), bitwise or (|)
When doing math between a distribution and a float or integer, that float/int will be treated as a Delta distribution. In some simple cases, the applicable distribution type will be returned, but in other cases, a Composite distribution will be returned. For example, multiplying a Uniform or Gaussian distribution by a float will return another Uniform or Gaussian distribution, respectively.
Limitations and treatment "under-the-hood":
-
&: the pdfs of the two underlying distributions are sampled over their 99.99% intervals and multiplied to create a new pdf. A spline is then fit to the pdf and integrated to create the cdf (which is inverted to create the ppf function). Each of these are then linearly interpolated to create the underlying scipy.stats object. This object is then used for sampling as well as accessing the Composite.pdf, Composite.cdf, Composite.ppf, etc. For this reason, the and operator does not support retaining covariances at all.
-
|: the pdfs and cdfs of the two underlying distributions are sampled over their 99.9% intervals and added to create the new pdfs and cdfs, respectively (and the cdf inverted to create the ppf function). Each of these are then linearly interpolated to create the underlying scipy.stats object. This object is then used for any call to the underlying call EXCEPT for sampling. Sampling is handled by randomly choosing which child distribution to sample from and then sampling from that distribution. Or operators are therefore able to retain covariances for Composite.sample, but not for any calls to Composite.pdf, Composite.cdf, or Composite.ppf.
-
all others: sampling is handled by sampling the underyling children and therefore can retain covariances. The pdfs, cdfs, and ppfs are created by taking 1 million samples, converting to a Histogram with 100 bins, and using the underlying scipy.stats.rv_histogram, thereby losing all covariances. Note if any of the underlying children are Function distributions, then the minimum Function.hist_samples will be used when converting to a Histogram.