Ejemplo n.º 1
0
def plot_discrete_distribution(distro, **options):

    test_obj_subclass(distro, DictWrapper)
    
    xs, ps = distro.sort_zip()
    options = add_options_to_plot(options, label=distro.name)
    plot(xs, ps, **options)
Ejemplo n.º 2
0
 def __mod__(self, other):
     test_obj_subclass(other, (DictWrapper))
     d = copy.deepcopy(self.d)
     for key, value in other:
         if value == 0.0:
             d[key] = 0.0
         else:
             d[key] %= value
     return DictWrapper(d, self.name)
Ejemplo n.º 3
0
 def __init__(self, prior, sample, likelihood):
     test_obj_instance(prior, Pmf)
     test_obj_instance(sample, list)
     test_obj_subclass(likelihood, Likelihood)
     self.prior = prior
     self.sample = sample
     self.likelihood = likelihood
     self.posterior = deepcopy(prior)
     self.posterior.name = 'posterior'
     self._estimate_posterior()
Ejemplo n.º 4
0
 def __init__(self, prior, sample, likelihood):
     test_obj_instance(prior, Pmf)
     test_obj_instance(sample, list)
     test_obj_subclass(likelihood, Likelihood)
     self.prior = prior
     self.sample = sample
     self.likelihood = likelihood
     self.posterior = deepcopy(prior)
     self.posterior.name = 'posterior'
     self._estimate_posterior()
Ejemplo n.º 5
0
 def is_subset(self, other):
     test_obj_subclass(other, (DictWrapper))
     if len(other) < len(self):
         return False
     
     if (not min(other.get_keys()) <= min(self.get_keys())) and (not max(self.get_keys()) <= max(min(other.get_keys()))): 
         return False
     
     for val, freq in self.d.iteritems():
         if other[val] == None:
             continue
         if freq > other[val]:
             return False
     return True
Ejemplo n.º 6
0
def plot_histogram(distro, **options):
    
    test_obj_subclass(distro, DictWrapper)

    xs, fs = distro.sort_zip()
    width = min(differences_adj_elements(xs))

    options = add_options_to_plot(options, 
                                  label=distro.name,
                                  align='center',
                                  edgecolor='blue',
                                  width=width)

    pyplot.bar(xs, fs, **options)    
Ejemplo n.º 7
0
 def __mul__(self, other):
     test_obj_subclass(other, (DictWrapper))
     d = copy.deepcopy(self.d)
     for key, value in other:
         d[key] *= value
     return DictWrapper(d, self.name)
Ejemplo n.º 8
0
 def __ge__(self, other):
     test_obj_subclass(other, (DictWrapper))
     return (self.d >= other.d)
Ejemplo n.º 9
0
 def __cmp__(self, other):
     test_obj_subclass(other, (DictWrapper))
     return cmp(self.d, other.d)    
Ejemplo n.º 10
0
 def __init__(self, X, Y):
     self.X = X
     self.Y = Y
     test_obj_subclass(self.X, RandomVariable)
     test_obj_subclass(self.Y, RandomVariable)