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


Python norm.logpdf方法代碼示例

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


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

示例1: logpdf

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def logpdf(self, rowid, targets, constraints=None, inputs=None):
        constraints = self.populate_constraints(rowid, targets, constraints)
        # XXX Disable logpdf queries without constraints.
        if inputs:
            raise ValueError('Prohibited inputs: %s' % (inputs,))
        if not constraints:
            raise ValueError('Provide at least one constraint: %s'
                % (constraints,))
        self._validate_simulate_logpdf(rowid, targets, constraints)
        # Retrieve the dataset and neighborhoods.
        dataset, neighborhoods = self._find_neighborhoods(targets, constraints)
        models = [self._create_local_model_joint(targets, dataset[n])
            for n in neighborhoods]
        # Compute logpdf in each neighborhood and simple average.
        lp = [m.logpdf(targets) for m in models]
        return gu.logsumexp(lp) - np.log(len(models)) 
開發者ID:probcomp,項目名稱:cgpm,代碼行數:18,代碼來源:mvknn.py

示例2: test_gaussian

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def test_gaussian():

    # Test we can at match a Gaussian distribution from scipy

    mu = 0
    var = 2
    dist = lk.Gaussian()

    x = np.linspace(-10, 10, 100)

    p1 = norm.logpdf(x, loc=mu, scale=np.sqrt(var))
    p2 = dist.loglike(x, mu, var)

    np.allclose(p1, p2)

    p1 = norm.cdf(x, loc=mu, scale=np.sqrt(var))
    p2 = dist.cdf(x, mu, var)

    np.allclose(p1, p2) 
開發者ID:NICTA,項目名稱:revrand,代碼行數:21,代碼來源:test_likelihoods.py

示例3: _event_handler

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def _event_handler(self, manager):
        minibatch_size = 1000
        S = 100
        means, vars = [], []
        for mb in range(-(-len(Xs) // minibatch_size)):
            m, v = model.predict_y(Xs[mb * minibatch_size:(mb + 1) * minibatch_size, :], S)
            means.append(m)
            vars.append(v)
        mean_SND = np.concatenate(means, 1)
        var_SDN = np.concatenate(vars, 1)

        mean_ND = np.average(mean_SND, 0)

        test_err = np.average(Y_std * np.mean((Ys - mean_ND) ** 2.0) ** 0.5)
        test_nll_ND = logsumexp(norm.logpdf(Ys * Y_std, mean_SND * Y_std, var_SDN ** 0.5 * Y_std), 0, b=1 / float(S))
        test_nll = np.average(test_nll_ND)

        summary, step = model.enquire_session().run([self.summary, global_step],
                                                    feed_dict={self._full_test_err: test_err,
                                                               self._full_test_nlpp: test_nll})
        self.file_writer.add_summary(summary, step) 
開發者ID:ICL-SML,項目名稱:Doubly-Stochastic-DGP,代碼行數:23,代碼來源:run_regression.py

示例4: logpdf_joint

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def logpdf_joint(self, x, y):
        return multivariate_normal.logpdf(
            np.array([x,y]), np.array([0,0]),
            np.array([[1,1-self.noise],[1-self.noise,1]])) 
開發者ID:probcomp,項目名稱:cgpm,代碼行數:6,代碼來源:linear.py

示例5: logpdf_marginal

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def logpdf_marginal(self, z):
        return norm.logpdf(z, scale=1) 
開發者ID:probcomp,項目名稱:cgpm,代碼行數:4,代碼來源:linear.py

示例6: logpdf_conditional

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def logpdf_conditional(self, w, z):
        mean = self.conditional_mean(z)
        var = self.conditional_variance(z)
        return norm.logpdf(w, loc=mean, scale=np.sqrt(var)) 
開發者ID:probcomp,項目名稱:cgpm,代碼行數:6,代碼來源:linear.py

示例7: logpdf_joint

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def logpdf_joint(self, x, y):
        return gu.logsumexp([np.log(.25)
                + norm.logpdf(x, loc=mx, scale=self.noise)
                + norm.logpdf(y, loc=my, scale=self.noise)
            for (mx,my) in zip(self.mx, self.my)]) 
開發者ID:probcomp,項目名稱:cgpm,代碼行數:7,代碼來源:dots.py

示例8: logpdf_marginal

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def logpdf_marginal(self, z):
        return gu.logsumexp(
            [np.log(.5) + norm.logpdf(z, loc=mx, scale=self.noise)
            for mx in set(self.mx)]) 
開發者ID:probcomp,項目名稱:cgpm,代碼行數:6,代碼來源:dots.py

示例9: calc_predictive_logp

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def calc_predictive_logp(x, mu, sigma, l, h):
        return norm.logpdf(x, loc=mu, scale=sigma) 
開發者ID:probcomp,項目名稱:cgpm,代碼行數:4,代碼來源:normal_trunc.py

示例10: calc_log_prior

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def calc_log_prior(mu, sigma, alpha, beta, l, h):
        log_sigma = gamma.logpdf(sigma, alpha, scale=beta)
        log_mu = uniform.logpdf(mu, loc=l, scale=l+h)
        return log_mu + log_sigma 
開發者ID:probcomp,項目名稱:cgpm,代碼行數:6,代碼來源:normal_trunc.py

示例11: _create_local_model_joint

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def _create_local_model_joint(self, targets, dataset):
        assert all(q in self.outputs for q in targets)
        assert dataset.shape[1] == len(targets)
        lookup = {
            'numerical': self._create_local_model_numerical,
            'categorical': self._create_local_model_categorical,
            'nominal': self._create_local_model_categorical,
        }
        models = {
            q: lookup[self.stattypes[self.outputs.index(q)]](q, dataset[:,i])
            for i, q in enumerate(targets)}
        simulate = lambda q, N=None: {c: models[c].simulate(N) for c in q}
        logpdf = lambda q: sum(models[c].logpdf(x) for c,x in q.iteritems())
        return LocalGpm(simulate, logpdf) 
開發者ID:probcomp,項目名稱:cgpm,代碼行數:16,代碼來源:mvknn.py

示例12: _create_local_model_numerical

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def _create_local_model_numerical(self, q, locality):
        assert q not in self.levels
        (mu, std) = (np.mean(locality), max(np.std(locality), .01))
        simulate = lambda N=None: self.rng.normal(mu, std, size=N)
        logpdf = lambda x: norm.logpdf(x, mu, std)
        return LocalGpm(simulate, logpdf) 
開發者ID:probcomp,項目名稱:cgpm,代碼行數:8,代碼來源:mvknn.py

示例13: mll

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def mll(y_true, y_pred, y_var):
    """
    Mean log loss under a Gaussian distribution.

    Parameters
    ----------
    y_true: ndarray
        vector of true targets
    y_pred: ndarray
        vector of predicted targets
    y_var: float or ndarray
        predicted variances

    Returns
    -------
    float:
        The mean negative log loss (negative log likelihood)

    Example
    -------
    >>> y_true = np.random.randn(100)
    >>> mean_prob = - norm.logpdf(1e-2, loc=0)  # -ve log prob close to mean
    >>> mll(y_true, y_true, 1) <= mean_prob  # Should be good predictor
    True
    >>> mll(y_true, np.random.randn(100), 1) >= mean_prob  # naive predictor
    True
    """

    return - norm.logpdf(y_true, loc=y_pred, scale=np.sqrt(y_var)).mean() 
開發者ID:NICTA,項目名稱:revrand,代碼行數:31,代碼來源:metrics.py

示例14: msll

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def msll(y_true, y_pred, y_var, y_train):
    """
    Mean standardised log loss under a Gaussian distribution.

    Parameters
    ----------
    y_true: ndarray
        vector of true targets
    y_pred: ndarray
        vector of predicted targets
    y_var: float or ndarray
        predicted variances
    y_train: ndarray
        vector of *training* targets by which to standardise

    Returns
    -------
    float:
        The negative mean standardised log loss (negative log likelihood)

    Example
    -------
    >>> y_true = np.random.randn(100)
    >>> msll(y_true, y_true, 1, y_true) < 0  # Should be good predictor
    True
    >>> msll(y_true, np.random.randn(100), 1, y_true) >= 0  # naive predictor
    True
    """

    var = y_train.var()
    mu = y_train.mean()

    ll_naive = norm.logpdf(y_true, loc=mu, scale=np.sqrt(var))
    ll_mod = norm.logpdf(y_true, loc=y_pred, scale=np.sqrt(y_var))

    return - (ll_mod - ll_naive).mean() 
開發者ID:NICTA,項目名稱:revrand,代碼行數:38,代碼來源:metrics.py

示例15: loglike

# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import logpdf [as 別名]
def loglike(self, y, f, var=None):
        r"""
        Gaussian log likelihood.

        Parameters
        ----------
        y: ndarray
            array of 0, 1 valued integers of targets
        f: ndarray
            latent function from the GLM prior (:math:`\mathbf{f} =
            \boldsymbol\Phi \mathbf{w}`)
        var: float, ndarray, optional
            The variance of the distribution, if not input, the initial value
            of variance is used.

        Returns
        -------
        logp: ndarray
            the log likelihood of each y given each f under this
            likelihood.
        """
        # way faster than calling norm.logpdf
        var = self._check_param(var)
        y, f = np.broadcast_arrays(y, f)
        ll = - 0.5 * (np.log(2 * np.pi * var) + (y - f)**2 / var)
        return ll 
開發者ID:NICTA,項目名稱:revrand,代碼行數:28,代碼來源:likelihoods.py


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