In [2]:
import pymc3 as mc
import numpy as np
import matplotlib.pyplot as plt

In [7]:
import numpy as np
import pymc3 as pm

with pm.Model() as model:
    dist = pm.Mixture('dist', np.array([0.25, 0.75]),
                      [pm.Uniform.dist(-0.15, -0.05), pm.Uniform.dist(0., 0.05)])

N = 40000
samples = dist.random(size=N)

In [10]:
plt.hist(samples, 100, density=True);



In [19]:
with pm.Model():
        mu = pm.Normal('mu',0,1)
        normal_dist = pm.Normal.dist(mu, 1)
        pm.DensityDist('density_dist', normal_dist.logp, )
        trace = pm.sample(10000)


Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [density_dist, mu]
100%|██████████| 10500/10500 [00:08<00:00, 1238.51it/s]

In [20]:
pm.traceplot(trace, combined=True)


Out[20]:
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x11783dc18>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x117811a20>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x117233390>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x1177a3eb8>]],
      dtype=object)

In [23]:
with pm.Model():
#     mu = pm.Normal('mu',0,1)
    norm = scipy.stats.norm()
#     normal_dist = pm.Normal.dist(mu, 1)
    pm.DensityDist('density_dist', norm.logpdf, )
    trace = pm.sample(10000)
pm.traceplot(trace, combined=True)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-23-c16b430f6f20> in <module>()
      3     norm = scipy.stats.norm()
      4 #     normal_dist = pm.Normal.dist(mu, 1)
----> 5     pm.DensityDist('density_dist', norm.logpdf, )
      6     trace = pm.sample(10000)
      7 pm.traceplot(trace, combined=True)

~/miniconda3/lib/python3.6/site-packages/pymc3/distributions/distribution.py in __new__(cls, name, *args, **kwargs)
     35             total_size = kwargs.pop('total_size', None)
     36             dist = cls.dist(*args, **kwargs)
---> 37             return model.Var(name, dist, data, total_size)
     38         else:
     39             raise TypeError("Name needs to be a string but got: {}".format(name))

~/miniconda3/lib/python3.6/site-packages/pymc3/model.py in Var(self, name, dist, data, total_size)
    800                 with self:
    801                     var = FreeRV(name=name, distribution=dist,
--> 802                                  total_size=total_size, model=self)
    803                 self.free_RVs.append(var)
    804             else:

~/miniconda3/lib/python3.6/site-packages/pymc3/model.py in __init__(self, type, owner, index, name, distribution, total_size, model)
   1179             self.tag.test_value = np.ones(
   1180                 distribution.shape, distribution.dtype) * distribution.default()
-> 1181             self.logp_elemwiset = distribution.logp(self)
   1182             # The logp might need scaling in minibatches.
   1183             # This is done in `Factor`.

~/miniconda3/lib/python3.6/site-packages/scipy/stats/_distn_infrastructure.py in logpdf(self, x)
    451 
    452     def logpdf(self, x):
--> 453         return self.dist.logpdf(x, *self.args, **self.kwds)
    454 
    455     def cdf(self, x):

~/miniconda3/lib/python3.6/site-packages/scipy/stats/_distn_infrastructure.py in logpdf(self, x, *args, **kwds)
   1694         x = np.asarray((x - loc)/scale, dtype=dtyp)
   1695         cond0 = self._argcheck(*args) & (scale > 0)
-> 1696         cond1 = self._support_mask(x) & (scale > 0)
   1697         cond = cond0 & cond1
   1698         output = empty(shape(cond), dtyp)

~/miniconda3/lib/python3.6/site-packages/scipy/stats/_distn_infrastructure.py in _support_mask(self, x)
    874 
    875     def _support_mask(self, x):
--> 876         return (self.a <= x) & (x <= self.b)
    877 
    878     def _open_support_mask(self, x):

~/miniconda3/lib/python3.6/site-packages/theano/tensor/var.py in __bool__(self)
     89         else:
     90             raise TypeError(
---> 91                 "Variables do not support boolean operations."
     92             )
     93 

TypeError: Variables do not support boolean operations.

In [ ]:


In [ ]: