def test_uniform_discrete(rnd, l, u): # uniform discrete random variate generator uniformdiscrete_dist = RVGs.UniformDiscrete(l, u) # obtain samples samples = get_samples(uniformdiscrete_dist, rnd) # report mean and variance print_test_results('Uniform Discrete', samples, expectation=(l + u) / 2.0, variance=((u - l + 1)**2 - 1) / 12.0)
def utility_sample_stat(utility, d_cost_samples, d_effect_samples, wtp_random_variate, n_samples, rnd): discrete_rnd = RVG.UniformDiscrete(l=0, u=len(d_cost_samples) - 1) samples = [] for i in range(n_samples): j = discrete_rnd.sample(rnd) u = utility(d_effect=d_effect_samples[j], d_cost=d_cost_samples[j]) w = wtp_random_variate.sample(rnd) samples.append(u(w)) return Stat.SummaryStat(name='', data=samples)
def test_fitting_uniform_discrete(): print("\nTesting uniform discrete with l=10, u=18") dist = RVGs.UniformDiscrete(l=10, u=18) print(' percentile interval: ', dist.get_percentile_interval(alpha=0.05)) data = np.array(get_samples(dist, np.random)) dict_mm_results = RVGs.UniformDiscrete.fit_mm(mean=np.average(data), st_dev=np.std(data)) dict_ml_results = RVGs.UniformDiscrete.fit_ml(data=data) print(" Fit:") print(" MM:", dict_mm_results) print(" ML:", dict_ml_results) # plot the fitted distributions Plot.plot_uniform_discrete_fit(data=data, fit_results=dict_mm_results, title='Method of Moment') Plot.plot_uniform_discrete_fit(data=data, fit_results=dict_ml_results, title='Maximum Likelihood')