Skip to content

Commit

Permalink
Improve performance of transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
aseyboldt authored and twiecki committed Mar 13, 2017
1 parent f4d9a7c commit 532b1aa
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pymc3/distributions/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def backward(self, x):
def forward(self, x):
return tt.log(x)

def jacobian_det(self, x):
return x

log = Log()


Expand All @@ -109,20 +112,22 @@ class Interval(ElemwiseTransform):

name = "interval"

def __init__(self, a, b, eps=1e-6):
def __init__(self, a, b):
self.a = a
self.b = b
self.eps = eps

def backward(self, x):
a, b = self.a, self.b
r = (b - a) / (1 + tt.exp(-x)) + a
r = (b - a) * tt.nnet.sigmoid(x) + a
return r

def forward(self, 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
a, b = self.a, self.b
return tt.log(x - a) - tt.log(b - x)

def jacobian_det(self, x):
s = tt.nnet.softplus(-x)
return tt.log(self.b - self.a) - 2 * s - x

interval = Interval

Expand All @@ -145,6 +150,9 @@ def forward(self, x):
r = tt.log(x - a)
return r

def jacobian_det(self, x):
return x

lowerbound = LowerBound


Expand All @@ -166,6 +174,9 @@ def forward(self, x):
r = tt.log(b - x)
return r

def jacobian_det(self, x):
return x

upperbound = UpperBound


Expand Down

0 comments on commit 532b1aa

Please sign in to comment.