当前位置: 首页>>代码示例>>Python>>正文


Python stats.lognorm方法代码示例

本文整理汇总了Python中scipy.stats.lognorm方法的典型用法代码示例。如果您正苦于以下问题:Python stats.lognorm方法的具体用法?Python stats.lognorm怎么用?Python stats.lognorm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.stats的用法示例。


在下文中一共展示了stats.lognorm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_class

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def setup_class(cls):
        cls.dist_equivalents = [
            #transf, stats.lognorm(1))
            #The below fails on the SPARC box with scipy 10.1
            #(lognormalg, stats.lognorm(1)),
            #transf2
           (squarenormalg, stats.chi2(1)),
           (absnormalg, stats.halfnorm),
           (absnormalg, stats.foldnorm(1e-5)),  #try frozen
           #(negsquarenormalg, 1-stats.chi2),  # won't work as distribution
           (squaretg(10), stats.f(1, 10))
            ]      #try both frozen

        l,s = 0.0, 1.0
        cls.ppfq = [0.1,0.5,0.9]
        cls.xx = [0.95,1.0,1.1]
        cls.nxx = [-0.95,-1.0,-1.1] 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:test_transf.py

示例2: setUp_configure

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def setUp_configure(self):
        from scipy import stats
        self.dist = distributions.LogNormal
        self.scipy_dist = stats.lognorm

        self.test_targets = set([
            'batch_shape', 'entropy', 'event_shape', 'log_prob', 'mean',
            'sample', 'support', 'variance'])

        mu = utils.force_array(
            numpy.random.uniform(-1, 1, self.shape).astype(numpy.float32))
        sigma = utils.force_array(numpy.exp(numpy.random.uniform(
            -1, 0, self.shape)).astype(numpy.float32))
        self.params = {'mu': mu, 'sigma': sigma}
        self.scipy_params = {'s': sigma, 'scale': numpy.exp(mu)}

        self.support = 'positive' 
开发者ID:chainer,项目名称:chainer,代码行数:19,代码来源:test_log_normal.py

示例3: test_lognorm_fit

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def test_lognorm_fit(self):
        x = np.array([1.5, 3, 10, 15, 23, 59])
        lnxm1 = np.log(x - 1)

        shape, loc, scale = stats.lognorm.fit(x, floc=1)
        assert_allclose(shape, lnxm1.std(), rtol=1e-12)
        assert_equal(loc, 1)
        assert_allclose(scale, np.exp(lnxm1.mean()), rtol=1e-12)

        shape, loc, scale = stats.lognorm.fit(x, floc=1, fscale=6)
        assert_allclose(shape, np.sqrt(((lnxm1 - np.log(6))**2).mean()),
                        rtol=1e-12)
        assert_equal(loc, 1)
        assert_equal(scale, 6)

        shape, loc, scale = stats.lognorm.fit(x, floc=1, fix_s=0.75)
        assert_equal(shape, 0.75)
        assert_equal(loc, 1)
        assert_allclose(scale, np.exp(lnxm1.mean()), rtol=1e-12) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:21,代码来源:test_distributions.py

示例4: test_stats_shapes_argcheck

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def test_stats_shapes_argcheck():
    # stats method was failing for vector shapes if some of the values
    # were outside of the allowed range, see gh-2678
    mv3 = stats.invgamma.stats([0.0, 0.5, 1.0], 1, 0.5)  # 0 is not a legal `a`
    mv2 = stats.invgamma.stats([0.5, 1.0], 1, 0.5)
    mv2_augmented = tuple(np.r_[np.nan, _] for _ in mv2)
    assert_equal(mv2_augmented, mv3)

    # -1 is not a legal shape parameter
    mv3 = stats.lognorm.stats([2, 2.4, -1])
    mv2 = stats.lognorm.stats([2, 2.4])
    mv2_augmented = tuple(np.r_[_, np.nan] for _ in mv2)
    assert_equal(mv2_augmented, mv3)

    # FIXME: this is only a quick-and-dirty test of a quick-and-dirty bugfix.
    # stats method with multiple shape parameters is not properly vectorized
    # anyway, so some distributions may or may not fail.


# Test subclassing distributions w/ explicit shapes 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:22,代码来源:test_distributions.py

