Closed monkpit closed 8 years ago
That's interesting. I'll look into it. Thanks for reporting.
I notice that this only happens when you create a model with no variables, which we should probably forbid. For some reason there is an integer attribute that results, which causes the issue.
I initially tried this with a model that was not empty (while following along with Bayesian Methods for Hackers) and got the same result, the empty model was the simplest way to recreate the issue.
import pymc as pm
count_data = np.loadtxt("data\txtdata.csv")
alpha = 1.0 / count_data.mean()
lambda_1 = pm.Exponential("lambda_1", alpha)
lambda_2 = pm.Exponential("lambda_2", alpha)
tau = pm.DiscreteUniform("tau", lower=0, upper=n_count_data)
@pm.deterministic
def lambda_(tau=tau, lambda_1=lambda_1, lambda_2=lambda_2):
out = np.zeros(n_count_data)
out[:tau] = lambda_1
out[tau:] = lambda_2
return out
observation = pm.Poisson("obs", lambda_, value=count_data, observed=True)
model = pm.Model([observation, lambda_1, lambda_2, tau])
mcmc = pm.MCMC(model)
mcmc.sample(40000, 10000, 1)
dir(mcmc)
This gets me:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-127-0fc7ab4e9e82> in <module>()
----> 1 dir(mcmc)
TypeError: unorderable types: int() < str()
Ah, thanks. We don't recommend instantiating a Model
directly; it is intended to be subclassed for particular model types. So, the following is what you need:
mcmc = pm.MCMC([observation, lambda_1, lambda_2, tau])
or if you want to avoid listing the parameters explicitly:
mcmc = pm.MCMC(vars())
I will add an informative message to this effect.
Perfect, when I change my code to follow your example, dir
works fine. Thanks.
This should all be dealt with in the above pull request. Feel free to test.
Windows 7 running Python 3.5 32-bit and pymc 2.3.5.
Steps to recreate:
Expected output: a normal python
dir
listing of the attributes of the MCMC object.Edit:
Expected output same as or similar to
m.__dir__()
: