當前位置: 首頁>>代碼示例>>Python>>正文


Python special.lambertw方法代碼示例

本文整理匯總了Python中scipy.special.lambertw方法的典型用法代碼示例。如果您正苦於以下問題:Python special.lambertw方法的具體用法?Python special.lambertw怎麽用?Python special.lambertw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.special的用法示例。


在下文中一共展示了special.lambertw方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_wrightomega_region2

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import lambertw [as 別名]
def test_wrightomega_region2():
    # This region gets less coverage in the TestSystematic test
    x = np.linspace(-2, 1)
    y = np.linspace(-2*np.pi, -1)
    x, y = np.meshgrid(x, y)
    z = (x + 1j*y).flatten()

    dataset = []
    for z0 in z:
        dataset.append((z0, complex(_mpmath_wrightomega(z0, 25))))
    dataset = np.asarray(dataset)

    FuncData(sc.wrightomega, dataset, 0, 1, rtol=1e-15).check()


# ------------------------------------------------------------------------------
# lambertw
# ------------------------------------------------------------------------------ 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:20,代碼來源:test_mpmath.py

示例2: prox_max_entropy

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import lambertw [as 別名]
def prox_max_entropy(X, step, gamma=1, type="relative"):
    """Proximal operator for maximum entropy regularization.

    g(x) = gamma sum_i x_i ln(x_i)

    has the analytical solution of gamma W(1/gamma exp((X-gamma)/gamma)), where
    W is the Lambert W function.

    If type == 'relative', the penalty is expressed in units of the function value;
    if type == 'absolute', it's expressed in units of the variable `X`.
    """
    from scipy.special import lambertw

    assert type in ["relative", "absolute"]
    if type == "relative":
        gamma_ = _step_gamma(step, gamma)
    else:
        gamma_ = gamma
    # minimize entropy: return gamma_ * np.real(lambertw(np.exp((X - gamma_) / gamma_) / gamma_))
    above = X > 0
    X[above] = gamma_ * np.real(lambertw(np.exp(X[above] / gamma_ - 1) / gamma_))
    return X 
開發者ID:pmelchior,項目名稱:proxmin,代碼行數:24,代碼來源:operators.py

