本文整理汇总了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))
示例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)
示例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)
示例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]]))
示例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)
示例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))
示例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)])
示例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)])
示例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)
示例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
示例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)
示例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)
示例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()
示例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()
示例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