當前位置: 首頁>>代碼示例>>Python>>正文


Python stats.bernoulli方法代碼示例

本文整理匯總了Python中scipy.stats.bernoulli方法的典型用法代碼示例。如果您正苦於以下問題:Python stats.bernoulli方法的具體用法?Python stats.bernoulli怎麽用?Python stats.bernoulli使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.stats的用法示例。


在下文中一共展示了stats.bernoulli方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_nan_arguments_gh_issue_1362

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def test_nan_arguments_gh_issue_1362():
    assert_(np.isnan(stats.t.logcdf(1, np.nan)))
    assert_(np.isnan(stats.t.cdf(1, np.nan)))
    assert_(np.isnan(stats.t.logsf(1, np.nan)))
    assert_(np.isnan(stats.t.sf(1, np.nan)))
    assert_(np.isnan(stats.t.pdf(1, np.nan)))
    assert_(np.isnan(stats.t.logpdf(1, np.nan)))
    assert_(np.isnan(stats.t.ppf(1, np.nan)))
    assert_(np.isnan(stats.t.isf(1, np.nan)))

    assert_(np.isnan(stats.bernoulli.logcdf(np.nan, 0.5)))
    assert_(np.isnan(stats.bernoulli.cdf(np.nan, 0.5)))
    assert_(np.isnan(stats.bernoulli.logsf(np.nan, 0.5)))
    assert_(np.isnan(stats.bernoulli.sf(np.nan, 0.5)))
    assert_(np.isnan(stats.bernoulli.pmf(np.nan, 0.5)))
    assert_(np.isnan(stats.bernoulli.logpmf(np.nan, 0.5)))
    assert_(np.isnan(stats.bernoulli.ppf(np.nan, 0.5)))
    assert_(np.isnan(stats.bernoulli.isf(np.nan, 0.5))) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:20,代碼來源:test_distributions.py

示例2: setUp_configure

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def setUp_configure(self):
        from scipy import stats
        self.dist = distributions.Bernoulli
        self.scipy_dist = stats.bernoulli
        self.options = {'binary_check': self.binary_check}

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

        if self.extreme_values:
            p = numpy.random.randint(0, 2, self.shape).astype(numpy.float32)
        else:
            p = numpy.random.uniform(0, 1, self.shape).astype(numpy.float32)

        self.params = {'p': p}
        self.scipy_params = {'p': p}

        self.support = '{0, 1}'
        self.continuous = False

        self.old_settings = None
        if self.extreme_values:
            self.old_settings = numpy.seterr(divide='ignore', invalid='ignore') 
開發者ID:chainer,項目名稱:chainer,代碼行數:26,代碼來源:test_bernoulli.py

示例3: test_nan_arguments_gh_issue_1362

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def test_nan_arguments_gh_issue_1362():
    with np.errstate(invalid='ignore'):
        assert_(np.isnan(stats.t.logcdf(1, np.nan)))
        assert_(np.isnan(stats.t.cdf(1, np.nan)))
        assert_(np.isnan(stats.t.logsf(1, np.nan)))
        assert_(np.isnan(stats.t.sf(1, np.nan)))
        assert_(np.isnan(stats.t.pdf(1, np.nan)))
        assert_(np.isnan(stats.t.logpdf(1, np.nan)))
        assert_(np.isnan(stats.t.ppf(1, np.nan)))
        assert_(np.isnan(stats.t.isf(1, np.nan)))

        assert_(np.isnan(stats.bernoulli.logcdf(np.nan, 0.5)))
        assert_(np.isnan(stats.bernoulli.cdf(np.nan, 0.5)))
        assert_(np.isnan(stats.bernoulli.logsf(np.nan, 0.5)))
        assert_(np.isnan(stats.bernoulli.sf(np.nan, 0.5)))
        assert_(np.isnan(stats.bernoulli.pmf(np.nan, 0.5)))
        assert_(np.isnan(stats.bernoulli.logpmf(np.nan, 0.5)))
        assert_(np.isnan(stats.bernoulli.ppf(np.nan, 0.5)))
        assert_(np.isnan(stats.bernoulli.isf(np.nan, 0.5))) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:21,代碼來源:test_distributions.py

