# Buggy code
def astep(self, q0, logp):
    """q0 : current state
    logp : log probability function
    """

    # Draw from the normal prior by multiplying the Cholesky decomposition
    # of the covariance with draws from a standard normal
    chol = draw_values([self.prior_chol])
    nu = np.dot(chol, nr.randn(chol.shape[0]))
    y = logp(q0) - nr.standard_exponential()

    # Draw initial proposal and propose a candidate point
    theta = nr.uniform(0, 2 * np.pi)
    theta_max = theta
    theta_min = theta - 2 * np.pi
    q_new = q0 * np.cos(theta) + nu * np.sin(theta)

    while logp(q_new) <= y:
        # Shrink the bracket and propose a new point
        if theta < 0:
            theta_min = theta
        else:
            theta_max = theta
        theta = nr.uniform(theta_min, theta_max)
        q_new = q0 * np.cos(theta) + nu * np.sin(theta)

    return q_new


# Traceback (TypeError)
TypeError Traceback (most recent call last)
in ()
1 ann_input.set_value(X_test)
2 ann_output.set_value(Y_test)
----> 3 ppc = pm.sample_ppc(trace, model=neural_network, samples=500, progressbar=False)
4

C:\Users\Nikos\Documents\Lasagne\python-3.4.4.amd64\lib\site-packages\pymc3\sampling.py in sample_ppc(trace, samples, model, vars, size, random_seed, progressbar)
526 for var in vars:
527 ppc[var.name].append(var.distribution.random(point=param,
--> 528 size=size))
529
530 return {k: np.asarray(v) for k, v in ppc.items()}

C:\Users\Nikos\Documents\Lasagne\python-3.4.4.amd64\lib\site-packages\pymc3\distributions\discrete.py in random(self, point, size, repeat)
152
153 def random(self, point=None, size=None, repeat=None):
--> 154 p = draw_values([self.p], point=point)
155 return generate_samples(stats.bernoulli.rvs, p,
156 dist_shape=self.shape,

C:\Users\Nikos\Documents\Lasagne\python-3.4.4.amd64\lib\site-packages\pymc3\distributions\distribution.py in draw_values(params, point)
183 if not isinstance(node, (tt.sharedvar.TensorSharedVariable,
184 tt.TensorConstant)):
--> 185 givens[name] = (node, draw_value(node, point=point))
186 values = [None for _ in params]
187 for i, param in enumerate(params):

C:\Users\Nikos\Documents\Lasagne\python-3.4.4.amd64\lib\site-packages\pymc3\distributions\distribution.py in draw_value(param, point, givens)
251 except:
252 shape = param.shape
--> 253 if len(shape) == 0 and len(value) == 1:
254 value = value[0]
255 return value

TypeError: object of type 'TensorVariable' has no len()

# Fixed code
def astep(self, q0, logp):
    """q0 : current state
    logp : log probability function
    """

    # Draw from the normal prior by multiplying the Cholesky decomposition
    # of the covariance with draws from a standard normal
    chol = draw_values([self.prior_chol])[0]
    nu = np.dot(chol, nr.randn(chol.shape[0]))
    y = logp(q0) - nr.standard_exponential()

    # Draw initial proposal and propose a candidate point
    theta = nr.uniform(0, 2 * np.pi)
    theta_max = theta
    theta_min = theta - 2 * np.pi
    q_new = q0 * np.cos(theta) + nu * np.sin(theta)

    while logp(q_new) <= y:
        # Shrink the bracket and propose a new point
        if theta < 0:
            theta_min = theta
        else:
            theta_max = theta
        theta = nr.uniform(theta_min, theta_max)
        q_new = q0 * np.cos(theta) + nu * np.sin(theta)

    return q_new