Ejemplo n.º 1
0
    def get_obj_value(self, x, seed_index=0):
        """ returns one realization from x^2+noise """

        # create a random number generator
        rng = RVGs.RNG(seed=seed_index)

        accum_penalty = 0  # accumulated penalty

        # test the feasibility
        if x[1] < 1:
            accum_penalty += self._penalty * pow(x[1] - 1, 2)
            x[1] = 1

        return (x[0] + 1) * (x[0] + 1) + x[1] * x[1] + self._err.sample(
            rng) + accum_penalty
Ejemplo n.º 2
0
import SimPy.RandomVariateGenerators as rndSupport
from tests.ProbDistributions import RVGtests as Tests

# use numpy random number generator
rng = rndSupport.RNG(1)

print('')

# tests
Tests.test_rng(rng)
Tests.test_bernoulli(rng, p=.2)
Tests.test_beta(rng, a=2, b=5, loc=1, scale=2)
Tests.test_beta(rng, a=0.2, b=0.1, loc=0.5, scale=0.25)
Tests.test_beta_binomial(rng, n=100, a=2, b=3, loc=1)
Tests.test_binomial(rng, n=1000, p=.2, loc=1)
Tests.test_dirichlet(rng, a=[1, 2, 3])
Tests.test_empirical(rng, prob=[0.2, 0.3, 0.5])
Tests.test_exponential(rng, scale=10, loc=1)
Tests.test_gamma(rng, a=2, scale=4, loc=1)
Tests.test_gamma_poisson(rng, a=2, gamma_scale=5, loc=1)
Tests.test_geometric(rng, p=.2, loc=1)
Tests.test_johnsonsb(rng, a=10, b=5, loc=10, scale=100)
Tests.test_johnsonsu(rng, a=10, b=3, loc=1, scale=2)
Tests.test_lognormal(rng, mu=0.2, sigma=0.1, loc=1)
Tests.test_multinomial(rng, n=100, pvals=[.2, 0.3, 0.5])
Tests.test_negative_binomial(rng, n=10, p=.2, loc=1)
Tests.test_non_homogeneous_exponential(rng, rates=[1, 1])
Tests.test_normal(rng, loc=5, scale=1.2)
Tests.test_poisson(rng, mu=2)
Tests.test_triangular(rng, c=0.2, loc=6, scale=7)
Tests.test_uniform(rng, loc=2, scale=7)
Ejemplo n.º 3
0
    def get_obj_value(self, x, seed_index=0):
        """ returns one realization from x^2+noise """
        # create a random number generator
        rng = RVGs.RNG(seed=seed_index)

        return (x[0] + 1) * (x[0] + 1) + x[1] * x[1] + self._err.sample(rng)
Ejemplo n.º 4
0
    [55, 1, 0.035],  # 55-59, female
    [60, 0, 0.029],  # 60-64, male
    [60, 1, 0.031],  # 60-64, female
    [65, 0, 0.024],  # 65-69, male
    [65, 1, 0.027],  # 65-69, female
    [70, 0, 0.018],  # 70-74, male
    [70, 1, 0.027],  # 70-74, female
    [75, 0, 0.012],  # 75-79, male
    [75, 1, 0.015],  # 75-79, female
    [80, 0, 0.008],  # 80-84, male
    [80, 1, 0.011],  # 80-84, female
    [85, 0, 0.007],  # >= 85, male
    [85, 1, 0.013]  # >= 85, female
]

rng = RVGs.RNG(seed=1)
probDf = df.DataFrameWithEmpiricalDist(rows=rows,
                                       list_x_min=[0, 0],
                                       list_x_max=[85, 1],
                                       list_x_delta=[5, 'int'])
# get a sample
print('Get a sampled index:', probDf.sample_indices(rng=rng))
print('Get a sampled index:', probDf.sample_values(rng=rng))
print('')

# testing to make sure sample by index works
counts = [0] * len(rows)
for i in range(5000):
    idx = probDf.sample_indices(rng=rng)
    counts[idx[0] * 2 + idx[1]] += 1