本文整理匯總了Python中scipy.stats.norm.pdf方法的典型用法代碼示例。如果您正苦於以下問題:Python norm.pdf方法的具體用法?Python norm.pdf怎麽用?Python norm.pdf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scipy.stats.norm
的用法示例。
在下文中一共展示了norm.pdf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: lnprob
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def lnprob(self, theta):
lp = 0
# Covariance amplitude
lp += self.ln_prior.lnprob(theta[0])
# Lengthscales
lp += self.tophat.lnprob(theta[1:self.n_ls + 1])
# Prior for the Bayesian regression kernel
pos = (self.n_ls + 1)
end = (self.n_ls + self.n_lr + 1)
lp += -np.sum((theta[pos:end]) ** 2 / 10.)
# alpha
lp += norm.pdf(theta[end], loc=-7, scale=1)
# beta
lp += norm.pdf(theta[end + 1], loc=0.5, scale=1)
# Noise
lp += self.horseshoe.lnprob(theta[-1])
return lp
示例2: encode_extreme_points
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def encode_extreme_points(mask, use_gaussian):
nz = mask.nonzero()
assert nz[0].size > 0, "mask cannot be empty"
ymin_idx = nz[0].argmin()
ymax_idx = nz[0].argmax()
xmin_idx = nz[1].argmin()
xmax_idx = nz[1].argmax()
ymin = (nz[0][ymin_idx], nz[1][ymin_idx])
ymax = (nz[0][ymax_idx], nz[1][ymax_idx])
xmin = (nz[0][xmin_idx], nz[1][xmin_idx])
xmax = (nz[0][xmax_idx], nz[1][xmax_idx])
pts = (ymin, ymax, xmin, xmax)
distance_transform_extreme_pts = get_distance_transform(pts, mask)
distance_transform_extreme_pts[distance_transform_extreme_pts > 20] = 20
if use_gaussian:
distance_transform_extreme_pts = norm.pdf(distance_transform_extreme_pts, loc=0, scale=10) * 25
else:
distance_transform_extreme_pts /= 20.0
return distance_transform_extreme_pts.astype(np.float32)
示例3: test_marginalization
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def test_marginalization(self):
# Integrating out one of the variables of a 2D Gaussian should
# yield a 1D Gaussian
mean = np.array([2.5, 3.5])
cov = np.array([[.5, 0.2], [0.2, .6]])
n = 2 ** 8 + 1 # Number of samples
delta = 6 / (n - 1) # Grid spacing
v = np.linspace(0, 6, n)
xv, yv = np.meshgrid(v, v)
pos = np.empty((n, n, 2))
pos[:, :, 0] = xv
pos[:, :, 1] = yv
pdf = multivariate_normal.pdf(pos, mean, cov)
# Marginalize over x and y axis
margin_x = romb(pdf, delta, axis=0)
margin_y = romb(pdf, delta, axis=1)
# Compare with standard normal distribution
gauss_x = norm.pdf(v, loc=mean[0], scale=cov[0, 0] ** 0.5)
gauss_y = norm.pdf(v, loc=mean[1], scale=cov[1, 1] ** 0.5)
assert_allclose(margin_x, gauss_x, rtol=1e-2, atol=1e-2)
assert_allclose(margin_y, gauss_y, rtol=1e-2, atol=1e-2)
示例4: test_frozen_matrix_normal
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def test_frozen_matrix_normal(self):
for i in range(1,5):
for j in range(1,5):
M = 0.3 * np.ones((i,j))
U = 0.5 * np.identity(i) + 0.5 * np.ones((i,i))
V = 0.7 * np.identity(j) + 0.3 * np.ones((j,j))
frozen = matrix_normal(mean=M, rowcov=U, colcov=V)
rvs1 = frozen.rvs(random_state=1234)
rvs2 = matrix_normal.rvs(mean=M, rowcov=U, colcov=V,
random_state=1234)
assert_equal(rvs1, rvs2)
X = frozen.rvs(random_state=1234)
pdf1 = frozen.pdf(X)
pdf2 = matrix_normal.pdf(X, mean=M, rowcov=U, colcov=V)
assert_equal(pdf1, pdf2)
logpdf1 = frozen.logpdf(X)
logpdf2 = matrix_normal.logpdf(X, mean=M, rowcov=U, colcov=V)
assert_equal(logpdf1, logpdf2)
示例5: test_frozen_dirichlet
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [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))
示例6: sensorModel
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def sensorModel(particles, numParticles, boxX, boxY):
totalW = 0
for i in range(numParticles):
x = particles[i].x
y = particles[i].y
dx = abs(boxX - x)
dy = abs(boxY - y)
dist = math.sqrt(dx**2 + dy**2)
if dist == 0:
dist = 0.1
bias = 1/dist
particles[i].weight = norm.pdf(bias)
totalW += particles[i].weight
for i in range(numParticles):
particles[i].weight = particles[i].weight/totalW
return particles
示例7: EI
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def EI(y_best, predictions, uncertainty, objective='max'):
"""Return expected improvement acq. function.
Parameters
----------
y_best : float
Condition
predictions : list
Predicted means.
uncertainty : list
Uncertainties associated with the predictions.
"""
if objective == 'max':
z = (predictions - y_best) / (uncertainty)
return (predictions - y_best) * norm.cdf(z) + \
uncertainty * norm.pdf(
z)
if objective == 'min':
z = (-predictions + y_best) / (uncertainty)
return -((predictions - y_best) * norm.cdf(z) -
uncertainty * norm.pdf(z))
示例8: ExpectedImprovement
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def ExpectedImprovement(self, tau, mean, std):
"""
Expected Improvement acquisition function.
Parameters
----------
tau: float
Best observed function evaluation.
mean: float
Point mean of the posterior process.
std: float
Point std of the posterior process.
Returns
-------
float
Expected improvement.
"""
z = (mean - tau - self.eps) / (std + self.eps)
return (mean - tau) * norm.cdf(z) + std * norm.pdf(z)[0]
示例9: tExpectedImprovement
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def tExpectedImprovement(self, tau, mean, std, nu=3.0):
"""
Expected Improvement acquisition function. Only to be used with `tStudentProcess` surrogate.
Parameters
----------
tau: float
Best observed function evaluation.
mean: float
Point mean of the posterior process.
std: float
Point std of the posterior process.
Returns
-------
float
Expected improvement.
"""
gamma = (mean - tau - self.eps) / (std + self.eps)
return gamma * std * t.cdf(gamma, df=nu) + std * (1 + (gamma ** 2 - 1)/(nu - 1)) * t.pdf(gamma, df=nu)
示例10: piece_linear
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def piece_linear(self, hyper, M, prob_R):
'''
model: straight line
'''
c, slope, sigma, trans = self.split_hyper_linear(hyper)
R = np.zeros_like(M)
for i in range(4):
ind = self.indicate(M, trans, i)
mu = c[i] + M[ind]*slope[i]
R[ind] = norm.ppf(prob_R[ind], mu, sigma[i])
return R
# # Unused functions
# def classification(self, logm, trans ):
# '''
# classify as four worlds
# '''
# count = np.zeros(4)
# sample_size = len(logm)
# for iclass in range(4):
# for isample in range(sample_size):
# ind = self.indicate( logm[isample], trans[isample], iclass)
# count[iclass] = count[iclass] + ind
# prob = count / np.sum(count) * 100.
# print 'Terran %(T).1f %%, Neptunian %(N).1f %%, Jovian %(J).1f %%, Star %(S).1f %%' \
# % {'T': prob[0], 'N': prob[1], 'J': prob[2], 'S': prob[3]}
# return None
#
# def ProbRGivenM(self, radii, M, hyper):
# '''
# p(radii|M)
# '''
# c, slope, sigma, trans = self.split_hyper_linear(hyper)
# prob = np.zeros_like(M)
# for i in range(4):
# ind = self.indicate(M, trans, i)
# mu = c[i] + M[ind]*slope[i]
# sig = sigma[i]
# prob[ind] = norm.pdf(radii, mu, sig)
# prob = prob/np.sum(prob)
# return prob
示例11: _gen_beta_data
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def _gen_beta_data(Z, rng, separation=.9, distargs=None):
n_rows = len(Z)
K = np.max(Z)+1
alphas = np.linspace(.5 - .5*separation*.85, .5 + .5*separation*.85, K)
Tc = np.zeros(n_rows)
for r in xrange(n_rows):
cluster = Z[r]
alpha = alphas[cluster]
beta = (1.-alpha) * 20.* (norm.pdf(alpha, .5, .25))
alpha *= 20. * norm.pdf(alpha, .5, .25)
Tc[r] = rng.beta(alpha, beta)
return Tc
示例12: compute
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def compute(self, X_test, derivative=False):
"""
Computes the PI value and its derivatives.
Parameters
----------
X_test: np.ndarray(1, D), The input point where the acquisition_functions function
should be evaluate. The dimensionality of X is (N, D), with N as
the number of points to evaluate at and D is the number of
dimensions of one X.
derivative: Boolean
If is set to true also the derivative of the acquisition_functions
function at X is returned
Returns
-------
np.ndarray(1,1)
Probability of Improvement of X_test
np.ndarray(1,D)
Derivative of Probability of Improvement at X_test
(only if derivative=True)
"""
m, v = self.model.predict(X_test)
_, inc_val = self.model.get_incumbent()
s = np.sqrt(v)
z = (inc_val - m - self.par) / s
f = norm.cdf(z)
if derivative:
dmdx, ds2dx = self.model.predictive_gradients(X_test)
dmdx = dmdx[0]
ds2dx = ds2dx[0][:, None]
dsdx = ds2dx / (2 * s)
df = ((-norm.pdf(z) / s) * (dmdx + dsdx * z)).T
return f, df
else:
return f
示例13: __init__
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def __init__(self, c=1.5, tol=1.0e-08, maxiter=30, norm=None):
self.c = c
self.maxiter = maxiter
self.tol = tol
self.norm = norm
tmp = 2 * Gaussian.cdf(c) - 1
self.gamma = tmp + c**2 * (1 - tmp) - 2 * c * Gaussian.pdf(c)
示例14: hall_sheather
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def hall_sheather(n, q, alpha=.05):
z = norm.ppf(q)
num = 1.5 * norm.pdf(z)**2.
den = 2. * z**2. + 1.
h = n**(-1. / 3) * norm.ppf(1. - alpha / 2.)**(2./3) * (num / den)**(1./3)
return h
示例15: bofinger
# 需要導入模塊: from scipy.stats import norm [as 別名]
# 或者: from scipy.stats.norm import pdf [as 別名]
def bofinger(n, q):
num = 9. / 2 * norm.pdf(2 * norm.ppf(q))**4
den = (2 * norm.ppf(q)**2 + 1)**2
h = n**(-1. / 5) * (num / den)**(1. / 5)
return h