Esempio n. 1
0
 def incorporate(self, rowid, observation, inputs=None):
     DistributionGpm.incorporate(self, rowid, observation, inputs)
     x = observation[self.outputs[0]]
     self.N += 1.
     self.sum_x += x
     self.sum_x_sq += x * x
     self.data[rowid] = x
Esempio n. 2
0
File: crp.py Progetto: wilsondy/cgpm
 def incorporate(self, rowid, observation, inputs=None):
     DistributionGpm.incorporate(self, rowid, observation, inputs)
     x = int(observation[self.outputs[0]])
     self.N += 1
     if x not in self.counts:
         self.counts[x] = 0
     self.counts[x] += 1
     self.data[rowid] = x
Esempio n. 3
0
 def incorporate(self, rowid, observation, inputs=None):
     DistributionGpm.incorporate(self, rowid, observation, inputs)
     x = observation[self.outputs[0]]
     if x < 0:
         raise ValueError('Invalid Exponential: %s' % str(x))
     self.N += 1
     self.sum_x += x
     self.data[rowid] = x
Esempio n. 4
0
 def incorporate(self, rowid, observation, inputs=None):
     DistributionGpm.incorporate(self, rowid, observation, inputs)
     x = observation[self.outputs[0]]
     if x not in [0, 1]:
         raise ValueError('Invalid Bernoulli: %s' % str(x))
     self.N += 1
     self.x_sum += x
     self.data[rowid] = x
Esempio n. 5
0
 def incorporate(self, rowid, observation, inputs=None):
     DistributionGpm.incorporate(self, rowid, observation, inputs)
     x = observation[self.outputs[0]]
     if not (x % 1 == 0 and x >= 0):
         raise ValueError('Invalid Geometric: %s') % str(x)
     self.N += 1
     self.sum_x += x
     self.data[rowid] = x
Esempio n. 6
0
 def incorporate(self, rowid, observation, inputs=None):
     DistributionGpm.incorporate(self, rowid, observation, inputs)
     x = observation[self.outputs[0]]
     if not (0 <= x <= 2 * pi):
         raise ValueError('Invalid Vonmises: %s' % str(x))
     self.N += 1
     self.sum_sin_x += sin(x)
     self.sum_cos_x += cos(x)
     self.data[rowid] = x
Esempio n. 7
0
 def incorporate(self, rowid, observation, inputs=None):
     DistributionGpm.incorporate(self, rowid, observation, inputs)
     x = observation[self.outputs[0]]
     if x <= 0:
         raise ValueError('Invalid Lognormal: %s' % str(x))
     self.N += 1
     self.sum_log_x += log(x)
     self.sum_log_x_sq += log(x) * log(x)
     self.data[rowid] = x
Esempio n. 8
0
 def incorporate(self, rowid, observation, inputs=None):
     DistributionGpm.incorporate(self, rowid, observation, inputs)
     x = observation[self.outputs[0]]
     if not (x % 1 == 0 and x >= 0):
         raise ValueError('Invalid Poisson: %s' % str(x))
     self.N += 1
     self.sum_x += x
     self.sum_log_fact_x += gammaln(x + 1)
     self.data[rowid] = x
Esempio n. 9
0
 def incorporate(self, rowid, observation, inputs=None):
     DistributionGpm.incorporate(self, rowid, observation, inputs)
     x = observation[self.outputs[0]]
     if not (x % 1 == 0 and 0 <= x < self.k):
         raise ValueError('Invalid Categorical(%d): %s' % (self.k, x))
     x = int(x)
     self.N += 1
     self.counts[x] += 1
     self.data[rowid] = x
Esempio n. 10
0
 def incorporate(self, rowid, observation, inputs=None):
     DistributionGpm.incorporate(self, rowid, observation, inputs)
     x = observation[self.outputs[0]]
     if not (self.l <= x <= self.h):
         raise ValueError('Invalid NormalTrunc(%f,%f): %s' %
                          (self.l, self.h, str(x)))
     self.N += 1
     self.sum_x += x
     self.sum_x_sq += x * x
     self.data[rowid] = x
Esempio n. 11
0
 def incorporate(self, rowid, observation, inputs=None):
     DistributionGpm.incorporate(self, rowid, observation, inputs)
     x = observation[self.outputs[0]]
     if np.allclose(0, x):
         x = 0.001
     elif np.allclose(1, x):
         x = 0.999
     if not 0 < x < 1:
         raise ValueError('Invalid Beta: %s' % str(x))
     self.N += 1
     self.sum_log_x += log(x)
     self.sum_minus_log_x += log(1.-x)
     self.data[rowid] = x