Exemple #1
0
def test_multinomial(rnd, n, pvals):
    # multinomial random variate generator
    multinomial_dist = RVGs.Binomial(n, pvals)

    # obtain samples
    samples = get_samples(multinomial_dist, rnd)

    # report mean and variance
    print_test_results('Multinomial',
                       samples,
                       expectation=n * pvals,
                       variance=n * pvals * (1 - pvals))
Exemple #2
0
def test_binomial(rnd, n, p, loc=0):

    # bimonial random variate generator
    binomial_dist = RVGs.Binomial(n, p, loc)

    # obtain samples
    samples = get_samples(binomial_dist, rnd)

    # report mean and variance
    print_test_results('Binomial',
                       samples,
                       expectation=n * p + loc,
                       variance=n * p * (1 - p))
dist = RVGs.Beta(2, 3, loc=1, scale=2)
dat_beta = np.array(get_samples(dist, np.random))  # generate data
dictResults = Fit.fit_beta(dat_beta, 'Data', minimum=1, maximum=3)  # fit
print("Fitting Beta:", dictResults)

# 3 fitting a beta-binomial distribution
dist = RVGs.BetaBinomial(100, 2, 3, loc=1, scale=2)  # n, a, b
dat_betabin = np.array(get_samples(dist, np.random))
dictResults = Fit.fit_beta_binomial(dat_betabin,
                                    'Data',
                                    fixed_location=1,
                                    fixed_scale=2)  # fit
print("Fitting BetaBinomial:", dictResults)

# 4 Binomial
dist = RVGs.Binomial(100, 0.3, 1)
dat_bin = np.array(get_samples(dist, np.random))
dictResults = Fit.fit_binomial(dat_bin, 'Data', fixed_location=1)  # fit
print("Fitting Binomial:", dictResults)

# 5 Empirical (for int data)
dat_em = np.random.poisson(30, 1000)
dictResults = Fit.fit_empirical(dat_em, 'Data', bin_size=2.5)  # fit
print("Fitting Empirical:", dictResults)

# 6 fitting a gamma distribution
dist = RVGs.Gamma(10, 1, 2)
dat_gamma = np.array(get_samples(dist, np.random))  # generate data
dictResults = Fit.fit_gamma(dat_gamma, 'Data', fixed_location=1)  # fit
print("Fitting Gamma:", dictResults)