当前位置: 首页>>代码示例>>Python>>正文


Python stats.uniform方法代码示例

本文整理汇总了Python中scipy.stats.uniform方法的典型用法代码示例。如果您正苦于以下问题:Python stats.uniform方法的具体用法?Python stats.uniform怎么用?Python stats.uniform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.stats的用法示例。


在下文中一共展示了stats.uniform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: likelihood

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def likelihood(parameter_vector):

    parameter_vector = 10**np.array(parameter_vector)

    #Solve ODE system given parameter vector
    yout = odeint(odefunc, y0, tspan, args=(parameter_vector,))

    cout = yout[:, 2]

    #Calculate log probability contribution given simulated experimental values.
    
    logp_ctotal = np.sum(like_ctot.logpdf(cout))
    
    #If simulation failed due to integrator errors, return a log probability of -inf.
    if np.isnan(logp_ctotal):
        logp_ctotal = -np.inf
      
    return logp_ctotal


# Add vector of rate parameters to be sampled as unobserved random variables in DREAM with uniform priors. 
开发者ID:LoLab-VU,项目名称:PyDREAM,代码行数:23,代码来源:example_sample_robertson_nopysb_with_dream.py

示例2: test_param_sampler

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def test_param_sampler():
    # test basic properties of param sampler
    param_distributions = {"kernel": ["rbf", "linear"],
                           "C": uniform(0, 1)}
    sampler = ParameterSampler(param_distributions=param_distributions,
                               n_iter=10, random_state=0)
    samples = [x for x in sampler]
    assert_equal(len(samples), 10)
    for sample in samples:
        assert sample["kernel"] in ["rbf", "linear"]
        assert 0 <= sample["C"] <= 1

    # test that repeated calls yield identical parameters
    param_distributions = {"C": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]}
    sampler = ParameterSampler(param_distributions=param_distributions,
                               n_iter=3, random_state=0)
    assert_equal([x for x in sampler], [x for x in sampler])

    if sp_version >= (0, 16):
        param_distributions = {"C": uniform(0, 1)}
        sampler = ParameterSampler(param_distributions=param_distributions,
                                   n_iter=10, random_state=0)
        assert_equal([x for x in sampler], [x for x in sampler]) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:25,代码来源:test_search.py

示例3: setUp_configure

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def setUp_configure(self):
        from scipy import stats
        self.dist = distributions.Uniform
        self.scipy_dist = stats.uniform

        self.test_targets = set([
            'batch_shape', 'cdf', 'entropy', 'event_shape', 'icdf', 'log_prob',
            'mean', 'sample', 'stddev', 'support', 'variance'])

        if self.use_loc_scale:
            loc = numpy.random.uniform(
                -10, 0, self.shape).astype(numpy.float32)
            scale = numpy.random.uniform(
                0, 10, self.shape).astype(numpy.float32)
            self.params = {'loc': loc, 'scale': scale}
            self.scipy_params = {'loc': loc, 'scale': scale}
        else:
            low = numpy.random.uniform(
                -10, 0, self.shape).astype(numpy.float32)
            high = numpy.random.uniform(
                low, low + 10, self.shape).astype(numpy.float32)
            self.params = {'low': low, 'high': high}
            self.scipy_params = {'loc': low, 'scale': high-low}

        self.support = '[low, high]' 
开发者ID:chainer,项目名称:chainer,代码行数:27,代码来源:test_uniform.py

示例4: _construct_generator_obj

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def _construct_generator_obj(self, C_tv_range, C_group_l1_range,
                                 logspace=True):
        generators = []
        if len(C_tv_range) == 2:
            if logspace:
                generators.append(Log10UniformGenerator(*C_tv_range))
            else:
                generators.append(uniform(C_tv_range))
        else:
            generators.append(null_generator)

        if len(C_group_l1_range) == 2:
            if logspace:
                generators.append(Log10UniformGenerator(*C_group_l1_range))
            else:
                generators.append(uniform(C_group_l1_range))
        else:
            generators.append(null_generator)

        return generators

    # Properties # 
开发者ID:X-DataInitiative,项目名称:tick,代码行数:24,代码来源:convolutional_sccs.py

示例5: test_frozen_dirichlet

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def test_frozen_dirichlet(self):
        np.random.seed(2846)

        n = np.random.randint(1, 32)
        alpha = np.random.uniform(10e-10, 100, n)

        d = dirichlet(alpha)

        assert_equal(d.var(), dirichlet.var(alpha))
        assert_equal(d.mean(), dirichlet.mean(alpha))
        assert_equal(d.entropy(), dirichlet.entropy(alpha))
        num_tests = 10
        for i in range(num_tests):
            x = np.random.uniform(10e-10, 100, n)
            x /= np.sum(x)
            assert_equal(d.pdf(x[:-1]), dirichlet.pdf(x[:-1], alpha))
            assert_equal(d.logpdf(x[:-1]), dirichlet.logpdf(x[:-1], alpha)) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:19,代码来源:test_multivariate.py

