コード例 #1
0
    def test_univ_uniform_range(self):
        """
        Distributions: Checks that the univariate uniform dist obeys limits.
        """
        for lower, upper in [(0, 1), (-1, 1), (-1, 5)]:
            dist = UniformDistribution([lower, upper])

            samples = dist.sample(1000)
            assert np.all(samples >= lower)
            assert np.all(samples <= upper)
コード例 #2
0
    def test_univ_uniform_range(self):
        """
        Distributions: Checks that the univariate uniform dist obeys limits.
        """
        for lower, upper in [(0, 1), (-1, 1), (-1, 5)]:
            dist = UniformDistribution([lower, upper])

            samples = dist.sample(1000)
            assert np.all(samples >= lower)
            assert np.all(samples <= upper)
コード例 #3
0
    def test_univ_uniform_moments(self):
        """
        Distributions: Checks that the univ. uniform dist. has the right moments.
        """
        dist = UniformDistribution([[0, 1]])
        samples = dist.sample(10000)

        # We use low-precision checks here, since the error goes as 1/sqrt{N}.
        # Determinism helps us be sure that once we pass, we'll keep passing,
        # but it does nothing to make the moments accurate.
        assert_almost_equal(1 / 12, samples.var(), 2)
        assert_almost_equal(1 / 2, samples.mean(), 2)
コード例 #4
0
    def test_univ_uniform_moments(self):
        """
        Distributions: Checks that the univ. uniform dist. has the right moments.
        """
        dist = UniformDistribution([[0, 1]])
        samples = dist.sample(10000)

        # We use low-precision checks here, since the error goes as 1/sqrt{N}.
        # Determinism helps us be sure that once we pass, we'll keep passing,
        # but it does nothing to make the moments accurate.
        assert_almost_equal(1 / 12, samples.var(), 2)
        assert_almost_equal(1 / 2, samples.mean(), 2)
コード例 #5
0
import logging

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)

model = T1Model()
prior = UniformDistribution(np.array([0, 10]))
N_particles = 1000000
updater = SMCUpdater(
        model, N_particles, prior, resampler=LiuWestResampler(),
        zero_weight_policy='reset'
)
designer = ExperimentDesigner(updater, opt_algo=1)

# Set the value of T1 to Learn, pick 1 value from prior
true_model = prior.sample()
# true_model=np.array([11.032], dtype=model.expparams_dtype)

performance_dtype = [
    ('expparams', 'float'),
    ('sim_outcome', 'float'),
    ('est_mean', 'float'),
]

# NMR EXPERIMENT Initialization*******************************
# going to normalize Mo max of 1.
# model.Mo=float(raw_input('Please enter Mo: '))
# dummy=float(raw_input('Waiting for Mo: '))
# Mo_norm=LF.lorentzfit('1_spectrum.txt')
# model.Mo=(Mo_norm/Mo_norm)
コード例 #6
0
 def test_uniform_shape(self):
     """
     Distributions: Checks that the multivar. uni. dist has the right shape.
     """
     dist = UniformDistribution([[0, 1], [0, 2], [0, 3]])
     assert dist.sample(100).shape == (100, 3)
コード例 #7
0
 def test_uniform_shape(self):
     """
     Distributions: Checks that the multivar. uni. dist has the right shape.
     """
     dist = UniformDistribution([[0, 1], [0, 2], [0, 3]])
     assert dist.sample(100).shape == (100, 3)