Question

I'm using a Dirichlet distribution to generate an array of random numbers which sum to 1. However, I actually think I need these numbers to sum to an arbitrary constant.

import numpy as np
d = np.random.dirichlet(np.ones(10), size=1)

I'm confused about a good way to modify this so that the sum is, say 10. Presumably:

10*d

isn't a good way to go about it.

Was it helpful?

Solution

I think N*d is a legitimate way to modify your random numbers to sum to N=10. The Dirichlet random numbers are samples from a Gamma generator that are normalized to sum to 1 (see also Wikipedia). Since you want them to sum to N instead of 1, it's completely legitimate to just multiply each Dirichlet random number by N.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top