Exemplo n.º 1
0
def test_fitting_binomial():

    print("\nTesting Binomial with n=100, p=0.3, loc=1:")
    dist = RVGs.Binomial(n=100, p=0.3, loc=1)
    print('  percentile interval: ', dist.get_percentile_interval(alpha=0.05))

    data = np.array(get_samples(dist, np.random))
    # method of moment
    dict_mm_results = RVGs.Binomial.fit_mm(mean=np.mean(data),
                                           st_dev=np.std(data),
                                           fixed_location=1)
    # maximum likelihood
    dict_ml_results = RVGs.Binomial.fit_ml(data=data, fixed_location=1)

    print("  Fit:")
    print("    MM:", dict_mm_results)
    print("    ML:", dict_ml_results)

    # plot the fitted distributions
    Plot.plot_binomial_fit(data=data,
                           fit_results=dict_mm_results,
                           title='Method of Moment')
    Plot.plot_binomial_fit(data=data,
                           fit_results=dict_ml_results,
                           title='Maximum Likelihood')
Exemplo n.º 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))