Skip to content

Commit f2e08d5

Browse files
colintwiecki
authored andcommitted
Clean up imports in math.pyt
1 parent ae1d40e commit f2e08d5

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

pymc3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .blocking import *
44
from .distributions import *
5-
from .math import *
5+
from .math import logsumexp, logit, invlogit
66
from .model import *
77
from .stats import *
88
from .sampling import *

pymc3/math.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
from __future__ import division
2-
from theano.tensor import constant, flatten, zeros_like, ones_like, stack, concatenate, sum, prod, lt, gt, le, ge, eq, \
3-
neq, switch, clip, where, and_, or_, abs_
4-
from theano.tensor import exp, log, cos, sin, tan, cosh, sinh, \
5-
tanh, sqr, sqrt, erf, erfinv, dot
6-
from theano.tensor import maximum, minimum, sgn, ceil, floor
7-
from theano.tensor.nlinalg import det, matrix_inverse, \
8-
extract_diag, matrix_dot, trace
9-
from theano.tensor.nnet import sigmoid
2+
import sys
103
import theano
114
import theano.tensor as tt
12-
import sys
5+
from theano.tensor import (constant, flatten, zeros_like, ones_like, stack, concatenate, sum, prod,
6+
lt, gt, le, ge, eq, neq, switch, clip, where, and_, or_, abs_, exp, log,
7+
cos, sin, tan, cosh, sinh, tanh, sqr, sqrt, erf, erfinv, dot, maximum,
8+
minimum, sgn, ceil, floor)
9+
from theano.tensor.nlinalg import det, matrix_inverse, extract_diag, matrix_dot, trace
10+
from theano.tensor.nnet import sigmoid
1311

1412

1513
def logsumexp(x, axis=None):

pymc3/tests/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33
import pymc3 as pm
44
from itertools import product
5-
from theano.tensor import log
5+
import theano.tensor as tt
66

77

88
def simple_model():
@@ -35,7 +35,7 @@ def simple_2model():
3535
p = .4
3636
with Model() as model:
3737
x = pm.Normal('x', mu, tau=tau, testval=.1)
38-
pm.Deterministic('logx', log(x))
38+
pm.Deterministic('logx', tt.log(x))
3939
pm.Bernoulli('y', p)
4040
return model.test_point, model
4141

@@ -48,7 +48,7 @@ def mv_simple():
4848
[1., -0.05, 5.5]])
4949
tau = np.dot(p, p.T)
5050
with pm.Model() as model:
51-
pm.MvNormal('x', pm.constant(mu), tau=pm.constant(tau),
51+
pm.MvNormal('x', tt.constant(mu), tau=tt.constant(tau),
5252
shape=3, testval=np.array([.1, 1., .8]))
5353
H = tau
5454
C = np.linalg.inv(H)
@@ -60,7 +60,7 @@ def mv_simple_discrete():
6060
n = 5
6161
p = np.array([.15, .85])
6262
with pm.Model() as model:
63-
pm.Multinomial('x', n, pm.constant(p), shape=d, testval=np.array([1, 4]))
63+
pm.Multinomial('x', n, tt.constant(p), shape=d, testval=np.array([1, 4]))
6464
mu = n * p
6565
# covariance matrix
6666
C = np.zeros((d, d))

pymc3/tests/test_advi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
import pymc3 as pm
3-
from pymc3 import Model, Normal, DiscreteUniform, Poisson, switch, Exponential
3+
from pymc3 import Model, Normal, DiscreteUniform, Poisson, Exponential
44
from pymc3.theanof import inputvars
55
from pymc3.variational import advi, advi_minibatch, sample_vp
66
from pymc3.variational.advi import _calc_elbo, adagrad_optimizer
@@ -66,7 +66,7 @@ def test_check_discrete(self):
6666
late_rate = Exponential('late_rate', 1)
6767

6868
# Allocate appropriate Poisson rates to years before and after current
69-
rate = switch(switchpoint >= self.year, early_rate, late_rate)
69+
rate = tt.switch(switchpoint >= self.year, early_rate, late_rate)
7070
Poisson('disasters', rate, observed=self.disaster_data)
7171

7272
# This should raise ValueError
@@ -90,7 +90,7 @@ def create_minibatches():
9090
late_rate = Exponential('late_rate', 1)
9191

9292
# Allocate appropriate Poisson rates to years before and after current
93-
rate = switch(switchpoint >= self.year, early_rate, late_rate)
93+
rate = tt.switch(switchpoint >= self.year, early_rate, late_rate)
9494
disasters = Poisson('disasters', rate, observed=disaster_data_t)
9595

9696
with self.assertRaises(ValueError):

pymc3/tests/test_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def build_model(self):
4141

4242
with pm.Model() as model:
4343
effects = pm.Normal('effects', mu=0, tau=100. ** -2, shape=len(P.columns))
44-
p = pm.sigmoid(pm.dot(np.array(P), effects))
44+
p = tt.nnet.sigmoid(tt.dot(np.array(P), effects))
4545
pm.Bernoulli('s', p, observed=np.array(data.switch))
4646
return model
4747

@@ -154,7 +154,7 @@ def build_disaster_model(masked=False):
154154
# Allocate appropriate Poisson rates to years before and after current
155155
# switchpoint location
156156
idx = np.arange(years)
157-
rate = pm.switch(switchpoint >= idx, early_mean, late_mean)
157+
rate = tt.switch(switchpoint >= idx, early_mean, late_mean)
158158
# Data likelihood
159159
pm.Poisson('disasters', rate, observed=disasters_data)
160160
return model

0 commit comments

Comments
 (0)