示例#1
0
def test_triangular(rnd, c, loc=0, scale=1):
    # triangular random variate generator
    triangular_dist = RVGs.Triangular(c, loc, scale)

    # obtain samples
    samples = get_samples(triangular_dist, rnd)

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

    # report mean and variance
    print_test_results('Triangular',
                       samples,
                       expectation=(3 * loc + scale + c * scale) / 3.0,
                       variance=var)
示例#2
0
def test_fitting_triangular():

    print("\nTesting triangular with c=0.2, loc=6, scale=7")
    dist = RVGs.Triangular(c=0.2, loc=6, scale=7)
    print('  percentile interval: ', dist.get_percentile_interval(alpha=0.05))

    data = np.array(get_samples(dist, np.random))
    dict_ml_results = RVGs.Triangular.fit_ml(data=data, fixed_location=6)

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

    # plot the fitted distributions
    Plot.plot_triangular_fit(data=data,
                             fit_results=dict_ml_results,
                             title='Maximum Likelihood')