Sure,
the neural network:
def build_ann(init, input_var, target_var):
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
#Creating the NN
neural_network = build_ann(GaussWeights(),minibatch_x, minibatch_y)
with neural_network:
inference = pm.ADVI()
approx = pm.fit(n=15000, method=inference, score=True)
0%| | 0/15000 [00:00<?, ?it/s]/u01/anaconda3/lib/python3.6/site-packages/theano/tensor/subtensor.py:2197: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use arr[tuple(seq)]
instead of arr[seq]
. In the future this will be interpreted as an array index, arr[np.array(seq)]
, which will result either in an error or a different result.
rval = inputs[0].getitem(inputs[1:])
Average Loss = 51,094: 100%|██████████| 15000/15000 [1:30:31<00:00, 2.64it/s]
Finished [100%]: Average Loss = 50,890
input_var.set_value(X_test)
target_var.set_value(y_test)
with neural_network:
ppc = pm.sample_posterior_predictive(inference, samples=500, progressbar=False)
TypeError Traceback (most recent call last)
in
1 with neural_network:
----> 2 ppc = pm.sample_posterior_predictive(inference, samples=500, progressbar=False)
/u01/anaconda3/lib/python3.6/site-packages/pymc3/sampling.py in sample_posterior_predictive(trace, samples, model, vars, size, random_seed, progressbar)
1102 posterior predictive samples.
1103 “”"
-> 1104 len_trace = len(trace)
1105 try:
1106 nchain = trace.nchains
TypeError: object of type ‘ADVI’ has no len()