示例3: test_ufunc

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import lambertw [as 別名]
def test_ufunc():
    assert_array_almost_equal(
        lambertw(r_[0., e, 1.]), r_[0., 1., 0.567143290409783873]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:5,代碼來源:test_lambertw.py

示例4: test_lambertw

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import lambertw [as 別名]
def test_lambertw(self):
        assert_mpmath_equal(lambda x, k: sc.lambertw(x, int(k)),
                            lambda x, k: mpmath.lambertw(x, int(k)),
                            [Arg(), IntArg(0, 10)]) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:6,代碼來源:test_mpmath.py

示例5: test_lambertw

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import lambertw [as 別名]
def test_lambertw(self):
        # python-list/2010-December/594592.html
        xxroot = fixed_point(lambda xx: np.exp(-2.0*xx)/2.0, 1.0,
                args=(), xtol=1e-12, maxiter=500)
        assert_allclose(xxroot, np.exp(-2.0*xxroot)/2.0)
        assert_allclose(xxroot, lambertw(1)/2) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:8,代碼來源:test_minpack.py

示例6: test_lambertw_ufunc_loop_selection

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import lambertw [as 別名]
def test_lambertw_ufunc_loop_selection():
    # see https://github.com/scipy/scipy/issues/4895
    dt = np.dtype(np.complex128)
    assert_equal(lambertw(0, 0, 0).dtype, dt)
    assert_equal(lambertw([0], 0, 0).dtype, dt)
    assert_equal(lambertw(0, [0], 0).dtype, dt)
    assert_equal(lambertw(0, 0, [0]).dtype, dt)
    assert_equal(lambertw([0], [0], [0]).dtype, dt) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:10,代碼來源:test_lambertw.py

示例7: _mpmath_wrightomega

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import lambertw [as 別名]
def _mpmath_wrightomega(z, dps):
    with mpmath.workdps(dps):
        z = mpmath.mpc(z)
        unwind = mpmath.ceil((z.imag - mpmath.pi)/(2*mpmath.pi))
        res = mpmath.lambertw(mpmath.exp(z), unwind)
    return res 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:8,代碼來源:test_mpmath.py

示例8: test_lambertw_real

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import lambertw [as 別名]
def test_lambertw_real(self):
        assert_mpmath_equal(lambda x, k: sc.lambertw(x, int(k.real)),
                            lambda x, k: mpmath.lambertw(x, int(k.real)),
                            [ComplexArg(-np.inf, np.inf), IntArg(0, 10)],
                            rtol=1e-13, nan_ok=False) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:7,代碼來源:test_mpmath.py

示例9: main

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import lambertw [as 別名]
def main():
    parser = argparse.ArgumentParser(
        description="Estimates parameter for scheduled sampling.")
    parser.add_argument("--value", type=float, required=True,
                        help="The value the threshold should achieve.")
    parser.add_argument("--step", type=int, required=True,
                        help="Step when you want to achieve the value.")
    args = parser.parse_args()

    x = args.step
    c = args.value

    coeff = c * np.exp(lambertw((1 - c) / c * x)) / (1 - c)

    print(coeff.real) 
開發者ID:ufal,項目名稱:neuralmonkey,代碼行數:17,代碼來源:estimate_scheduled_sampling.py

示例10: lambertw

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import lambertw [as 別名]
def lambertw(*args, **kwargs):
            from scipy.special import lambertw
            return lambertw(*args, **kwargs) 
開發者ID:CalebBell,項目名稱:fluids,代碼行數:5,代碼來源:__init__.py

示例11: erf

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import lambertw [as 別名]
def erf(*args, **kwargs):
            from scipy.special import erf
            return erf(*args, **kwargs)


#    from scipy.special import lambertw, ellipe, gammaincc, gamma # fluids
#    from scipy.special import i1, i0, k1, k0, iv # ht
#    from scipy.special import hyp2f1    
#    if erf is None:
#        from scipy.special import erf 
開發者ID:CalebBell,項目名稱:fluids,代碼行數:12,代碼來源:__init__.py

示例12: w_d

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import lambertw [as 別名]
def w_d(z, delta):
    # Eq. 9
    if delta < _EPS:
        return z
    return np.sign(z) * np.sqrt(np.real(special.lambertw(delta * z ** 2)) / delta) 
開發者ID:gregversteeg,項目名稱:gaussianize,代碼行數:7,代碼來源:gaussianize.py

示例13: _lambertw_i_from_v

# 需要導入模塊: from scipy import special [as 別名]
# 或者: from scipy.special import lambertw [as 別名]
def _lambertw_i_from_v(resistance_shunt, resistance_series, nNsVth, voltage,
                       saturation_current, photocurrent):
    try:
        from scipy.special import lambertw
    except ImportError:
        raise ImportError('This function requires scipy')

    # Record if inputs were all scalar
    output_is_scalar = all(map(np.isscalar,
                               [resistance_shunt, resistance_series, nNsVth,
                                voltage, saturation_current, photocurrent]))

    # This transforms Gsh=1/Rsh, including ideal Rsh=np.inf into Gsh=0., which
    #  is generally more numerically stable
    conductance_shunt = 1. / resistance_shunt

    # Ensure that we are working with read-only views of numpy arrays
    # Turns Series into arrays so that we don't have to worry about
    #  multidimensional broadcasting failing
    Gsh, Rs, a, V, I0, IL = \
        np.broadcast_arrays(conductance_shunt, resistance_series, nNsVth,
                            voltage, saturation_current, photocurrent)

    # Intitalize output I (V might not be float64)
    I = np.full_like(V, np.nan, dtype=np.float64)           # noqa: E741, N806

    # Determine indices where 0 < Rs requires implicit model solution
    idx_p = 0. < Rs

    # Determine indices where 0 = Rs allows explicit model solution
    idx_z = 0. == Rs

    # Explicit solutions where Rs=0
    if np.any(idx_z):
        I[idx_z] = IL[idx_z] - I0[idx_z] * np.expm1(V[idx_z] / a[idx_z]) - \
                   Gsh[idx_z] * V[idx_z]

    # Only compute using LambertW if there are cases with Rs>0
    # Does NOT handle possibility of overflow, github issue 298
    if np.any(idx_p):
        # LambertW argument, cannot be float128, may overflow to np.inf
        argW = Rs[idx_p] * I0[idx_p] / (
                    a[idx_p] * (Rs[idx_p] * Gsh[idx_p] + 1.)) * \
               np.exp((Rs[idx_p] * (IL[idx_p] + I0[idx_p]) + V[idx_p]) /
                      (a[idx_p] * (Rs[idx_p] * Gsh[idx_p] + 1.)))

        # lambertw typically returns complex value with zero imaginary part
        # may overflow to np.inf
        lambertwterm = lambertw(argW).real

        # Eqn. 2 in Jain and Kapoor, 2004
        #  I = -V/(Rs + Rsh) - (a/Rs)*lambertwterm + Rsh*(IL + I0)/(Rs + Rsh)
        # Recast in terms of Gsh=1/Rsh for better numerical stability.
        I[idx_p] = (IL[idx_p] + I0[idx_p] - V[idx_p] * Gsh[idx_p]) / \
                   (Rs[idx_p] * Gsh[idx_p] + 1.) - (
                               a[idx_p] / Rs[idx_p]) * lambertwterm

    if output_is_scalar:
        return I.item()
    else:
        return I 
開發者ID:pvlib,項目名稱:pvlib-python,代碼行數:63,代碼來源:singlediode.py


注:本文中的scipy.special.lambertw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。