def _sample(self, num_samples): sigma, mu = self.natural_to_regular(self.regular_to_natural(self.get_parameters('regular'))) L = T.cholesky(sigma) sample_shape = T.concat([[num_samples], T.shape(mu)], 0) noise = T.random_normal(sample_shape) L = T.tile(L[None], T.concat([[num_samples], T.ones([T.rank(sigma)], dtype=np.int32)])) return mu[None] + T.matmul(L, noise[..., None])[..., 0]
def natural_to_regular(cls, natural_parameters): J, m = natural_parameters[Stats.XXT], natural_parameters[Stats.X] sigma = -0.5 * T.matrix_inverse(J) mu = T.matmul(sigma, m[..., None])[..., 0] return [sigma, mu]