I want to create:
- An square array X of independent random variables. Each element of the array follows the standard uniform distribution
- Same as X, except each column is constrained to sum to one. To sample from this distribution, I can use
y = np.random.uniform(0, 1, size=(5, 5)); y /= np.sum(y, axis=0)
I absolutely need 1 and 2 is nice to have.
What is the correct way to do this for an array of 100 x 100 random variables?
I was thinking about the follow way, which seems horribly inefficient.
Test
import theano.tensor as tt
import pymc3 as pm
# with shape var_shape
var_shape = (4, 4)
with pm.Model() as opmodel:
var_array = []
for i in range(var_shape[0]):
for j in range(var_shape[1]):
var_now = pm.Uniform('a_%d_%d' % (i, j),
lower=0, upper=1)
var_array.append(var_now)
# Theta is an array of independent
# uniform random variables
theta = tt.as_tensor_variable(var_array)
theta = theta.reshape(var_shape)
# Normalize each column of the array
normalized_theta = theta / tt.sum(theta, axis=0)
# Use theta as the prior distribution for NUTS ...