def test_negative_binomial(rnd, n, p, loc=0): # negative bimonial random variate generator negative_binomial_dist = RVGs.NegativeBinomial(n, p, loc) # obtain samples samples = get_samples(negative_binomial_dist, rnd) # get theoretical mean and variance mean = scipy.nbinom.stats(n, p, loc, moments='m') mean = np.asarray(mean).item() var = scipy.nbinom.stats(n, p, loc, moments='v') var = np.asarray(var).item() # report mean and variance print_test_results('Negative Binomial', samples, expectation=mean, variance=var)
# 10 fitting a JohnsonSu distribution dist = RVGs.JohnsonSu(a=10, b=3, loc=1, scale=2) dat_JohnsonSu = np.array(get_samples(dist, np.random)) # generate data dictResults = Fit.fit_johnsonSu(dat_JohnsonSu, 'Data', fixed_location=1) # fit print("Fitting johnsonSu:", dictResults) # 11 LogNormal dist = RVGs.LogNormal(s=1, loc=1, scale=2) dat_lognorm = np.array(get_samples(dist, np.random)) # mean, sigma dictResults = Fit.fit_lognorm(dat_lognorm, 'Data', fixed_location=1) # fit (scale=exp(mean)) print("Fitting LogNormal:", dictResults) # 12 NegativeBinomial dist = RVGs.NegativeBinomial(3, 0.3, 1) dat_neg_bin = np.array(get_samples(dist, np.random)) # mean, sigma dictResults = Fit.fit_negative_binomial(dat_neg_bin, 'Data', fixed_location=1) print("Fitting NegativeBinomial:", dictResults) # 13 Normal dist = RVGs.Normal(0, 1) dat_norm = np.array(get_samples(dist, np.random)) # mean, sigma dictResults = Fit.fit_normal(dat_norm, 'Data') # fit print("Fitting Normal:", dictResults) # 14 Triangular dist = RVGs.Triangular(0.5, loc=1, scale=2) dat_tri = np.array(get_samples(dist, np.random)) dictResults = Fit.fit_triang(dat_tri, 'Data', fixed_location=1) # fit print("Fitting Triangular:", dictResults)