Skip to content

Commit eba2344

Browse files
committed
dont wrap np.pi
1 parent 1d69cff commit eba2344

2 files changed

Lines changed: 6 additions & 18 deletions

File tree

pymc/dims/distributions/custom.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ def logitnormal_dist(mu, sigma):
104104
105105
def normal_logp(value, mu, sigma):
106106
v = value.values # strip dims for tensor ops
107-
return pt.sum(
108-
pt.pow(v - mu, 2) / (2 * sigma**2) + pt.log(sigma * pt.sqrt(2 * pt.constant(np.pi)))
109-
)
107+
return pt.sum(pt.pow(v - mu, 2) / (2 * sigma**2) + pt.log(sigma * pt.sqrt(2 * np.pi)))
110108
111109
112110
pmd.CustomDist("y", mu, sigma, logp=normal_logp, observed=y, dims="city")

tests/dims/distributions/test_custom.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ def test_logp_basic(self):
7373

7474
def normal_logp(value, mu, sigma):
7575
v = value.values
76-
return pt.sum(
77-
-0.5 * ((v - mu) / sigma) ** 2 - pt.log(sigma * pt.sqrt(2 * pt.constant(np.pi)))
78-
)
76+
return pt.sum(-0.5 * ((v - mu) / sigma) ** 2 - pt.log(sigma * pt.sqrt(2 * np.pi)))
7977

8078
coords = {"city": range(5)}
8179
rng = np.random.default_rng(42)
@@ -101,9 +99,7 @@ def test_random_logp(self):
10199

102100
def normal_logp(value, mu, sigma):
103101
v = value.values
104-
return pt.sum(
105-
-0.5 * ((v - mu) / sigma) ** 2 - pt.log(sigma * pt.sqrt(2 * pt.constant(np.pi)))
106-
)
102+
return pt.sum(-0.5 * ((v - mu) / sigma) ** 2 - pt.log(sigma * pt.sqrt(2 * np.pi)))
107103

108104
def normal_random(mu, sigma, rng=None, size=None):
109105
return rng.normal(loc=mu, scale=sigma, size=size)
@@ -135,9 +131,7 @@ def test_logcdf(self):
135131

136132
def normal_logp(value, mu, sigma):
137133
v = value.values
138-
return pt.sum(
139-
-0.5 * ((v - mu) / sigma) ** 2 - pt.log(sigma * pt.sqrt(2 * pt.constant(np.pi)))
140-
)
134+
return pt.sum(-0.5 * ((v - mu) / sigma) ** 2 - pt.log(sigma * pt.sqrt(2 * np.pi)))
141135

142136
def normal_logcdf(value, mu, sigma):
143137
v = value.values
@@ -169,9 +163,7 @@ def test_mu_as_model_var(self):
169163

170164
def normal_logp(value, mu, sigma):
171165
v = value.values
172-
return pt.sum(
173-
-0.5 * ((v - mu) / sigma) ** 2 - pt.log(sigma * pt.sqrt(2 * pt.constant(np.pi)))
174-
)
166+
return pt.sum(-0.5 * ((v - mu) / sigma) ** 2 - pt.log(sigma * pt.sqrt(2 * np.pi)))
175167

176168
coords = {"city": range(5)}
177169
rng = np.random.default_rng(42)
@@ -197,9 +189,7 @@ def test_support_point(self):
197189

198190
def normal_logp(value, mu, sigma):
199191
v = value.values
200-
return pt.sum(
201-
-0.5 * ((v - mu) / sigma) ** 2 - pt.log(sigma * pt.sqrt(2 * pt.constant(np.pi)))
202-
)
192+
return pt.sum(-0.5 * ((v - mu) / sigma) ** 2 - pt.log(sigma * pt.sqrt(2 * np.pi)))
203193

204194
def custom_support_point(rv, size, mu, sigma):
205195
return pt.full_like(rv, mu)

0 commit comments

Comments
 (0)