def GMM_sample(mus, sigmas, mix_weights):
"""
First, sample according to the prior mixing probabilities
to choose the component density.
Second, draw sample from that density
Inspired by implementation in `cle`
"""
chosen_component = \
T.argmax(
srng.multinomial(pvals=mix_weights),
axis=1)
selected_mus = mus[T.arange(mus.shape[0]), :, chosen_component]
selected_sigmas = sigmas[T.arange(sigmas.shape[0]), :, chosen_component]
sample = srng.normal(size=selected_mus.shape,
avg=0.,
std=1.)
sample *= selected_sigmas
sample += selected_mus
return sample, selected_mus, selected_sigmas, chosen_component
评论列表
文章目录