AlexanderFabisch / gmr

Gaussian Mixture Regression
https://alexanderfabisch.github.io/gmr/
BSD 3-Clause "New" or "Revised" License
168 stars 49 forks source link

Doing conditional sampling for multiple values #38

Closed nardi closed 2 years ago

nardi commented 2 years ago

I would like to perform a specific kind of sampling, and I'm not sure what is the best way to go about it. Say I have two variables (1d arrays) X and Y, and I have a GMM trained on the [X Y] dataset. Now I'd like to generate values for Y based on an array of values of X, but instead of just getting the mean I'd like to obtain multiple (let's say N) values sampled according to the mixture distribution. One way to accomplish this is as follows:

Y_sampled = np.empty((len(X), N))
for i in range(len(X)):
  Y_sampled[i, :] = gmm.condition([0], X[i]).sample(N)

However, this requires a loop over all values of X (which predict avoids). Is there a better/more performant way to get this same result?

AlexanderFabisch commented 2 years ago

Hi @nardi ,

unfortunately there is no faster way to do this at the moment. If you have an idea how to implement this efficiently, let me know!