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


Python special.xlogy方法代碼示例

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


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

示例1: log_loss

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import xlogy [as 別名]
def log_loss(y_true, y_prob):
    """Compute Logistic loss for classification.

    Parameters
    ----------
    y_true : array-like or label indicator matrix
        Ground truth (correct) labels.

    y_prob : array-like of float, shape = (n_samples, n_classes)
        Predicted probabilities, as returned by a classifier's
        predict_proba method.

    Returns
    -------
    loss : float
        The degree to which the samples are correctly predicted.
    """
    if y_prob.shape[1] == 1:
        y_prob = np.append(1 - y_prob, y_prob, axis=1)

    if y_true.shape[1] == 1:
        y_true = np.append(1 - y_true, y_true, axis=1)

    return - xlogy(y_true, y_prob).sum() / y_prob.shape[0] 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:26,代碼來源:_base.py

示例2: binary_log_loss

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import xlogy [as 別名]
def binary_log_loss(y_true, y_prob):
    """Compute binary logistic loss for classification.

    This is identical to log_loss in binary classification case,
    but is kept for its use in multilabel case.

    Parameters
    ----------
    y_true : array-like or label indicator matrix
        Ground truth (correct) labels.

    y_prob : array-like of float, shape = (n_samples, n_classes)
        Predicted probabilities, as returned by a classifier's
        predict_proba method.

    Returns
    -------
    loss : float
        The degree to which the samples are correctly predicted.
    """
    return -(xlogy(y_true, y_prob) +
             xlogy(1 - y_true, 1 - y_prob)).sum() / y_prob.shape[0] 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:24,代碼來源:_base.py

示例3: _logpdf

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import xlogy [as 別名]
def _logpdf(self, x, alpha):
        """
        Parameters
        ----------
        x : ndarray
            Points at which to evaluate the log of the probability
            density function
        %(_dirichlet_doc_default_callparams)s

        Notes
        -----
        As this function does no argument checking, it should not be
        called directly; use 'logpdf' instead.

        """
        lnB = _lnB(alpha)
        return - lnB + np.sum((xlogy(alpha - 1, x.T)).T, 0) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:19,代碼來源:_multivariate.py

示例4: test_kl_div

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import xlogy [as 別名]
def test_kl_div():
    def xfunc(x, y):
        if x < 0 or y < 0 or (y == 0 and x != 0):
            # extension of natural domain to preserve convexity
            return np.inf
        elif np.isposinf(x) or np.isposinf(y):
            # limits within the natural domain
            return np.inf
        elif x == 0:
            return y
        else:
            return special.xlogy(x, x/y) - x + y
    values = (0, 0.5, 1.0)
    signs = [-1, 1]
    arr = []
    for sgna, va, sgnb, vb in itertools.product(signs, values, signs, values):
        arr.append((sgna*va, sgnb*vb))
    z = np.array(arr, dtype=float)
    w = np.vectorize(xfunc, otypes=[np.float64])(z[:,0], z[:,1])
    assert_func_equal(special.kl_div, w, z, rtol=1e-13, atol=1e-13) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:22,代碼來源:test_basic.py

示例5: test_rel_entr

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import xlogy [as 別名]
def test_rel_entr():
    def xfunc(x, y):
        if x > 0 and y > 0:
            return special.xlogy(x, x/y)
        elif x == 0 and y >= 0:
            return 0
        else:
            return np.inf
    values = (0, 0.5, 1.0)
    signs = [-1, 1]
    arr = []
    for sgna, va, sgnb, vb in itertools.product(signs, values, signs, values):
        arr.append((sgna*va, sgnb*vb))
    z = np.array(arr, dtype=float)
    w = np.vectorize(xfunc, otypes=[np.float64])(z[:,0], z[:,1])
    assert_func_equal(special.rel_entr, w, z, rtol=1e-13, atol=1e-13) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:18,代碼來源:test_basic.py

