예제 #1
0
 def __init__(self, d=None, name=''):
     if d == None:
         d = {}
         
     test_obj_instance(d, (dict))
     self.d = d
     self.name = name
예제 #2
0
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
        
    
예제 #3
0
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
예제 #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()
예제 #5
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()
예제 #6
0
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
예제 #7
0
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
예제 #8
0
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
예제 #9
0
 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
예제 #10
0
 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
예제 #11
0
    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
예제 #12
0
    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
예제 #13
0
 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)
예제 #14
0
 def __init__(self, results):
     test_obj_instance(results, dict)
     self.results = results
예제 #15
0
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)
예제 #16
0
 def _validate_input_objects(self, observed_sample, expected_sample, prob_functions):
     test_obj_instance(observed_sample, Pmf)
     test_obj_instance(expected_sample, Pmf)
예제 #17
0
def plot_histograms(distros, **options):
    
    test_obj_instance(distros, list)
    
    for distro in distros:
        plot_histogram(distro, **options)
예제 #18
0
def make_cdf_from_dict(dct, name=''):
    test_obj_instance(dct, dict)
    return make_cdf_from_items(dct.items(), name)
예제 #19
0
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
예제 #20
0
def make_pmf_from_dict(dct, name=''):
    test_obj_instance(dct, dict)
    pmf = Pmf(dct, name)
    pmf.normalise()
    return pmf
예제 #21
0
 def __init__(self, results):
     test_obj_instance(results, dict)
     self.results = results
예제 #22
0
def plot_discrete_distributions(distros, **options):

    test_obj_instance(distros, list)
    
    for distro in distros:
        plot_discrete_distribution(distro, **options)
예제 #23
0
 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)
예제 #24
0
 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)
예제 #25
0
 def __init__(self, sample):
     test_obj_instance(sample, list)
     self.__sample = sample
     self.__mean = mean(sample)
     self.__median = median(sample)
예제 #26
0
def make_hist_from_dict(dct, name=''):
    test_obj_instance(dct, dict)
    return Histogram(dct, name)