Esempio n. 1
0
 def simulate(self, rowid, targets, constraints=None, inputs=None, N=None):
     DistributionGpm.simulate(self, rowid, targets, constraints, inputs, N)
     if rowid in self.data:
         return {self.outputs[0]: self.data[rowid]}
     an, bn = Poisson.posterior_hypers(self.N, self.sum_x, self.a, self.b)
     x = self.rng.negative_binomial(an, bn / (bn + 1.))
     return {self.outputs[0]: x}
Esempio n. 2
0
 def simulate(self, rowid, targets, constraints=None, inputs=None, N=None):
     DistributionGpm.simulate(self, rowid, targets, constraints, inputs, N)
     if rowid in self.data:
         return {self.outputs[0]: self.data[rowid]}
     alpha = self.strength * self.balance
     beta = self.strength * (1. - self.balance)
     x = self.rng.beta(alpha, beta)
     return {self.outputs[0]: x}
Esempio n. 3
0
 def simulate(self, rowid, targets, constraints=None, inputs=None, N=None):
     DistributionGpm.simulate(self, rowid, targets, constraints, inputs, N)
     if rowid in self.data:
         return {self.outputs[0]: self.data[rowid]}
     an, bn = Geometric.posterior_hypers(self.N, self.sum_x, self.a, self.b)
     pn = self.rng.beta(an, bn)
     x = self.rng.geometric(pn) - 1
     return {self.outputs[0]: x}
Esempio n. 4
0
 def simulate(self, rowid, targets, constraints=None, inputs=None, N=None):
     DistributionGpm.simulate(self, rowid, targets, constraints, inputs, N)
     if rowid in self.data:
         return {self.outputs[0]: self.data[rowid]}
     an, bn = Exponential.posterior_hypers(self.N, self.sum_x, self.a,
                                           self.b)
     mu = self.rng.gamma(an, scale=1. / bn)
     x = self.rng.exponential(scale=1. / mu)
     return {self.outputs[0]: x}
Esempio n. 5
0
File: crp.py Progetto: wilsondy/cgpm
 def simulate(self, rowid, targets, constraints=None, inputs=None, N=None):
     DistributionGpm.simulate(self, rowid, targets, constraints, inputs, N)
     if rowid in self.data:
         x = self.data[rowid]
     else:
         K = sorted(self.counts) + [max(self.counts) + 1] if self.counts\
             else [0]
         logps = [self.logpdf(rowid, {targets[0]: x}, None) for x in K]
         x = gu.log_pflip(logps, array=K, rng=self.rng)
     return {self.outputs[0]: x}
Esempio n. 6
0
 def simulate(self, rowid, targets, constraints=None, inputs=None, N=None):
     DistributionGpm.simulate(self, rowid, targets, constraints, inputs, N)
     if rowid in self.data:
         return {self.outputs[0]: self.data[rowid]}
     mn, rn, sn, nun = Normal.posterior_hypers(self.N, self.sum_x,
                                               self.sum_x_sq, self.m,
                                               self.r, self.s, self.nu)
     mu, rho = Normal.sample_parameters(mn, rn, sn, nun, self.rng)
     x = self.rng.normal(loc=mu, scale=rho**-.5)
     return {self.outputs[0]: x}
Esempio n. 7
0
 def simulate(self, rowid, targets, constraints=None, inputs=None, N=None):
     DistributionGpm.simulate(self, rowid, targets, constraints, inputs, N)
     if rowid in self.data:
         return {self.outputs[0]: self.data[rowid]}
     p0 = Bernoulli.calc_predictive_logp(0, self.N, self.x_sum, self.alpha,
                                         self.beta)
     p1 = Bernoulli.calc_predictive_logp(1, self.N, self.x_sum, self.alpha,
                                         self.beta)
     x = gu.log_pflip([p0, p1], rng=self.rng)
     return {self.outputs[0]: x}
Esempio n. 8
0
 def simulate(self, rowid, targets, constraints=None, inputs=None, N=None):
     DistributionGpm.simulate(self, rowid, targets, constraints, inputs, N)
     if rowid in self.data:
         return {self.outputs[0]: self.data[rowid]}
     max_iters = 1000
     for i in xrange(max_iters):
         x = self.rng.normal(loc=self.mu, scale=self.sigma)
         if self.l <= x <= self.h:
             return {self.outputs[0]: x}
     else:
         raise RuntimeError('NormalTrunc failed to rejection sample.')
Esempio n. 9
0
 def simulate(self, rowid, targets, constraints=None, inputs=None, N=None):
     DistributionGpm.simulate(self, rowid, targets, constraints, inputs, N)
     if rowid in self.data:
         return {self.outputs[0]: self.data[rowid]}
     an, bn = Vonmises.posterior_hypers(self.N, self.sum_sin_x,
                                        self.sum_cos_x, self.a, self.b,
                                        self.k)
     # if not 0 <= bn <= 2*pi:
     #     import ipdb; ipdb.set_trace()
     mu = self.rng.vonmises(bn - pi, an) + pi
     x = self.rng.vonmises(mu - pi, self.k) + pi
     assert 0 <= x <= 2 * pi
     return {self.outputs[0]: x}
Esempio n. 10
0
 def simulate(self, rowid, targets, constraints=None, inputs=None, N=None):
     # XXX This implementation is not verified but will be covered in
     # future univariate simulate tests, see Github issue #14.
     DistributionGpm.simulate(self, rowid, targets, constraints, inputs, N)
     if rowid in self.data:
         return {self.outputs[0]: self.data[rowid]}
     # Simulate normal parameters.
     mn, rn, sn, nun = Normal.posterior_hypers(self.N, self.sum_log_x,
                                               self.sum_log_x_sq, self.m,
                                               self.r, self.s, self.nu)
     mu, rho = Normal.sample_parameters(mn, rn, sn, nun, self.rng)
     xn = self.rng.normal(loc=mu, scale=rho**-.5)
     x = np.exp(xn)
     return {self.outputs[0]: x}
Esempio n. 11
0
 def simulate(self, rowid, targets, constraints=None, inputs=None, N=None):
     DistributionGpm.simulate(self, rowid, targets, constraints, inputs, N)
     if rowid in self.data:
         return {self.outputs[0]: self.data[rowid]}
     x = gu.pflip(self.counts + self.alpha, rng=self.rng)
     return {self.outputs[0]: x}