Python scipy.stats.rv_continuous() Examples
The following are 23
code examples of scipy.stats.rv_continuous().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy.stats
, or try the search function
.
Example #1
Source File: test_distributions.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_no_name_arg(self): # If name is not given, construction shouldn't fail. See #1508. stats.rv_continuous() stats.rv_discrete()
Example #2
Source File: bootstrap.py From resample with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #3
Source File: marginal.py From mixedvines with GNU General Public License v3.0 | 5 votes |
def __init__(self, rv_mixed): self.rv_mixed = rv_mixed self.is_continuous = isinstance(rv_mixed.dist, rv_continuous)
Example #4
Source File: test_distributions.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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'))
Example #5
Source File: test_distributions.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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'))
Example #6
Source File: test_distributions.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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'))
Example #7
Source File: test_distributions.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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))
Example #8
Source File: test_distributions.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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))
Example #9
Source File: test_distributions.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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))
Example #10
Source File: test_distributions.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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))
Example #11
Source File: test_distributions.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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)
Example #12
Source File: test_distributions.py From Computable with MIT License | 5 votes |
def test_no_name_arg(self): # If name is not given, construction shouldn't fail. See #1508. stats.rv_continuous() stats.rv_discrete()
Example #13
Source File: test_distributions.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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)
Example #14
Source File: test_distributions.py From Computable with MIT License | 5 votes |
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)
Example #15
Source File: test_distributions.py From Computable with MIT License | 5 votes |
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))
Example #16
Source File: test_distributions.py From Computable with MIT License | 5 votes |
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)
Example #17
Source File: test_distributions.py From Computable with MIT License | 5 votes |
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))
Example #18
Source File: test_distributions.py From Computable with MIT License | 5 votes |
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))
Example #19
Source File: test_distributions.py From Computable with MIT License | 5 votes |
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)
Example #20
Source File: test_distributions.py From Computable with MIT License | 4 votes |
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'))
Example #21
Source File: test_distributions.py From Computable with MIT License | 4 votes |
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'))
Example #22
Source File: test_distributions.py From Computable with MIT License | 4 votes |
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'))
Example #23
Source File: tools.py From GSTools with GNU Lesser General Public License v3.0 | 4 votes |
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")