@@ -66,7 +66,7 @@ def discrete_histogram(data: ArrayLike, min_count=None) -> Dict[str, ArrayLike]:
66
66
return dict (mid = mid , count = count )
67
67
68
68
69
- def histogram_approximation (name , dist , * , observed : ArrayLike , ** h_kwargs ):
69
+ def histogram_approximation (name , dist , * , observed , ** h_kwargs ):
70
70
"""Approximate a distribution with a histogram potential.
71
71
72
72
Parameters
@@ -76,7 +76,8 @@ def histogram_approximation(name, dist, *, observed: ArrayLike, **h_kwargs):
76
76
dist : aesara.tensor.var.TensorVariable
77
77
The output of pm.Distribution.dist()
78
78
observed : ArrayLike
79
- Observed value to construct a histogram. Histogram is computed over 0th axis. Dask is supported.
79
+ Observed value to construct a histogram. Histogram is computed over 0th axis.
80
+ Dask is supported.
80
81
81
82
Returns
82
83
-------
@@ -86,34 +87,37 @@ def histogram_approximation(name, dist, *, observed: ArrayLike, **h_kwargs):
86
87
Examples
87
88
--------
88
89
Discrete variables are reduced to unique repetitions (up to min_count)
90
+
89
91
>>> import pymc as pm
90
92
>>> import pymc_experimental as pmx
91
93
>>> production = np.random.poisson([1, 2, 5], size=(1000, 3))
92
94
>>> with pm.Model(coords=dict(plant=range(3))):
93
95
... lam = pm.Exponential("lam", 1.0, dims="plant")
94
96
... pot = pmx.distributions.histogram_approximation(
95
- ... "histogram_potential ", pm.Poisson.dist(lam), observed=production, min_count=2
97
+ ... "pot ", pm.Poisson.dist(lam), observed=production, min_count=2
96
98
... )
97
99
98
100
Continuous variables are discretized into n_quantiles
101
+
99
102
>>> measurements = np.random.normal([1, 2, 3], [0.1, 0.4, 0.2], size=(10000, 3))
100
103
>>> with pm.Model(coords=dict(tests=range(3))):
101
104
... m = pm.Normal("m", dims="tests")
102
105
... s = pm.LogNormal("s", dims="tests")
103
106
... pot = pmx.distributions.histogram_approximation(
104
- ... "histogram_potential ", pm.Normal.dist(m, s),
107
+ ... "pot ", pm.Normal.dist(m, s),
105
108
... observed=measurements, n_quantiles=50
106
109
... )
107
110
108
111
For special cases like Zero Inflation in Continuous variables there is a flag.
109
112
The flag adds a separate bin for zeros
113
+
110
114
>>> measurements = abs(measurements)
111
115
>>> measurements[100:] = 0
112
116
>>> with pm.Model(coords=dict(tests=range(3))):
113
117
... m = pm.Normal("m", dims="tests")
114
118
... s = pm.LogNormal("s", dims="tests")
115
119
... pot = pmx.distributions.histogram_approximation(
116
- ... "histogram_potential ", pm.Normal.dist(m, s),
120
+ ... "pot ", pm.Normal.dist(m, s),
117
121
... observed=measurements, n_quantiles=50, zero_inflation=True
118
122
... )
119
123
"""
0 commit comments