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)
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)
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()
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
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)
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)
def __ge__(self, other): test_obj_subclass(other, (DictWrapper)) return (self.d >= other.d)
def __cmp__(self, other): test_obj_subclass(other, (DictWrapper)) return cmp(self.d, other.d)
def __init__(self, X, Y): self.X = X self.Y = Y test_obj_subclass(self.X, RandomVariable) test_obj_subclass(self.Y, RandomVariable)