本文整理汇总了Python中scipy.stats.norm方法的典型用法代码示例。如果您正苦于以下问题:Python stats.norm方法的具体用法?Python stats.norm怎么用?Python stats.norm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块scipy.stats的用法示例。
在下文中一共展示了stats.norm方法的24个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
点赞 6
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def __init__(self,
nbases,
Xdim,
mean=Parameter(norm_dist(), Bound()),
lenscale=Parameter(gamma(1.), Positive()),
regularizer=None,
random_state=None
):
"""See this class's docstring."""
self.random_state = random_state # for repr
self._random = check_random_state(random_state)
self._init_dims(nbases, Xdim)
self._params = [self._init_param(mean),
self._init_param(lenscale)]
self._init_matrices()
super(_LengthScaleBasis, self).__init__(regularizer)
开发者ID:NICTA,项目名称:revrand,代码行数:18,
示例2: conf_int
点赞 6
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def conf_int(self, alpha=.05):
"""
Returns the confidence intervals of the marginal effects
Parameters
----------
alpha : float
Number between 0 and 1. The confidence intervals have the
probability 1-alpha.
Returns
-------
conf_int : ndarray
An array with lower, upper confidence intervals for the marginal
effects.
"""
_check_at_is_all(self.margeff_options)
me_se = self.margeff_se
q = stats.norm.ppf(1 - alpha / 2)
lower = self.margeff - q * me_se
upper = self.margeff + q * me_se
return np.asarray(lzip(lower, upper))
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,
示例3: test_mixture_rvs_fixed
点赞 6
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def test_mixture_rvs_fixed(self):
mix = MixtureDistribution()
np.random.seed(1234)
res = mix.rvs([.15,.85], 50, dist=[stats.norm, stats.norm], kwargs =
(dict(loc=1,scale=.5),dict(loc=-1,scale=.5)))
npt.assert_almost_equal(
res,
np.array([-0.5794956 , -1.72290504, -1.70098664, -1.0504591 ,
-1.27412122,-1.07230975, -0.82298983, -1.01775651,
-0.71713085,-0.2271706 ,-1.48711817, -1.03517244,
-0.84601557, -1.10424938, -0.48309963,-2.20022682,
0.01530181, 1.1238961 , -1.57131564, -0.89405831,
-0.64763969, -1.39271761, 0.55142161, -0.76897013,
-0.64788589,-0.73824602, -1.46312716, 0.00392148,
-0.88651873, -1.57632955,-0.68401028, -0.98024366,
-0.76780384, 0.93160258,-2.78175833,-0.33944719,
-0.92368472, -0.91773523, -1.21504785, -0.61631563,
1.0091446 , -0.50754008, 1.37770699, -0.86458208,
-0.3040069 ,-0.96007884, 1.10763429, -1.19998229,
-1.51392528, -1.29235911]))
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,
示例4: test_compare
点赞 6
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def test_compare(self):
xx = self.res1.support
kde_vals = [self.res1.evaluate(xi) for xi in xx]
kde_vals = np.squeeze(kde_vals) #kde_vals is a "column_list"
mask_valid = np.isfinite(kde_vals)
# TODO: nans at the boundaries
kde_vals[~mask_valid] = 0
npt.assert_almost_equal(self.res1.density, kde_vals,
self.decimal_density)
# regression test, not compared to another package
nobs = len(self.res1.endog)
kern = self.res1.kernel
v = kern.density_var(kde_vals, nobs)
v_direct = kde_vals * kern.L2Norm / kern.h / nobs
npt.assert_allclose(v, v_direct, rtol=1e-10)
ci = kern.density_confint(kde_vals, nobs)
crit = 1.9599639845400545 #stats.norm.isf(0.05 / 2)
hw = kde_vals - ci[:, 0]
npt.assert_allclose(hw, crit * np.sqrt(v), rtol=1e-10)
hw = ci[:, 1] - kde_vals
npt.assert_allclose(hw, crit * np.sqrt(v), rtol=1e-10)
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:25,
示例5: __init__
点赞 6
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def __init__(self, predicted_mean, var_pred_mean, var_resid,
df=None, dist=None, row_labels=None):
self.predicted_mean = predicted_mean
self.var_pred_mean = var_pred_mean
self.df = df
self.var_resid = var_resid
self.row_labels = row_labels
if dist is None or dist == 'norm':
self.dist = stats.norm
self.dist_args = ()
elif dist == 't':
self.dist = stats.t
self.dist_args = (self.df,)
else:
self.dist = dist
self.dist_args = ()
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,
示例6: test_qqplot
点赞 6
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def test_qqplot(self):
"""Test qqplot()"""
np.random.seed(123)
x = np.random.normal(size=50)
x_ln = np.random.lognormal(size=50)
x_exp = np.random.exponential(size=50)
ax = qqplot(x, dist='norm')
assert isinstance(ax, matplotlib.axes.Axes)
_, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 4))
qqplot(x_exp, dist='expon', ax=ax2)
mean, std = 0, 0.8
qqplot(x, dist=stats.norm, sparams=(mean, std), confidence=False)
# For lognormal distribution, the shape parameter must be specified
ax = qqplot(x_ln, dist='lognorm', sparams=(1))
assert isinstance(ax, matplotlib.axes.Axes)
# Error: required parameters are not specified
with pytest.raises(ValueError):
qqplot(x_ln, dist='lognorm', sparams=())
plt.close('all')
开发者ID:raphaelvallat,项目名称:pingouin,代码行数:21,
示例7: test_compute_perfect_model_da1d_not_nan_crpss_quadratic_kwargs
点赞 6
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def test_compute_perfect_model_da1d_not_nan_crpss_quadratic_kwargs(
PM_da_initialized_1d, PM_da_control_1d
):
"""
Checks that there are no NaNs on perfect model metrics of 1D time series.
"""
actual = (
compute_perfect_model(
PM_da_initialized_1d.isel(lead=[0]),
PM_da_control_1d,
comparison='m2c',
metric='crpss',
gaussian=False,
dim='member',
tol=1e-6,
xmin=None,
xmax=None,
cdf_or_dist=norm,
)
.isnull()
.any()
)
assert not actual
开发者ID:bradyrx,项目名称:climpred,代码行数:25,
示例8: setUp_configure
点赞 6
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def setUp_configure(self):
from scipy import stats
self.dist = distributions.Normal
self.scipy_dist = stats.norm
self.test_targets = set([
'batch_shape', 'cdf', 'entropy', 'event_shape', 'icdf', 'log_cdf',
'log_prob', 'log_survival', 'mean', 'prob', 'sample', 'stddev',
'support', 'survival', 'variance'])
loc = utils.force_array(
numpy.random.uniform(-1, 1, self.shape).astype(numpy.float32))
if self.log_scale_option:
log_scale = utils.force_array(
numpy.random.uniform(-1, 1, self.shape).astype(numpy.float32))
scale = numpy.exp(log_scale)
self.params = {'loc': loc, 'log_scale': log_scale}
self.scipy_params = {'loc': loc, 'scale': scale}
else:
scale = utils.force_array(numpy.exp(
numpy.random.uniform(-1, 1, self.shape)).astype(numpy.float32))
self.params = {'loc': loc, 'scale': scale}
self.scipy_params = {'loc': loc, 'scale': scale}
开发者ID:chainer,项目名称:chainer,代码行数:25,
示例9: test_norm_logcdf
点赞 6
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def test_norm_logcdf():
# Test precision of the logcdf of the normal distribution.
# This precision was enhanced in ticket 1614.
x = -np.asarray(list(range(0, 120, 4)))
# Values from R
expected = [-0.69314718, -10.36010149, -35.01343716, -75.41067300,
-131.69539607, -203.91715537, -292.09872100, -396.25241451,
-516.38564863, -652.50322759, -804.60844201, -972.70364403,
-1156.79057310, -1356.87055173, -1572.94460885, -1805.01356068,
-2053.07806561, -2317.13866238, -2597.19579746, -2893.24984493,
-3205.30112136, -3533.34989701, -3877.39640444, -4237.44084522,
-4613.48339520, -5005.52420869, -5413.56342187, -5837.60115548,
-6277.63751711, -6733.67260303]
assert_allclose(stats.norm().logcdf(x), expected, atol=1e-8)
# also test the complex-valued code path
assert_allclose(stats.norm().logcdf(x + 1e-14j).real, expected, atol=1e-8)
# test the accuracy: d(logcdf)/dx = pdf / cdf \equiv exp(logpdf - logcdf)
deriv = (stats.norm.logcdf(x + 1e-10j)/1e-10).imag
deriv_expected = np.exp(stats.norm.logpdf(x) - stats.norm.logcdf(x))
assert_allclose(deriv, deriv_expected, atol=1e-10)
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:25,
示例10: test_pdf
点赞 6
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def test_pdf(self):
values = np.array([0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5,
5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5])
pdf_values = np.asarray([0.0/25.0, 0.0/25.0, 1.0/25.0, 1.0/25.0,
2.0/25.0, 2.0/25.0, 3.0/25.0, 3.0/25.0,
4.0/25.0, 4.0/25.0, 5.0/25.0, 5.0/25.0,
4.0/25.0, 4.0/25.0, 3.0/25.0, 3.0/25.0,
3.0/25.0, 3.0/25.0, 0.0/25.0, 0.0/25.0])
assert_allclose(self.template.pdf(values), pdf_values)
# Test explicitly the corner cases:
# As stated above the pdf in the bin [8,9) is greater than
# one would naively expect because np.histogram putted the 9
# into the [8,9) bin.
assert_almost_equal(self.template.pdf(8.0), 3.0/25.0)
assert_almost_equal(self.template.pdf(8.5), 3.0/25.0)
# 9 is outside our defined bins [8,9) hence the pdf is already 0
# for a continuous distribution this is fine, because a single value
# does not have a finite probability!
assert_almost_equal(self.template.pdf(9.0), 0.0/25.0)
assert_almost_equal(self.template.pdf(10.0), 0.0/25.0)
x = np.linspace(-2, 2, 10)
assert_allclose(self.norm_template.pdf(x),
stats.norm.pdf(x, loc=1.0, scale=2.5), rtol=0.1)
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:27,
示例11: test_cdf_ppf
点赞 6
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def test_cdf_ppf(self):
values = np.array([0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5,
5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 8.5, 9.0, 9.5])
cdf_values = np.asarray([0.0/25.0, 0.0/25.0, 0.0/25.0, 0.5/25.0,
1.0/25.0, 2.0/25.0, 3.0/25.0, 4.5/25.0,
6.0/25.0, 8.0/25.0, 10.0/25.0, 12.5/25.0,
15.0/25.0, 17.0/25.0, 19.0/25.0, 20.5/25.0,
22.0/25.0, 23.5/25.0, 25.0/25.0, 25.0/25.0])
assert_allclose(self.template.cdf(values), cdf_values)
# First three and last two values in cdf_value are not unique
assert_allclose(self.template.ppf(cdf_values[2:-1]), values[2:-1])
# Test of cdf and ppf are inverse functions
x = np.linspace(1.0, 9.0, 100)
assert_allclose(self.template.ppf(self.template.cdf(x)), x)
x = np.linspace(0.0, 1.0, 100)
assert_allclose(self.template.cdf(self.template.ppf(x)), x)
x = np.linspace(-2, 2, 10)
assert_allclose(self.norm_template.cdf(x),
stats.norm.cdf(x, loc=1.0, scale=2.5), rtol=0.1)
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:23,
示例12: step
点赞 5
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def step(self, actions, **kwargs):
reward = stats.norm.pdf(actions, loc=self.loc, scale=self.scale)[0]
self.episode_step += 1
self.loc = np.random.uniform(size=(1,)) * 2 - 1
return self.loc, reward, self.episode_step >= self.episode_length, None
开发者ID:rlgraph,项目名称:rlgraph,代码行数:7,
示例13: get_max_reward
点赞 5
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def get_max_reward(self):
max_reward_per_step = stats.norm(loc=0.0, scale=self.scale).pdf(0.0)
return self.episode_length * max_reward_per_step
开发者ID:rlgraph,项目名称:rlgraph,代码行数:5,
示例14: forward
点赞 5
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def forward(self, z, mu, sig):
self.save_for_backward(z, mu, sig)
p = st.norm(mu.cpu().numpy(),sig.cpu().numpy())
return torch.DoubleTensor((self.gamma_under + self.gamma_over) * p.cdf(
z.cpu().numpy()) - self.gamma_under).cuda()
开发者ID:locuslab,项目名称:e2e-model-learning,代码行数:7,
示例15: backward
点赞 5
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def backward(self, grad_output):
z, mu, sig = self.saved_tensors
p = st.norm(mu.cpu().numpy(),sig.cpu().numpy())
pz = torch.DoubleTensor(p.pdf(z.cpu().numpy())).cuda()
dz = (self.gamma_under + self.gamma_over) * pz
dmu = -dz
dsig = -(self.gamma_under + self.gamma_over)*(z-mu) / sig * pz
return grad_output * dz, grad_output * dmu, grad_output * dsig
开发者ID:locuslab,项目名称:e2e-model-learning,代码行数:11,
示例16: pvalues
点赞 5
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def pvalues(self):
if self.use_t:
df_resid = getattr(self, 'df_resid_inference', self.df_resid)
return stats.t.sf(np.abs(self.tvalues), df_resid) * 2
else:
return stats.norm.sf(np.abs(self.tvalues)) * 2
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:8,
示例17: __init__
点赞 5
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def __init__(self, data, dist=stats.norm, fit=False,
distargs=(), a=0, loc=0, scale=1):
self.data = data
self.a = a
self.nobs = data.shape[0]
self.distargs = distargs
self.fit = fit
if isinstance(dist, string_types):
dist = getattr(stats, dist)
self.fit_params = dist.fit(data)
if fit:
self.loc = self.fit_params[-2]
self.scale = self.fit_params[-1]
if len(self.fit_params) > 2:
self.dist = dist(*self.fit_params[:-2],
**dict(loc = 0, scale = 1))
else:
self.dist = dist(loc=0, scale=1)
elif distargs or loc == 0 or scale == 1:
self.dist = dist(*distargs, **dict(loc=loc, scale=scale))
self.loc = loc
self.scale = scale
else:
self.dist = dist
self.loc = loc
self.scale = scale
# propertes
self._cache = resettable_cache()
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:34,
示例18: pvalues
点赞 5
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def pvalues(self):
_check_at_is_all(self.margeff_options)
return stats.norm.sf(np.abs(self.tvalues)) * 2
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:5,
示例19: params_transform_univariate
点赞 5
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def params_transform_univariate(params, cov_params, link=None, transform=None,
row_labels=None):
"""
results for univariate, nonlinear, monotonicaly transformed parameters
This provides transformed values, standard errors and confidence interval
for transformations of parameters, for example in calculating rates with
`exp(params)` in the case of Poisson or other models with exponential
mean function.
"""
from statsmodels.genmod.families import links
if link is None and transform is None:
link = links.Log()
if row_labels is None and hasattr(params, 'index'):
row_labels = params.index
params = np.asarray(params)
predicted_mean = link.inverse(params)
link_deriv = link.inverse_deriv(params)
var_pred_mean = link_deriv**2 * np.diag(cov_params)
# TODO: do we want covariance also, or just var/se
dist = stats.norm
# TODO: need ci for linear prediction, method of `lin_pred
linpred = PredictionResults(params, np.diag(cov_params), dist=dist,
row_labels=row_labels, link=links.identity())
res = PredictionResults(predicted_mean, var_pred_mean, dist=dist,
row_labels=row_labels, linpred=linpred, link=link)
return res
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:38,
示例20: exactdist
点赞 5
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def exactdist(self, xzero, t):
expnt = np.exp(-self.lambd * t)
meant = xzero * expnt + self._exactconst(expnt)
stdt = self._exactstd(expnt)
return stats.norm(loc=meant, scale=stdt)
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,
示例21: example_n
点赞 5
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def example_n():
print(skewnorm.pdf(1,0), stats.norm.pdf(1), skewnorm.pdf(1,0) - stats.norm.pdf(1))
print(skewnorm.pdf(1,1000), stats.chi.pdf(1,1), skewnorm.pdf(1,1000) - stats.chi.pdf(1,1))
print(skewnorm.pdf(-1,-1000), stats.chi.pdf(1,1), skewnorm.pdf(-1,-1000) - stats.chi.pdf(1,1))
rvs = skewnorm.rvs(0,size=500)
print('sample mean var: ', rvs.mean(), rvs.var())
print('theoretical mean var', skewnorm.stats(0))
rvs = skewnorm.rvs(5,size=500)
print('sample mean var: ', rvs.mean(), rvs.var())
print('theoretical mean var', skewnorm.stats(5))
print(skewnorm.cdf(1,0), stats.norm.cdf(1), skewnorm.cdf(1,0) - stats.norm.cdf(1))
print(skewnorm.cdf(1,1000), stats.chi.cdf(1,1), skewnorm.cdf(1,1000) - stats.chi.cdf(1,1))
print(skewnorm.sf(0.05,1000), stats.chi.sf(0.05,1), skewnorm.sf(0.05,1000) - stats.chi.sf(0.05,1))
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:16,
示例22: setup_class
点赞 5
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def setup_class(kls):
kls.scale = 2
kls.dist1 = stats.norm(1, 2)
kls.mvsk = [1., 2**2, 0, 0]
kls.dist2 = NormExpan_gen(kls.mvsk, mode='mvsk')
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:7,
示例23: _rvs
点赞 5
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def _rvs(self, alpha):
# see http://azzalini.stat.unipd.it/SN/faq.html
delta = alpha/np.sqrt(1+alpha**2)
u0 = stats.norm.rvs(size=self._size)
u1 = delta*u0 + np.sqrt(1-delta**2)*stats.norm.rvs(size=self._size)
return np.where(u0>0, u1, -u1)
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:8,
示例24: test_mixture_rvs_random
点赞 5
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import norm [as 别名]
def test_mixture_rvs_random(self):
# Test only medium small sample at 1 decimal
np.random.seed(0)
mix = MixtureDistribution()
res = mix.rvs([.75,.25], 1000, dist=[stats.norm, stats.norm], kwargs =
(dict(loc=-1,scale=.5),dict(loc=1,scale=.5)))
npt.assert_almost_equal(
np.array([res.std(),res.mean(),res.var()]),
np.array([1,-0.5,1]),
decimal=1)
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:12,
注:本文中的scipy.stats.norm方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。