Hi, I would like to sample joint probability densities of size nxm from a Dirichlet distribution defined on the simplex of size nxm, i.e. each sample is a joint probability density. The only thing I can do so far is generate a doubly-stochastic matrix, which columns and rows sum to a vector of 1. Any input would be appreciated.

@SBY54 Welcome to the Tensorflow Forum!

You can sample joint probability densities of size nxm from a Dirichlet distribution defined on the simplex of size nxm :

Refer below sample code :

```
import numpy as np
def sample_dirichlet_doubly_stochastic(n, m):
"""Samples a joint probability density from a Dirichlet distribution defined on the simplex of size nxm using a doubly-stochastic matrix.
Args:
n (int): The number of rows in the matrix.
m (int): The number of columns in the matrix.
Returns:
np.ndarray: The sampled joint probability density.
"""
ds_matrix = np.random.rand(n, m)
ds_matrix = ds_matrix / np.sum(ds_matrix, axis=1, keepdims=True)
p = ds_matrix @ ds_matrix.T
return p
if __name__ == "__main__":
n = 3
m = 2
p = sample_dirichlet_doubly_stochastic(n, m)
print(p)
```

This code will first generate a doubly-stochastic matrix. Then, it will multiply the matrix by its transpose. The result will be a joint probability density sampled from a Dirichlet distribution.

I hope this helps! Let me know if you have any further queries.

Thank you for you reply, Tanya,

The matrix you are using is not bi-stochastic, you are normalizing only rows. Also , I think that the product of two bi-stochastic matrices is a bi-stochastic matrix. What I am looking for is to sample from the generalized Dirichlet in the space of matrices, where the marginals are pmfs.