示例4: __init__

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def __init__(self, parameters, name='Bernoulli'):
        """This class implements a probabilistic model following a bernoulli distribution.

        Parameters
        ----------
        parameters: list
             A list containing one entry, the probability of the distribution.

        name: string
            The name that should be given to the probabilistic model in the journal file.
        """

        if not isinstance(parameters, list):
            raise TypeError('Input for Bernoulli has to be of type list.')
        if len(parameters)!=1:
            raise ValueError('Input for Bernoulli has to be of length 1.')

        self._dimension = len(parameters)
        input_parameters = InputConnector.from_list(parameters)
        super(Bernoulli, self).__init__(input_parameters, name)
        self.visited = False 
開發者ID:eth-cscs,項目名稱:abcpy,代碼行數:23,代碼來源:discretemodels.py

示例5: forward_simulate

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def forward_simulate(self, input_values, k, rng=np.random.RandomState(), mpi_comm=None):
        """
        Samples from the bernoulli distribution associtated with the probabilistic model.

        Parameters
        ----------
        input_values: list
            List of input parameters, in the same order as specified in the InputConnector passed to the init function
        k: integer
            The number of samples to be drawn.
        rng: random number generator
            The random number generator to be used.

        Returns
        -------
        list: [np.ndarray]
            A list containing the sampled values as np-array.
        """

        result = np.array(rng.binomial(1, input_values[0], k))
        return [np.array([x]) for x in result] 
開發者ID:eth-cscs,項目名稱:abcpy,代碼行數:23,代碼來源:discretemodels.py

示例6: pmf

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def pmf(self, input_values, x):
        """Evaluates the probability mass function at point x.

        Parameters
        ----------
        input_values: list
            List of input parameters, in the same order as specified in the InputConnector passed to the init function
        x: float
            The point at which the pmf should be evaluated.

        Returns
        -------
        float:
            The pmf evaluated at point x.
        """
        probability = input_values[0]
        pmf = bernoulli(probability).pmf(x)
        self.calculated_pmf = pmf
        return pmf 
開發者ID:eth-cscs,項目名稱:abcpy,代碼行數:21,代碼來源:discretemodels.py

示例7: bernoulli_pmf

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def bernoulli_pmf(p=0.0):
    """
    伯努利分布,隻有一個參數
    https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.bernoulli.html#scipy.stats.bernoulli
    :param p: 試驗成功的概率,或結果為1的概率
    :return:
    """
    ber_dist = stats.bernoulli(p)
    x = [0, 1]
    x_name = ['0', '1']
    pmf = [ber_dist.pmf(x[0]), ber_dist.pmf(x[1])]
    plt.bar(x, pmf, width=0.15)
    plt.xticks(x, x_name)
    plt.ylabel('Probability')
    plt.title('PMF of bernoulli distribution')
    plt.show()

# bernoulli_pmf(p=0.3) 
開發者ID:OnlyBelter,項目名稱:machine-learning-note,代碼行數:20,代碼來源:draw_pmf.py

示例8: test_rvs

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def test_rvs(self):
        vals = stats.bernoulli.rvs(0.75, size=(2, 50))
        assert_(numpy.all(vals >= 0) & numpy.all(vals <= 1))
        assert_(numpy.shape(vals) == (2, 50))
        assert_(vals.dtype.char in typecodes['AllInteger'])
        val = stats.bernoulli.rvs(0.75)
        assert_(isinstance(val, int))
        val = stats.bernoulli(0.75).rvs(3)
        assert_(isinstance(val, numpy.ndarray))
        assert_(val.dtype.char in typecodes['AllInteger']) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:12,代碼來源:test_distributions.py

