Variables vector / dependencies / theano graph

Hi all, Lets say we have a vector of variables a[1…K] following independent normal distribution (e.g. regression coefficients). If these variables have the same mu and sd, one would create a single variable and use the “shape” parameter to pass the K values. (or even create an MvNormal with a spherical covariance)

However, the mu for a variable a[k] depends on the variable a[k-1].
e.g. a[k] ~ N(a[k-1],tau).
An additional complication is that these variables follow a truncated distribution in which the lower bound for a[k] is determined by a[k-1].
e.g. a[k] = Bound(Normal, lower=a[k-1])('a_k',mu=a[k-1],sd=tau)

Is my only option to create these variables explicitly in a for loop? (which I presume will slow down inference considerably).
The worse part is that it is used as part of a hierarchical model, so i will end up having to replicate the structure!
Thanks in advance for your suggestions.

You can create a HalfNormal(sd=tau, shape=K) and then do tt.cumsum over the output tensor.

Thank you for your reply. Could you please elaborate?
The HalfNormal is going to lower bound each a[k] to 0. How can the cumsum be used to set the lower bound for each a[k] to a[k-1]? How are the means for a[k] set to a[k-1] as a prior? Once again thanks.

Since you are modelling a[k] = Bound(Normal, lower=a[k-1])('a_k',mu=a[k-1],sd=tau), it would means that a[k] = HalfNormal(sd = tau) + a[k-1]. Expanding it it becames a cumsum operation.