Пример #1
0
def test_uniform(rnd, loc=0, scale=1):
    # uniform random variate generator
    uniform_dist = RVGs.Uniform(scale=scale, loc=loc)

    # obtain samples
    samples = get_samples(uniform_dist, rnd)

    # report mean and variance
    print_test_results('Uniform',
                       samples,
                       expectation=(2 * loc + scale) / 2.0,
                       variance=scale**2 / 12.0)
Пример #2
0
    def sample_values(self, rng):
        """
        :param rng: random number generator
        :return: (list) values of categories
                (in the example above, [1.4, 0] corresponds to age 1.4 and sex group 0.
        """

        values = []
        idx = self.sample_indices(rng=rng)
        for i, deltaX in enumerate(self.listXDelta):
            if deltaX == 'int':
                values.append(idx[i] + self._list_x_min[i])
            else:
                unif_dist = RVGs.Uniform(loc=0, scale=deltaX)
                values.append(idx[i] * deltaX + self._list_x_min[i] +
                              unif_dist.sample(rng=rng))

        return values
Пример #3
0
def test_fitting_uniform():

    print("\nTesting triangular with scale=10, loc=2")
    dist = RVGs.Uniform(scale=10, loc=2)
    print('  percentile interval: ', dist.get_percentile_interval(alpha=0.05))

    data = np.array(get_samples(dist, np.random))
    dict_mm_results = RVGs.Uniform.fit_mm(mean=np.average(data),
                                          st_dev=np.std(data))
    dict_ml_results = RVGs.Uniform.fit_ml(data=data)

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

    # plot the fitted distributions
    Plot.plot_uniform_fit(data=data,
                          fit_results=dict_mm_results,
                          title='Method of Moment')
    Plot.plot_uniform_fit(data=data,
                          fit_results=dict_ml_results,
                          title='Maximum Likelihood')