示例6: test_pairwise_distances

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def test_pairwise_distances(self):
        # Test that the distribution of pairwise distances is close to correct.
        np.random.seed(514)

        def random_ortho(dim):
            u, _s, v = np.linalg.svd(np.random.normal(size=(dim, dim)))
            return np.dot(u, v)

        for dim in range(2, 6):
            def generate_test_statistics(rvs, N=1000, eps=1e-10):
                stats = np.array([
                    np.sum((rvs(dim=dim) - rvs(dim=dim))**2)
                    for _ in range(N)
                ])
                # Add a bit of noise to account for numeric accuracy.
                stats += np.random.uniform(-eps, eps, size=stats.shape)
                return stats

            expected = generate_test_statistics(random_ortho)
            actual = generate_test_statistics(scipy.stats.ortho_group.rvs)

            _D, p = scipy.stats.ks_2samp(expected, actual)

            assert_array_less(.05, p) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:26,代码来源:test_multivariate.py

示例7: test_haar

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def test_haar(self):
        # Test that the eigenvalues, which lie on the unit circle in
        # the complex plane, are uncorrelated.

        # Generate samples
        dim = 5
        samples = 1000  # Not too many, or the test takes too long
        np.random.seed(514)  # Note that the test is sensitive to seed too
        xs = unitary_group.rvs(dim, size=samples)

        # The angles "x" of the eigenvalues should be uniformly distributed
        # Overall this seems to be a necessary but weak test of the distribution.
        eigs = np.vstack(scipy.linalg.eigvals(x) for x in xs)
        x = np.arctan2(eigs.imag, eigs.real)
        res = kstest(x.ravel(), uniform(-np.pi, 2*np.pi).cdf)
        assert_(res.pvalue > 0.05) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:18,代码来源:test_multivariate.py

示例8: test_randomizedsearchcv_best_estimator

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def test_randomizedsearchcv_best_estimator(u1_ml100k):
    """Ensure that the best estimator is the one that gives the best score (by
    re-running it)"""

    param_distributions = {'n_epochs': [5], 'lr_all': uniform(0.002, 0.003),
                           'reg_all': uniform(0.04, 0.02), 'n_factors': [1],
                           'init_std_dev': [0]}
    rs = RandomizedSearchCV(SVD, param_distributions, measures=['mae'],
                            cv=PredefinedKFold(), joblib_verbose=100)
    rs.fit(u1_ml100k)
    best_estimator = rs.best_estimator['mae']

    # recompute MAE of best_estimator
    mae = cross_validate(best_estimator, u1_ml100k, measures=['MAE'],
                         cv=PredefinedKFold())['test_mae']

    assert mae == rs.best_score['mae'] 
开发者ID:NicolasHug,项目名称:Surprise,代码行数:19,代码来源:test_search.py

