Skip to content

Commit

Permalink
Clean up imports in math.pyt
Browse files Browse the repository at this point in the history
  • Loading branch information
colin authored and twiecki committed Oct 1, 2016
1 parent ae1d40e commit f2e08d5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pymc3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from .blocking import *
from .distributions import *
from .math import *
from .math import logsumexp, logit, invlogit
from .model import *
from .stats import *
from .sampling import *
Expand Down
16 changes: 7 additions & 9 deletions pymc3/math.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from __future__ import division
from theano.tensor import constant, flatten, zeros_like, ones_like, stack, concatenate, sum, prod, lt, gt, le, ge, eq, \
neq, switch, clip, where, and_, or_, abs_
from theano.tensor import exp, log, cos, sin, tan, cosh, sinh, \
tanh, sqr, sqrt, erf, erfinv, dot
from theano.tensor import maximum, minimum, sgn, ceil, floor
from theano.tensor.nlinalg import det, matrix_inverse, \
extract_diag, matrix_dot, trace
from theano.tensor.nnet import sigmoid
import sys
import theano
import theano.tensor as tt
import sys
from theano.tensor import (constant, flatten, zeros_like, ones_like, stack, concatenate, sum, prod,
lt, gt, le, ge, eq, neq, switch, clip, where, and_, or_, abs_, exp, log,
cos, sin, tan, cosh, sinh, tanh, sqr, sqrt, erf, erfinv, dot, maximum,
minimum, sgn, ceil, floor)
from theano.tensor.nlinalg import det, matrix_inverse, extract_diag, matrix_dot, trace
from theano.tensor.nnet import sigmoid


def logsumexp(x, axis=None):
Expand Down
8 changes: 4 additions & 4 deletions pymc3/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import pymc3 as pm
from itertools import product
from theano.tensor import log
import theano.tensor as tt


def simple_model():
Expand Down Expand Up @@ -35,7 +35,7 @@ def simple_2model():
p = .4
with Model() as model:
x = pm.Normal('x', mu, tau=tau, testval=.1)
pm.Deterministic('logx', log(x))
pm.Deterministic('logx', tt.log(x))
pm.Bernoulli('y', p)
return model.test_point, model

Expand All @@ -48,7 +48,7 @@ def mv_simple():
[1., -0.05, 5.5]])
tau = np.dot(p, p.T)
with pm.Model() as model:
pm.MvNormal('x', pm.constant(mu), tau=pm.constant(tau),
pm.MvNormal('x', tt.constant(mu), tau=tt.constant(tau),
shape=3, testval=np.array([.1, 1., .8]))
H = tau
C = np.linalg.inv(H)
Expand All @@ -60,7 +60,7 @@ def mv_simple_discrete():
n = 5
p = np.array([.15, .85])
with pm.Model() as model:
pm.Multinomial('x', n, pm.constant(p), shape=d, testval=np.array([1, 4]))
pm.Multinomial('x', n, tt.constant(p), shape=d, testval=np.array([1, 4]))
mu = n * p
# covariance matrix
C = np.zeros((d, d))
Expand Down
6 changes: 3 additions & 3 deletions pymc3/tests/test_advi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import pymc3 as pm
from pymc3 import Model, Normal, DiscreteUniform, Poisson, switch, Exponential
from pymc3 import Model, Normal, DiscreteUniform, Poisson, Exponential
from pymc3.theanof import inputvars
from pymc3.variational import advi, advi_minibatch, sample_vp
from pymc3.variational.advi import _calc_elbo, adagrad_optimizer
Expand Down Expand Up @@ -66,7 +66,7 @@ def test_check_discrete(self):
late_rate = Exponential('late_rate', 1)

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

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

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

with self.assertRaises(ValueError):
Expand Down
4 changes: 2 additions & 2 deletions pymc3/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def build_model(self):

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

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

0 comments on commit f2e08d5

Please sign in to comment.