示例5: d_score

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def d_score(self, Y):
        E = Y["Event"][:, np.newaxis]
        T = Y["Time"]
        lT = np.log(T)
        Z = (lT - self.loc) / self.scale

        D_uncens = np.zeros((self.loc.shape[0], 2))
        D_uncens[:, 0] = (self.loc - lT) / (self.scale ** 2)
        D_uncens[:, 1] = 1 - ((self.loc - lT) ** 2) / (self.scale ** 2)

        D_cens = np.zeros((self.loc.shape[0], 2))
        D_cens[:, 0] = -sp.stats.norm.pdf(lT, loc=self.loc, scale=self.scale) / (
            1 - self.dist.cdf(T) + self.eps
        )
        D_cens[:, 1] = (
            -Z
            * sp.stats.norm.pdf(lT, loc=self.loc, scale=self.scale)
            / (1 - self.dist.cdf(T) + self.eps)
        )

        return (1 - E) * D_cens + E * D_uncens 
开发者ID:stanfordmlgroup,项目名称:ngboost,代码行数:23,代码来源:lognormal.py

示例6: define_tau_function

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def define_tau_function(after_treatment_temperature_threshold):
    """
    Defines tau-function of the extended Willans curve.

    :param after_treatment_temperature_threshold:
        Engine coolant temperature threshold when the after treatment system is
        warm [°C].
    :type after_treatment_temperature_threshold: (float, float)

    :return:
        Tau-function of the extended Willans curve.
    :rtype: callable
    """
    import scipy.stats as sci_sta
    temp_mean, temp_end = np.array(after_treatment_temperature_threshold) + 273
    s = np.log(temp_end / temp_mean) / sci_sta.norm.ppf(0.95)
    f = sci_sta.lognorm(max(s, dfl.EPS), 0, temp_mean).cdf

    def _tau_function(t0, t1, temp):
        return t0 + (t1 - t0) * f(temp + 273)

    return _tau_function 
开发者ID:JRCSTU,项目名称:CO2MPAS-TA,代码行数:24,代码来源:fc.py

示例7: exactdist

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def exactdist(self, xzero, t):
        expnt = np.exp(-self.lambd * t)
        #TODO: check this is still wrong, just guessing
        meant = np.log(xzero) * expnt + self._exactconst(expnt)
        stdt = self._exactstd(expnt)
        return stats.lognorm(loc=meant, scale=stdt) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:8,代码来源:diffusion.py

示例8: test_equivalent

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def test_equivalent(self):
        xx, ppfq = self.xx, self.ppfq
        for d1,d2 in self.dist_equivalents:
##            print d1.name
            assert_almost_equal(d1.cdf(xx), d2.cdf(xx), err_msg='cdf'+d1.name)
            assert_almost_equal(d1.pdf(xx), d2.pdf(xx),
                                err_msg='pdf '+d1.name+d2.name)
            assert_almost_equal(d1.sf(xx), d2.sf(xx),
                                err_msg='sf '+d1.name+d2.name)
            assert_almost_equal(d1.ppf(ppfq), d2.ppf(ppfq),
                                err_msg='ppq '+d1.name+d2.name)
            assert_almost_equal(d1.isf(ppfq), d2.isf(ppfq),
                                err_msg='isf '+d1.name+d2.name)
            self.d1 = d1
            self.d2 = d2
##            print d1, d2
##            print d1.moment(3)
##            print d2.moment(3)
            #work around bug#1293
            if hasattr(d2, 'dist'):
                d2mom = d2.dist.moment(3, *d2.args)
            else:
                d2mom = d2.moment(3)
            assert_almost_equal(d1.moment(3), d2mom,
                                DECIMAL,
                                err_msg='moment '+d1.name+d2.name)
            # silence warnings in scipy, works for versions
            # after print changed to warning in scipy
            orig_filter = warnings.filters[:]
            warnings.simplefilter('ignore')
            try:
                s1 = d1.stats(moments='mvsk')
                s2 = d2.stats(moments='mvsk')
            finally:
                warnings.filters = orig_filter
            #stats(moments='k') prints warning for lognormalg
            assert_almost_equal(s1[:2], s2[:2],
                                err_msg='stats '+d1.name+d2.name)
            assert_almost_equal(s1[2:], s2[2:],
                                decimal=2, #lognorm for kurtosis
                                err_msg='stats '+d1.name+d2.name) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:43,代码来源:test_transf.py

示例9: test_pdf

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def test_pdf(self):
        # Regression test for Ticket #1471: avoid nan with 0/0 situation
        with np.errstate(divide='ignore'):
            pdf = stats.lognorm.pdf([0, 0.5, 1], 1)
            assert_array_almost_equal(pdf, [0.0, 0.62749608, 0.39894228]) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_distributions.py

