From 3cf54506689f4e2824bd6cd11ed4ce27a5259a51 Mon Sep 17 00:00:00 2001 From: Chris Fonnesbeck Date: Thu, 6 Oct 2016 23:26:55 -0500 Subject: [PATCH 1/3] Added epsilon to numerator and denominator of Interval.forward --- pymc3/distributions/transforms.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pymc3/distributions/transforms.py b/pymc3/distributions/transforms.py index 00b95b6582..ad2a063d5c 100644 --- a/pymc3/distributions/transforms.py +++ b/pymc3/distributions/transforms.py @@ -109,18 +109,19 @@ class Interval(ElemwiseTransform): name = "interval" - def __init__(self, a, b): + def __init__(self, a, b, eps=1e-6): self.a = a self.b = b + self.eps = eps def backward(self, x): a, b = self.a, self.b - r = (b - a) * tt.exp(x) / (1 + tt.exp(x)) + a + r = (b - a) / (1 + tt.exp(-x)) + a return r def forward(self, x): - a, b = self.a, self.b - r = tt.log((x - a) / (b - x)) + a, b, e = self.a, self.b, self.eps + r = tt.log(tt.maximum((x - a) / tt.maximum(b - x, e), e)) return r interval = Interval From 28ad1273e22d04c7ba6c2d4e60c82dea8db66fb0 Mon Sep 17 00:00:00 2001 From: Chris Fonnesbeck Date: Fri, 7 Oct 2016 08:45:56 -0500 Subject: [PATCH 2/3] Removed redundant bounds check on normal --- pymc3/distributions/continuous.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pymc3/distributions/continuous.py b/pymc3/distributions/continuous.py index bf6ce60ab5..0294fb2782 100644 --- a/pymc3/distributions/continuous.py +++ b/pymc3/distributions/continuous.py @@ -217,10 +217,9 @@ def random(self, point=None, size=None, repeat=None): def logp(self, value): tau = self.tau - sd = self.sd mu = self.mu return bound((-tau * (value - mu)**2 + tt.log(tau / np.pi / 2.)) / 2., - tau > 0, sd > 0) + tau > 0) class HalfNormal(PositiveContinuous): From 8ff7d64d1c02573726916f950234a8824d331f6d Mon Sep 17 00:00:00 2001 From: Chris Fonnesbeck Date: Fri, 7 Oct 2016 10:39:41 -0500 Subject: [PATCH 3/3] Narrowed bounds of precision in adjust_precision --- pymc3/tuning/scaling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymc3/tuning/scaling.py b/pymc3/tuning/scaling.py index 654b8f5aca..e8b124ced2 100644 --- a/pymc3/tuning/scaling.py +++ b/pymc3/tuning/scaling.py @@ -126,7 +126,7 @@ def adjust_scaling(s): def adjust_precision(tau): mag = sqrt(abs(tau)) - bounded = bound(log(mag), log(1e-10), log(1e10)) + bounded = bound(log(mag), log(0.1), log(10)) return exp(bounded)**2