Hi,
I am trying to do Thomas Wiecki’s [Bayesian Deep Learning Part II] (https://blog.quantopian.com/bayesian-deep-learning2/)
When I do the sample_posterior_predictive I get the TypeError: object of type ‘MeanField’ has no len() : error.
Is this a bug or am I doing something wrong.?
What I do is:
with neural_network:
inference=pm.ADVI()
trace=pm.fit(n=150, method=inference, score=True)
with neural_network:
ppc = pm.sample_posterior_predictive(trace, progressbar=False)
The code of the neural network:
def build_ann(init):
with pm.Model() as neural_network:
l_in = lasagne.layers.InputLayer(shape=(None, 1, 28, 28),
input_var=input_var)
# Add a fully-connected layer of 800 units, using the linear rectifier, and
# initializing weights with Glorot's scheme (which is the default anyway):
n_hid1 = 800
l_hid1 = lasagne.layers.DenseLayer(
l_in, num_units=n_hid1,
nonlinearity=lasagne.nonlinearities.tanh,
b=init,
W=init
)
n_hid2 = 800
# Another 800-unit layer:
l_hid2 = lasagne.layers.DenseLayer(
l_hid1, num_units=n_hid2,
nonlinearity=lasagne.nonlinearities.tanh,
b=init,
W=init
)
# Finally, we'll add the fully-connected output layer, of 10 softmax units:
l_out = lasagne.layers.DenseLayer(
l_hid2, num_units=10,
nonlinearity=lasagne.nonlinearities.softmax,
b=init,
W=init
)
prediction = lasagne.layers.get_output(l_out)
# 10 discrete output classes -> pymc3 categorical distribution
out = pm.Categorical('out', prediction, observed=target_var)
return neural_network
class GaussWeights(object):
def init(self):
self.count = 0
def call(self, shape):
self.count += 1
return pm.Normal(‘w%d’ % self.count, mu=0, sd=.1,
testval=np.random.normal(size=shape).astype(np.float64),
shape=shape)
input_var = pm.Minibatch(X_train, batch_size=32)
target_var = pm.Minibatch(y_train, batch_size=32)