def __init__(self, d=None, name=''): if d == None: d = {} test_obj_instance(d, (dict)) self.d = d self.name = name
def make_transform(distro, transform_type='', complement=False): test_obj_instance(distro, DictWrapper) xs, ps = distro.sort_zip() scale = dict(xscale='linear', yscale='linear') if transform_type == 'exponential': complement = True scale['yscale'] = 'log' if transform_type == 'pareto': complement = True scale['yscale'] = 'log' scale['xscale'] = 'log' if complement: ps = [1.0-p for p in ps] if transform_type == 'weibull': xs.pop() ps.pop() ps = [-math.log(1.0-p) for p in ps] scale['xscale'] = 'log' scale['yscale'] = 'log' if transform_type == 'gumbel': xs.pop(0) ps.pop(0) ps = [-math.log(p) for p in ps] scale['yscale'] = 'log' return distro.__class__(dict(zip(xs,ps)), distro.name), scale
def make_mixture_pmfs(pmfs, name='mix'): test_obj_instance(pmfs, dict) mix = Pmf(name=name) for pmf, prob in pmfs.iteritems(): for x, p in pmf: mix.increment(x, p * prob) pmf.normalise() return mix
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 make_pmf_from_hist(hist, name=None): if name is None: name = hist.name test_obj_instance(hist, Histogram) # make a copy of the dictionary d = dict(hist.get_dict()) pmf = Pmf(d, name) pmf.normalise() return pmf
def relative_mean_difference(pmf, mu=None): test_obj_instance(pmf, Pmf) if mu is None: mu = mean(pmf) diff = Pmf() for v1, p1 in pmf.items(): for v2, p2 in pmf.items(): diff.increment(abs(v1 - v2), p1 * p2) return mean(diff) / mu
def make_pmf_from_cdf(cdf, name=None): if name is None: name = cdf.name test_obj_instance(cdf, Cdf) pmf = Pmf(name=name) prev = 0.0 for val, prob in cdf: pmf.increment(val, prob-prev) prev = prob pmf.normalise() return pmf
def __init__(self, null_hypo_results, alternative_hypo_result, bayesian_result_suite): test_obj_instance(null_hypo_results, HypoTestResult) test_obj_instance(alternative_hypo_result, HypoTestResult) test_obj_instance(bayesian_result_suite, BayesianResultSuite) self.null_hypo_results = null_hypo_results self.alternative_hypo_result = alternative_hypo_result self.bayesian_result_suite = bayesian_result_suite
def __init__(self, median_bayesian_result, plus_sigma_bayesian_result, minus_sigma_bayesian_result): test_obj_instance(median_bayesian_result, BayesianResult) test_obj_instance(plus_sigma_bayesian_result, BayesianResult) test_obj_instance(minus_sigma_bayesian_result, BayesianResult) self.median_bayesian_result = median_bayesian_result self.plus_sigma_bayesian_result = plus_sigma_bayesian_result self.minus_sigma_bayesian_result = minus_sigma_bayesian_result
def _validate_objects(self): test_obj_instance(self.sample_one, list) test_obj_instance(self.sample_two, list) test_obj_instance(self.population, list) test_obj_instance(self.options, dict)
def __init__(self, results): test_obj_instance(results, dict) self.results = results
def make_pmf_from_list(lst, name=''): test_obj_instance(lst, list) hist = make_hist_from_list(lst, name) return make_pmf_from_hist(hist)
def _validate_input_objects(self, observed_sample, expected_sample, prob_functions): test_obj_instance(observed_sample, Pmf) test_obj_instance(expected_sample, Pmf)
def plot_histograms(distros, **options): test_obj_instance(distros, list) for distro in distros: plot_histogram(distro, **options)
def make_cdf_from_dict(dct, name=''): test_obj_instance(dct, dict) return make_cdf_from_items(dct.items(), name)
def make_hist_from_list(lst, name=''): test_obj_instance(lst, list) hist = Histogram(name=name) [hist.increment(x) for x in lst] return hist
def make_pmf_from_dict(dct, name=''): test_obj_instance(dct, dict) pmf = Pmf(dct, name) pmf.normalise() return pmf
def plot_discrete_distributions(distros, **options): test_obj_instance(distros, list) for distro in distros: plot_discrete_distribution(distro, **options)
def get_probabilities(self, pmf): test_obj_instance(pmf, Pmf) cdf = make_cdf_from_pmf(pmf) return cdf.get_prob(self.high) - cdf.get_prob(self.low)
def __init__(self, sample): test_obj_instance(sample, list) self.__sample = sample self.__mean = mean(sample) self.__median = median(sample)
def make_hist_from_dict(dct, name=''): test_obj_instance(dct, dict) return Histogram(dct, name)