示例9: testUniformPDF

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def testUniformPDF(self):
    with self.test_session():
      a = tf.constant([-3.0] * 5 + [15.0])
      b = tf.constant([11.0] * 5 + [20.0])
      uniform = tf.contrib.distributions.Uniform(a=a, b=b)

      a_v = -3.0
      b_v = 11.0
      x = np.array([-10.5, 4.0, 0.0, 10.99, 11.3, 17.0], dtype=np.float32)

      def _expected_pdf():
        pdf = np.zeros_like(x) + 1.0 / (b_v - a_v)
        pdf[x > b_v] = 0.0
        pdf[x < a_v] = 0.0
        pdf[5] = 1.0 / (20.0 - 15.0)
        return pdf

      expected_pdf = _expected_pdf()

      pdf = uniform.pdf(x)
      self.assertAllClose(expected_pdf, pdf.eval())

      log_pdf = uniform.log_pdf(x)
      self.assertAllClose(np.log(expected_pdf), log_pdf.eval()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:26,代码来源:uniform_test.py

示例10: testUniformCDF

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def testUniformCDF(self):
    with self.test_session():
      batch_size = 6
      a = tf.constant([1.0] * batch_size)
      b = tf.constant([11.0] * batch_size)
      a_v = 1.0
      b_v = 11.0
      x = np.array([-2.5, 2.5, 4.0, 0.0, 10.99, 12.0], dtype=np.float32)

      uniform = tf.contrib.distributions.Uniform(a=a, b=b)

      def _expected_cdf():
        cdf = (x - a_v) / (b_v - a_v)
        cdf[x >= b_v] = 1
        cdf[x < a_v] = 0
        return cdf

      cdf = uniform.cdf(x)
      self.assertAllClose(_expected_cdf(), cdf.eval())

      log_cdf = uniform.log_cdf(x)
      self.assertAllClose(np.log(_expected_cdf()), log_cdf.eval()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:24,代码来源:uniform_test.py

示例11: testUniformSample

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def testUniformSample(self):
    with self.test_session():
      a = tf.constant([3.0, 4.0])
      b = tf.constant(13.0)
      a1_v = 3.0
      a2_v = 4.0
      b_v = 13.0
      n = tf.constant(100000)
      uniform = tf.contrib.distributions.Uniform(a=a, b=b)

      samples = uniform.sample(n, seed=137)
      sample_values = samples.eval()
      self.assertEqual(sample_values.shape, (100000, 2))
      self.assertAllClose(sample_values[::, 0].mean(), (b_v + a1_v) / 2,
                          atol=1e-2)
      self.assertAllClose(sample_values[::, 1].mean(), (b_v + a2_v) / 2,
                          atol=1e-2)
      self.assertFalse(np.any(sample_values[::, 0] < a1_v) or np.any(
          sample_values >= b_v))
      self.assertFalse(np.any(sample_values[::, 1] < a2_v) or np.any(
          sample_values >= b_v)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:23,代码来源:uniform_test.py

示例12: testUniformNans

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def testUniformNans(self):
    with self.test_session():
      a = 10.0
      b = [11.0, 100.0]
      uniform = tf.contrib.distributions.Uniform(a=a, b=b)

      no_nans = tf.constant(1.0)
      nans = tf.constant(0.0) / tf.constant(0.0)
      self.assertTrue(tf.is_nan(nans).eval())
      with_nans = tf.stack([no_nans, nans])

      pdf = uniform.pdf(with_nans)

      is_nan = tf.is_nan(pdf).eval()
      self.assertFalse(is_nan[0])
      self.assertTrue(is_nan[1]) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:18,代码来源:uniform_test.py

示例13: testUniformSampleWithShape

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def testUniformSampleWithShape(self):
    with self.test_session():
      a = 10.0
      b = [11.0, 20.0]
      uniform = tf.contrib.distributions.Uniform(a, b)

      pdf = uniform.pdf(uniform.sample((2, 3)))
      # pylint: disable=bad-continuation
      expected_pdf = [
        [[1.0, 0.1],
         [1.0, 0.1],
         [1.0, 0.1]],
        [[1.0, 0.1],
         [1.0, 0.1],
         [1.0, 0.1]],
      ]
      # pylint: enable=bad-continuation
      self.assertAllClose(expected_pdf, pdf.eval())

      pdf = uniform.pdf(uniform.sample())
      expected_pdf = [1.0, 0.1]
      self.assertAllClose(expected_pdf, pdf.eval()) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:24,代码来源:uniform_test.py

示例14: __init__

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def __init__(self, lower, upper):
        self.lower = lower
        self.upper = upper
        self.bounds = np.array([-1.0, 1.0])
        if (self.lower is None) or (self.upper is None):
            print('One or more bounds not specified. Assuming [0, 1].')
            self.lower = 0.0
            self.upper = 1.0
        self.mean = 0.5 * (self.upper + self.lower)
        self.variance = 1.0/12.0 * (self.upper - self.lower)**2
        self.x_range_for_pdf = np.linspace(self.lower, self.upper, RECURRENCE_PDF_SAMPLES)
        self.parent = uniform(loc=(self.lower), scale=(self.upper-self.lower))

        self.skewness = 0.0
        self.shape_parameter_A = 0.
        self.shape_parameter_B = 0. 
开发者ID:Effective-Quadratures,项目名称:Effective-Quadratures,代码行数:18,代码来源:uniform.py

示例15: get_cdf

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import uniform [as 别名]
def get_cdf(self, points=None):
        """
        A uniform cumulative density function.
        :param points:
                Matrix of points which have to be evaluated
        :param double lower:
            Lower bound of the support of the uniform distribution.
        :param double upper:
            Upper bound of the support of the uniform distribution.
        :return:
            An array of N equidistant values over the support of the distribution.
        :return:
            Cumulative density values along the support of the uniform distribution.
        """
        if points is not None:
            return self.parent.cdf(points)
        else:
            raise ValueError( 'Please digit an input for getCDF method') 
开发者ID:Effective-Quadratures,项目名称:Effective-Quadratures,代码行数:20,代码来源:uniform.py


注:本文中的scipy.stats.uniform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。