I fixed a bug in the definition of the CAR model. Here is the new source
class CAR3(distribution.Continuous):
"""
Conditional Autoregressive (CAR) with 2nd order neighbors
"""
def __init__(self, adjacency, tau, rho, adjacency2, rho2, *args, **kwargs):
super(CAR3, self).__init__(*args, **kwargs)
n, m = adjacency.shape
self.n = n
adjacency_sparse = scipy.sparse.csr_matrix(adjacency)
self.adjacency = theano.sparse.as_sparse_variable(adjacency_sparse)
adjacency_sparse2 = scipy.sparse.csr_matrix(adjacency2)
self.adjacency2 = theano.sparse.as_sparse_variable(adjacency_sparse2)
self.n_neighbors = tt.as_tensor_variable(adjacency.sum(1))
self.n_neighbors2 = tt.as_tensor_variable(adjacency2.sum(1))
self.mean = tt.zeros(n)
self.median = self.mean
self.tau = tt.as_tensor_variable(tau)
self.rho = tt.as_tensor_variable(rho)
self.rho2 = tt.as_tensor_variable(rho2)
def logp(self, x):
priorvardenom = 1 - (self.rho + self.rho2) + self.rho * self.n_neighbors + self.rho2 * self.n_neighbors2
#priorvar = self.tau * priorvardenom
priorvar = tt.sqrt(priorvardenom/self.tau)
Wx = theano.sparse.dot(self.adjacency, x.reshape((self.n, 1)))
Wx2 = theano.sparse.dot(self.adjacency2, x.reshape((self.n, 1)))
mu_w = (self.rho * tt.sum(Wx, axis=1) + self.rho2*tt.sum(Wx2, axis=1)) / priorvardenom
return tt.sum(continuous.Normal.dist(mu=mu_w, tau=priorvar).logp(x))
And the new error
Auto-assigning NUTS sampler...
Initializing NUTS using advi+adapt_diag...
Average Loss = 199.77: 15%|█▌ | 30391/200000 [00:15<01:24, 1995.75it/s]
Convergence archived at 30500
Interrupted at 30,500 [15%]: Average Loss = 12,235
99%|█████████▉| 5954/6000 [27:56<00:16, 2.83it/s]/home/nadai/.local/lib/python3.4/site-packages/pymc3/step_methods/hmc/nuts.py:459: UserWarning: Chain 2 reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
'reparameterize.' % self._chain_id)
100%|█████████▉| 5999/6000 [28:08<00:00, 3.58it/s]/home/nadai/.local/lib/python3.4/site-packages/pymc3/step_methods/hmc/nuts.py:459: UserWarning: Chain 0 reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
'reparameterize.' % self._chain_id)
100%|██████████| 6000/6000 [28:08<00:00, 3.55it/s]
/home/nadai/.local/lib/python3.4/site-packages/pymc3/step_methods/hmc/nuts.py:459: UserWarning: Chain 1 reached the maximum tree depth. Increase max_treedepth, increase target_accept or reparameterize.
'reparameterize.' % self._chain_id)
And the new traces
Could you help me please?
