def true_nll_gaussian(params, mu, sigma): params = convert_to_container(params, container=tuple) mu = convert_to_container(mu, container=tuple) sigma = convert_to_container(sigma, container=tuple) constraint = ztf.constant(0.) if not len(params) == len(mu) == len(sigma): raise ValueError("params, mu and sigma have to have the same length.") for param, mean, sig in zip(params, mu, sigma): constraint += ztf.reduce_sum( ztf.square(param - mean) / (2. * ztf.square(sig))) return constraint
def indefinite_integral(limits): max_degree = model.degree + 1 polys = do_recurrence(x=limits, polys=chebyshev_polys, degree=max_degree, recurrence=chebyshev_recurrence) one_limit_integrals = [] for degree in range(2, max_degree): coeff = model.params[f"c_{degree}"] n_float = ztf.convert_to_tensor(degree) integral = (n_float * polys[degree + 1] / (ztf.square(n_float) - 1) - limits * polys[degree] / (n_float - 1)) one_limit_integrals.append(coeff * integral) return ztf.reduce_sum(one_limit_integrals, axis=0)
def _func(self, x): mu = self.params['mu'] sigma = self.params['sigma'] x = ztf.unstack_x(x) return ztf.exp(-ztf.square((x - mu) / sigma))
def _unnormalized_pdf(self, x): mu = self.params['mu'] sigma = self.params['sigma'] x = ztf.unstack_x(x) return ztf.exp(-ztf.square((x - mu) / sigma))