コード例 #1
0
def test_geometric(rnd, p, loc=0):
    # geometric random variate generator
    geometric_dist = RVGs.Geometric(p, loc)

    # obtain samples
    samples = get_samples(geometric_dist, rnd)

    # report mean and variance
    print_test_results('Geometric',
                       samples,
                       expectation=1 / p + loc,
                       variance=(1 - p) / (p**2))
コード例 #2
0
ファイル: FitDistTests.py プロジェクト: yaesoubilab/SimPy
def test_fitting_geometric():
    print("\nTesting Geometric with p=0.3, loc=1")
    dist = RVGs.Geometric(p=0.3, loc=1)
    print('  percentile interval: ', dist.get_percentile_interval(alpha=0.05))

    data = np.array(get_samples(dist, np.random))
    dict_mm_results = RVGs.Geometric.fit_mm(mean=np.average(data),
                                            fixed_location=1)
    dict_ml_results = RVGs.Geometric.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_geometric_fit(data=data,
                            fit_results=dict_mm_results,
                            title='Method of Moment')
    Plot.plot_geometric_fit(data=data,
                            fit_results=dict_ml_results,
                            title='Maximum Likelihood')