示例6: compute_score

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import xlogy [as 別名]
def compute_score(self, predictions):
        """
        Compute the score according to the heuristic.

        Args:
            predictions (ndarray): Array of predictions

        Returns:
            Array of scores.
        """
        assert predictions.ndim >= 3
        # [n_sample, n_class, ..., n_iterations]

        expected_entropy = - np.mean(np.sum(xlogy(predictions, predictions), axis=1),
                                     axis=-1)  # [batch size, ...]
        expected_p = np.mean(predictions, axis=-1)  # [batch_size, n_classes, ...]
        entropy_expected_p = - np.sum(xlogy(expected_p, expected_p),
                                      axis=1)  # [batch size, ...]
        bald_acq = entropy_expected_p - expected_entropy
        return bald_acq 
開發者ID:ElementAI,項目名稱:baal,代碼行數:22,代碼來源:heuristics.py

示例7: _h_thin_plate

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import xlogy [as 別名]
def _h_thin_plate(self, r):
        return xlogy(r**2, r)

    # Setup self._function and do smoke test on initial r 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:6,代碼來源:rbf.py

示例8: _logpdf

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import xlogy [as 別名]
def _logpdf(self, x, a, b):
        lPx = sc.xlog1py(b - 1.0, -x) + sc.xlogy(a - 1.0, x)
        lPx -= sc.betaln(a, b)
        return lPx 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:6,代碼來源:_continuous_distns.py

示例9: _logpmf

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import xlogy [as 別名]
def _logpmf(self, x, n, p):
        return gammaln(n+1) + np.sum(xlogy(x, p) - gammaln(x+1), axis=-1) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:4,代碼來源:_multivariate.py

示例10: _logpmf

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import xlogy [as 別名]
def _logpmf(self, x, n, p):
        k = floor(x)
        combiln = (gamln(n+1) - (gamln(k+1) + gamln(n-k+1)))
        return combiln + special.xlogy(k, p) + special.xlog1py(n-k, -p) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:6,代碼來源:_discrete_distns.py

示例11: test_chi2_contingency_g

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import xlogy [as 別名]
def test_chi2_contingency_g():
    c = np.array([[15, 60], [15, 90]])
    g, p, dof, e = chi2_contingency(c, lambda_='log-likelihood', correction=False)
    assert_allclose(g, 2*xlogy(c, c/e).sum())

    g, p, dof, e = chi2_contingency(c, lambda_='log-likelihood', correction=True)
    c_corr = c + np.array([[-0.5, 0.5], [0.5, -0.5]])
    assert_allclose(g, 2*xlogy(c_corr, c_corr/e).sum())

    c = np.array([[10, 12, 10], [12, 10, 10]])
    g, p, dof, e = chi2_contingency(c, lambda_='log-likelihood')
    assert_allclose(g, 2*xlogy(c, c/e).sum()) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:14,代碼來源:test_contingency.py

示例12: test_entropy

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import xlogy [as 別名]
def test_entropy(self):
        # Basic entropy tests.
        b = stats.binom(2, 0.5)
        expected_p = np.array([0.25, 0.5, 0.25])
        expected_h = -sum(xlogy(expected_p, expected_p))
        h = b.entropy()
        assert_allclose(h, expected_h)

        b = stats.binom(2, 0.0)
        h = b.entropy()
        assert_equal(h, 0.0)

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

示例13: test_xlogy

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import xlogy [as 別名]
def test_xlogy():
    def xfunc(x, y):
        if x == 0 and not np.isnan(y):
            return x
        else:
            return x*np.log(y)

    z1 = np.asarray([(0,0), (0, np.nan), (0, np.inf), (1.0, 2.0)], dtype=float)
    z2 = np.r_[z1, [(0, 1j), (1, 1j)]]

    w1 = np.vectorize(xfunc)(z1[:,0], z1[:,1])
    assert_func_equal(special.xlogy, w1, z1, rtol=1e-13, atol=1e-13)
    w2 = np.vectorize(xfunc)(z2[:,0], z2[:,1])
    assert_func_equal(special.xlogy, w2, z2, rtol=1e-13, atol=1e-13) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:16,代碼來源:test_basic.py


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