本文整理汇总了Python中scipy.stats.rv_continuous方法的典型用法代码示例。如果您正苦于以下问题:Python stats.rv_continuous方法的具体用法?Python stats.rv_continuous怎么用?Python stats.rv_continuous使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.stats
的用法示例。
在下文中一共展示了stats.rv_continuous方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_name_arg
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def test_no_name_arg(self):
# If name is not given, construction shouldn't fail. See #1508.
stats.rv_continuous()
stats.rv_discrete()
示例2: test_shapes_signature
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def test_shapes_signature(self):
# test explicit shapes which agree w/ the signature of _pdf
class _dist_gen(stats.rv_continuous):
def _pdf(self, x, a):
return stats.norm._pdf(x) * a
dist = _dist_gen(shapes='a')
assert_equal(dist.pdf(0.5, a=2), stats.norm.pdf(0.5)*2)
示例3: test_shapes_signature_inconsistent
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def test_shapes_signature_inconsistent(self):
# test explicit shapes which do not agree w/ the signature of _pdf
class _dist_gen(stats.rv_continuous):
def _pdf(self, x, a):
return stats.norm._pdf(x) * a
dist = _dist_gen(shapes='a, b')
assert_raises(TypeError, dist.pdf, 0.5, **dict(a=1, b=2))
示例4: test_star_args
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def test_star_args(self):
# test _pdf with only starargs
# NB: **kwargs of pdf will never reach _pdf
class _dist_gen(stats.rv_continuous):
def _pdf(self, x, *args):
extra_kwarg = args[0]
return stats.norm._pdf(x) * extra_kwarg
dist = _dist_gen(shapes='extra_kwarg')
assert_equal(dist.pdf(0.5, extra_kwarg=33), stats.norm.pdf(0.5)*33)
assert_equal(dist.pdf(0.5, 33), stats.norm.pdf(0.5)*33)
assert_raises(TypeError, dist.pdf, 0.5, **dict(xxx=33))
示例5: test_star_args_2
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def test_star_args_2(self):
# test _pdf with named & starargs
# NB: **kwargs of pdf will never reach _pdf
class _dist_gen(stats.rv_continuous):
def _pdf(self, x, offset, *args):
extra_kwarg = args[0]
return stats.norm._pdf(x) * extra_kwarg + offset
dist = _dist_gen(shapes='offset, extra_kwarg')
assert_equal(dist.pdf(0.5, offset=111, extra_kwarg=33),
stats.norm.pdf(0.5)*33 + 111)
assert_equal(dist.pdf(0.5, 111, 33),
stats.norm.pdf(0.5)*33 + 111)
示例6: shapes_empty_string
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def shapes_empty_string(self):
# shapes='' is equivalent to shapes=None
class _dist_gen(stats.rv_continuous):
def _pdf(self, x):
return stats.norm.pdf(x)
dist = _dist_gen(shapes='')
assert_equal(dist.pdf(0.5), stats.norm.pdf(0.5))
示例7: test_defaults_raise
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def test_defaults_raise(self):
# default arguments should raise
class _dist_gen(stats.rv_continuous):
def _pdf(self, x, a=42):
return 42
assert_raises(TypeError, _dist_gen, **dict(name='dummy'))
示例8: test_starargs_raise
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def test_starargs_raise(self):
# without explicit shapes, *args are not allowed
class _dist_gen(stats.rv_continuous):
def _pdf(self, x, a, *args):
return 42
assert_raises(TypeError, _dist_gen, **dict(name='dummy'))
示例9: test_kwargs_raise
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def test_kwargs_raise(self):
# without explicit shapes, **kwargs are not allowed
class _dist_gen(stats.rv_continuous):
def _pdf(self, x, a, **kwargs):
return 42
assert_raises(TypeError, _dist_gen, **dict(name='dummy'))
示例10: test_docstrings
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def test_docstrings():
badones = [',\s*,', '\(\s*,', '^\s*:']
for distname in stats.__all__:
dist = getattr(stats, distname)
if isinstance(dist, (stats.rv_discrete, stats.rv_continuous)):
for regex in badones:
assert_( re.search(regex, dist.__doc__) is None)
示例11: test_cdf
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def test_cdf(self):
# regression test for gh-4030: Implementation of
# scipy.stats.betaprime.cdf()
x = stats.betaprime.cdf(0, 0.2, 0.3)
assert_equal(x, 0.0)
alpha, beta = 267, 1472
x = np.array([0.2, 0.5, 0.6])
cdfs = stats.betaprime.cdf(x, alpha, beta)
assert_(np.isfinite(cdfs).all())
# check the new cdf implementation vs generic one:
gen_cdf = stats.rv_continuous._cdf_single
cdfs_g = [gen_cdf(stats.betaprime, val, alpha, beta) for val in x]
assert_allclose(cdfs, cdfs_g, atol=0, rtol=2e-12)
示例12: test_extra_kwarg
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def test_extra_kwarg(self):
# **kwargs to _pdf are ignored.
# this is a limitation of the framework (_pdf(x, *goodargs))
class _distr_gen(stats.rv_continuous):
def _pdf(self, x, *args, **kwargs):
# _pdf should handle *args, **kwargs itself. Here "handling"
# is ignoring *args and looking for ``extra_kwarg`` and using
# that.
extra_kwarg = kwargs.pop('extra_kwarg', 1)
return stats.norm._pdf(x) * extra_kwarg
dist = _distr_gen(shapes='extra_kwarg')
assert_equal(dist.pdf(1, extra_kwarg=3), stats.norm.pdf(1))
示例13: __init__
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def __init__(self, rv_mixed):
self.rv_mixed = rv_mixed
self.is_continuous = isinstance(rv_mixed.dist, rv_continuous)
示例14: _fit_parametric_family
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def _fit_parametric_family(dist: stats.rv_continuous, sample: np.ndarray) -> Tuple:
if dist == stats.multivariate_normal:
# has no fit method...
return np.mean(sample, axis=0), np.cov(sample.T, ddof=1)
if dist == stats.t:
fit_kwd = {"fscale": 1}
elif dist in {stats.f, stats.beta}:
fit_kwd = {"floc": 0, "fscale": 1}
elif dist in (stats.gamma, stats.lognorm, stats.invgauss, stats.pareto):
fit_kwd = {"floc": 0}
else:
fit_kwd = {}
return dist.fit(sample, **fit_kwd)
示例15: dist_gen
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import rv_continuous [as 别名]
def dist_gen(pdf_in=None, cdf_in=None, ppf_in=None, **kwargs):
"""Distribution Factory.
Parameters
----------
pdf_in : :any:`callable` or :any:`None`, optional
Proprobability distribution function of the given distribution, that
takes a single argument
Default: ``None``
cdf_in : :any:`callable` or :any:`None`, optional
Cumulative distribution function of the given distribution, that
takes a single argument
Default: ``None``
ppf_in : :any:`callable` or :any:`None`, optional
Percent point function of the given distribution, that
takes a single argument
Default: ``None``
**kwargs
Keyword-arguments forwarded to :any:`scipy.stats.rv_continuous`.
Returns
-------
dist : :class:`scipy.stats.rv_continuous`
The constructed distribution.
Notes
-----
At least pdf or cdf needs to be given.
"""
if ppf_in is None:
if pdf_in is not None and cdf_in is None:
return DistPdf(pdf_in, **kwargs)
if pdf_in is None and cdf_in is not None:
return DistCdf(cdf_in, **kwargs)
if pdf_in is not None and cdf_in is not None:
return DistPdfCdf(pdf_in, cdf_in, **kwargs)
raise ValueError("Either pdf or cdf must be given")
else:
if pdf_in is not None and cdf_in is None:
return DistPdfPpf(pdf_in, ppf_in, **kwargs)
if pdf_in is None and cdf_in is not None:
return DistCdfPpf(cdf_in, ppf_in, **kwargs)
if pdf_in is not None and cdf_in is not None:
return DistPdfCdfPpf(pdf_in, cdf_in, ppf_in, **kwargs)
raise ValueError("pdf or cdf must be given along with the ppf")