def gen(self, n_samples=1, u=None):
"""
Generate samples from made. Requires as many evaluations as number of inputs.
:param n_samples: number of samples
:param u: random numbers to use in generating samples; if None, new random numbers are drawn
:return: samples
"""
x = np.zeros([n_samples, self.n_inputs], dtype=dtype)
u = rng.randn(n_samples, self.n_inputs).astype(dtype) if u is None else u
for i in xrange(1, self.n_inputs + 1):
m, logp, loga = self.eval_comps(x)
idx = np.argwhere(self.input_order == i)[0, 0]
for n in xrange(n_samples):
z = util.discrete_sample(np.exp(loga[n, idx]))[0]
x[n, idx] = m[n, idx, z] + np.exp(np.minimum(-0.5 * logp[n, idx, z], 10.0)) * u[n, idx]
return x
评论列表
文章目录