def _sample_n(self, n, seed=None):
# The sampling method comes from the well known fact that if X ~ Normal(0,
# 1), and Z ~ Chi2(df), then X / sqrt(Z / df) ~ StudentT(df).
shape = array_ops.concat(0, ([n], self.batch_shape()))
normal_sample = random_ops.random_normal(
shape, dtype=self.dtype, seed=seed)
half = constant_op.constant(0.5, self.dtype)
df = self.df * array_ops.ones(self.batch_shape(), dtype=self.dtype)
gamma_sample = random_ops.random_gamma(
[n,], half * df, beta=half, dtype=self.dtype,
seed=distribution_util.gen_new_seed(seed, salt="student_t"))
samples = normal_sample / math_ops.sqrt(gamma_sample / df)
return samples * self.sigma + self.mu
评论列表
文章目录