示例10: test_fix_fit_2args_lognorm

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def test_fix_fit_2args_lognorm(self):
        """Regression test for #1551."""
        np.random.seed(12345)
        with np.errstate(all='ignore'):
            x = stats.lognorm.rvs(0.25, 0., 20.0, size=20)
            assert_allclose(np.array(stats.lognorm.fit(x, floc=0, fscale=20)),
                            [0.25888672, 0, 20], atol=1e-5) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:9,代码来源:test_distributions.py

示例11: test_regression_ticket_1293

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def test_regression_ticket_1293(self):
        # Create a frozen distribution.
        frozen = stats.lognorm(1)
        # Call one of its methods that does not take any keyword arguments.
        m1 = frozen.moment(2)
        # Now call a method that takes a keyword argument.
        frozen.stats(moments='mvsk')
        # Call moment(2) again.
        # After calling stats(), the following was raising an exception.
        # So this test passes if the following does not raise an exception.
        m2 = frozen.moment(2)
        # The following should also be true, of course.  But it is not
        # the focus of this test.
        assert_equal(m1, m2) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:16,代码来源:test_distributions.py

示例12: test_frozen_fit_ticket_1536

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def test_frozen_fit_ticket_1536():
    np.random.seed(5678)
    true = np.array([0.25, 0., 0.5])
    x = stats.lognorm.rvs(true[0], true[1], true[2], size=100)

    olderr = np.seterr(divide='ignore')
    try:
        params = np.array(stats.lognorm.fit(x, floc=0.))
    finally:
        np.seterr(**olderr)

    assert_almost_equal(params, true, decimal=2)

    params = np.array(stats.lognorm.fit(x, fscale=0.5, loc=0))
    assert_almost_equal(params, true, decimal=2)

    params = np.array(stats.lognorm.fit(x, f0=0.25, loc=0))
    assert_almost_equal(params, true, decimal=2)

    params = np.array(stats.lognorm.fit(x, f0=0.25, floc=0))
    assert_almost_equal(params, true, decimal=2)

    np.random.seed(5678)
    loc = 1
    floc = 0.9
    x = stats.norm.rvs(loc, 2., size=100)
    params = np.array(stats.norm.fit(x, floc=floc))
    expected = np.array([floc, np.sqrt(((x-floc)**2).mean())])
    assert_almost_equal(params, expected, decimal=4) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:31,代码来源:test_distributions.py

示例13: __init__

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def __init__(self,
                 γ=2,
                 β=0.95,
                 α=0.90,
                 σ=0.1,
                 grid_size=100):

        self.γ, self.β, self.α, self.σ = γ, β, α, σ

        # == Set the grid interval to contain most of the mass of the
        # stationary distribution of the consumption endowment == #
        ssd = self.σ / np.sqrt(1 - self.α**2)
        grid_min, grid_max = np.exp(-4 * ssd), np.exp(4 * ssd)
        self.grid = np.linspace(grid_min, grid_max, grid_size)
        self.grid_size = grid_size

        # == set up distribution for shocks == #
        self.ϕ = lognorm(σ)
        self.draws = self.ϕ.rvs(500)

        # == h(y) = β * int G(y,z)^(1-γ) ϕ(dz) == #
        self.h = np.empty(self.grid_size)
        for i, y in enumerate(self.grid):
            self.h[i] = β * np.mean((y**α * self.draws)**(1 - γ))



## == Now the functions that act on a Lucas Tree == # 
开发者ID:QuantEcon,项目名称:QuantEcon.lectures.code,代码行数:30,代码来源:lucastree.py

示例14: test_pdf

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def test_pdf(self):
        # Regression test for Ticket #1471: avoid nan with 0/0 situation
        # Also make sure there are no warnings at x=0, cf gh-5202
        with warnings.catch_warnings():
            warnings.simplefilter('error', RuntimeWarning)
            pdf = stats.lognorm.pdf([0, 0.5, 1], 1)
            assert_array_almost_equal(pdf, [0.0, 0.62749608, 0.39894228]) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:9,代码来源:test_distributions.py

示例15: test_logcdf

# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import lognorm [as 别名]
def test_logcdf(self):
        # Regression test for gh-5940: sf et al would underflow too early
        x2, mu, sigma = 201.68, 195, 0.149
        assert_allclose(stats.lognorm.sf(x2-mu, s=sigma),
                        stats.norm.sf(np.log(x2-mu)/sigma))
        assert_allclose(stats.lognorm.logsf(x2-mu, s=sigma),
                        stats.norm.logsf(np.log(x2-mu)/sigma)) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:9,代码来源:test_distributions.py


注:本文中的scipy.stats.lognorm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。