示例9: test_entropy

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def test_entropy(self):
        # Simple tests of entropy.
        b = stats.bernoulli(0.25)
        expected_h = -0.25*np.log(0.25) - 0.75*np.log(0.75)
        h = b.entropy()
        assert_allclose(h, expected_h)

        b = stats.bernoulli(0.0)
        h = b.entropy()
        assert_equal(h, 0.0)

        b = stats.bernoulli(1.0)
        h = b.entropy()
        assert_equal(h, 0.0) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:16,代碼來源:test_distributions.py

示例10: test_docstrings

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def test_docstrings(self):
        # See ticket #761
        if stats.rayleigh.__doc__ is not None:
            self.assertTrue("rayleigh" in stats.rayleigh.__doc__.lower())
        if stats.bernoulli.__doc__ is not None:
            self.assertTrue("bernoulli" in stats.bernoulli.__doc__.lower()) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:8,代碼來源:test_distributions.py

示例11: test_parameters_sampler_replacement

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def test_parameters_sampler_replacement():
    # raise warning if n_iter is bigger than total parameter space
    params = {'first': [0, 1], 'second': ['a', 'b', 'c']}
    sampler = ParameterSampler(params, n_iter=7)
    n_iter = 7
    grid_size = 6
    expected_warning = ('The total space of parameters %d is smaller '
                        'than n_iter=%d. Running %d iterations. For '
                        'exhaustive searches, use GridSearchCV.'
                        % (grid_size, n_iter, grid_size))
    assert_warns_message(UserWarning, expected_warning,
                         list, sampler)

    # degenerates to GridSearchCV if n_iter the same as grid_size
    sampler = ParameterSampler(params, n_iter=6)
    samples = list(sampler)
    assert_equal(len(samples), 6)
    for values in ParameterGrid(params):
        assert values in samples

    # test sampling without replacement in a large grid
    params = {'a': range(10), 'b': range(10), 'c': range(10)}
    sampler = ParameterSampler(params, n_iter=99, random_state=42)
    samples = list(sampler)
    assert_equal(len(samples), 99)
    hashable_samples = ["a%db%dc%d" % (p['a'], p['b'], p['c'])
                        for p in samples]
    assert_equal(len(set(hashable_samples)), 99)

    # doesn't go into infinite loops
    params_distribution = {'first': bernoulli(.5), 'second': ['a', 'b', 'c']}
    sampler = ParameterSampler(params_distribution, n_iter=7)
    samples = list(sampler)
    assert_equal(len(samples), 7) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:36,代碼來源:test_search.py

示例12: check_forward

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def check_forward(self, logit_data, x_data):
        distributions.bernoulli._bernoulli_log_prob(logit_data, x_data) 
開發者ID:chainer,項目名稱:chainer,代碼行數:4,代碼來源:test_bernoulli.py

示例13: check_backward

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def check_backward(self, logit_data, x_data, y_grad):
        def f(logit):
            return distributions.bernoulli._bernoulli_log_prob(
                logit, x_data)
        gradient_check.check_backward(
            f, logit_data, y_grad, **self.backward_options) 
開發者ID:chainer,項目名稱:chainer,代碼行數:8,代碼來源:test_bernoulli.py

示例14: check_double_backward

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def check_double_backward(self, logit_data, x_data, y_grad, x_grad_grad):
        def f(logit):
            return distributions.bernoulli._bernoulli_log_prob(
                logit, x_data)
        gradient_check.check_double_backward(
            f, logit_data, y_grad, x_grad_grad, dtype=numpy.float64,
            **self.backward_options) 
開發者ID:chainer,項目名稱:chainer,代碼行數:9,代碼來源:test_bernoulli.py

示例15: test_backward_where_logit_has_infinite_values

# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import bernoulli [as 別名]
def test_backward_where_logit_has_infinite_values(self):
        self.logit[...] = numpy.inf
        with numpy.errstate(invalid='ignore'):
            log_prob = distributions.bernoulli._bernoulli_log_prob(
                self.logit, self.x)

        # just confirm that the backward method runs without raising error.
        log_prob.backward() 
開發者ID:chainer,項目名稱:chainer,代碼行數:10,代碼來源:test_bernoulli.py


注:本文中的scipy.stats.bernoulli方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。