Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pymc3/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ def random(self, point=None, size=None, repeat=None):
size=size)

def logp(self, value):
tau = self.tau
sd = self.sd
tau = self.tau
mu = self.mu
return bound((-tau * (value - mu)**2 + tt.log(tau / np.pi / 2.)) / 2.,
tau > 0, sd > 0)
sd > 0)


class HalfNormal(PositiveContinuous):
Expand Down
9 changes: 5 additions & 4 deletions pymc3/distributions/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions pymc3/tuning/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,28 @@ def find_hessian_diag(point, vars=None, model=None):
return H(Point(point, model=model))


def guess_scaling(point, vars=None, model=None):
def guess_scaling(point, vars=None, model=None, scaling_bound=1e-3):
model = modelcontext(model)
try:
h = find_hessian_diag(point, vars, model=model)
except NotImplementedError:
h = fixed_hessian(point, vars, model=model)
return adjust_scaling(h)
return adjust_scaling(h, scaling_bound)


def adjust_scaling(s):
def adjust_scaling(s, scaling_bound):
if s.ndim < 2:
return adjust_precision(s)
return adjust_precision(s, scaling_bound)
else:
val, vec = np.linalg.eigh(s)
val = adjust_precision(val)
val = adjust_precision(val, scaling_bound)
return eig_recompose(val, vec)


def adjust_precision(tau):
def adjust_precision(tau, scaling_bound=1e-3):
mag = sqrt(abs(tau))

bounded = bound(log(mag), log(1e-10), log(1e10))
bounded = bound(log(mag), log(1/scaling_bound), log(scaling_bound))
return exp(bounded)**2


Expand Down