Ejemplo n.º 1
0
def test_weibull(rnd, a, loc=0, scale=1):
    # weibull random variate generator
    weibull_dist = RVGs.Weibull(a=a, scale=scale, loc=loc)

    # obtain samples
    samples = get_samples(weibull_dist, rnd)

    # get theoretical variance
    var = scipy.weibull_min.stats(a, loc, scale, moments='v')
    var = np.asarray(var).item()

    # report mean and variance
    print_test_results('Weibull',
                       samples,
                       expectation=math.gamma(1.0 + 1 / a) * scale + loc,
                       variance=var)
Ejemplo n.º 2
0
def test_fitting_weibull():

    print("\nTesting Weibull with a=5, scale=2, loc=1")
    dist = RVGs.Weibull(a=5, scale=2, loc=1)
    print('  percentile interval: ', dist.get_percentile_interval(alpha=0.05))

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