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


Python sympy.exp方法代码示例

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


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

示例1: test_construct_lazy

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def test_construct_lazy(self):
        # adapted from https://gist.github.com/raddy/bd0e977dc8437a4f8276
        spot, strike, vol, dte, rate, cp = sy.symbols('spot strike vol dte rate cp')

        T = dte / 260.
        N = syNormal('N', 0.0, 1.0)

        d1 = (sy.ln(spot / strike) + (0.5 * vol ** 2) * T) / (vol * sy.sqrt(T))
        d2 = d1 - vol * sy.sqrt(T)

        TimeValueExpr = sy.exp(-rate * T) * (cp * spot * cdf(N)(cp * d1) - cp * strike * cdf(N)(cp * d2))

        PriceClass = ts.construct_lazy(TimeValueExpr)

        price = PriceClass(spot=210.59, strike=205, vol=14.04, dte=4, rate=.2175, cp=-1)

        x = price.evaluate()()

        assert price.evaluate()() == x

        price.strike = 210

        assert x != price.evaluate()() 
开发者ID:timkpaine,项目名称:tributary,代码行数:25,代码来源:test_symbolic.py

示例2: _doctest_grad_log_norm_symbolic

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def _doctest_grad_log_norm_symbolic(self):
        """
        >>> import pytest; pytest.skip('Bingham is to slow')
        >>> import sympy
        >>> trainer = ComplexBinghamTrainer(2)
        >>> trainer.grad_log_norm_symbolic[0]
        ((x0 - x1)*exp(x0) - exp(x0) + exp(x1))/((x0 - x1)*(exp(x0) - exp(x1)))
        >>> trainer.grad_log_norm_symbolic[1]
        (-(x0 - x1)*exp(x1) + exp(x0) - exp(x1))/((x0 - x1)*(exp(x0) - exp(x1)))
        >>> print(sympy.printing.pretty(
        ...     trainer.grad_log_norm_symbolic))  # doctest: +NORMALIZE_WHITESPACE
                    x0    x0    x1               x1    x0    x1
         (x0 - x1)*e   - e   + e    - (x0 - x1)*e   + e   - e
        [-------------------------, ---------------------------]
                     / x0    x1\\                 / x0    x1\\
           (x0 - x1)*\\e   - e  /       (x0 - x1)*\\e   - e  /

        """ 
开发者ID:fgnt,项目名称:pb_bss,代码行数:20,代码来源:complex_bingham.py

示例3: grad_log_norm_symbolic

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def grad_log_norm_symbolic(self):
        import sympy
        D = self.dimension
        X = self.eigenvalues_symbol
        B = [1] * D
        for d in range(D):
            for dd in range(D):
                if d != dd:
                    B[d] = B[d] * (X[d] - X[dd])
        B = [1 / b for b in B]

        p_D = sympy.pi ** D

        tmp = [b * sympy.exp(x_) for x_, b in zip(X, B)]
        tmp = sum(tmp)
        symbolic_norm_for_bingham = 2 * p_D * tmp

        return [
            sympy.simplify(sympy.diff(
                sympy.log(symbolic_norm_for_bingham),
                x_
            ))
            for x_ in X
        ] 
开发者ID:fgnt,项目名称:pb_bss,代码行数:26,代码来源:complex_bingham.py

示例4: _compute_local_sens_gnmax

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def _compute_local_sens_gnmax(logq, sigma, num_classes, order):
  """Implements Algorithm 3 (computes an upper bound on local sensitivity).

  (See Proposition 13 for proof of correctness.)
  """
  logq0 = _compute_logq0(sigma, order)
  logq1 = _compute_logq1(sigma, order, num_classes)
  if logq1 <= logq <= logq0:
    logq = logq1

  beta = _compute_rdp_gnmax(sigma, logq, order)
  beta_bu_q = _compute_rdp_gnmax(
      sigma, math.log(_compute_bu_gnmax(math.exp(logq), sigma, num_classes)),
      order)
  beta_bl_q = _compute_rdp_gnmax(
      sigma, math.log(_compute_bl_gnmax(math.exp(logq), sigma, num_classes)),
      order)
  return max(beta_bu_q - beta, beta - beta_bl_q) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:20,代码来源:smooth_sensitivity.py

示例5: check_conditions

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def check_conditions(sigma, m, order):
  """Checks conditions C5 and C6 (Section B.4.2 in Appendix)."""
  q = sp.symbols("q", positive=True, real=True)

  beta = _construct_symbolic_beta(q, sigma, order)
  q0 = math.exp(compute_logq0_gnmax(sigma, order))

  cond5 = _is_non_decreasing(beta, q, (0, q0))

  if cond5:
    bl_q0 = _compute_bl_gnmax(q0, sigma, m)

    bu = _construct_symbolic_bu(q, sigma, m)
    delta_beta = beta.subs(q, bu) - beta

    cond6 = _is_non_decreasing(delta_beta, q, (0, bl_q0))
  else:
    cond6 = False  # Skip the check, since Condition 5 is false already.

  return (cond5, cond6) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:22,代码来源:smooth_sensitivity.py

示例6: findomega

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def findomega(stab_fh):
    assert np.array_equal(np.shape(stab_fh), [2, 2]), 'Not 2x2 matrix...'
    omega = sympy.Symbol('omega')
    func = (sympy.exp(-1j * omega) - stab_fh[0, 0]) * (sympy.exp(-1j * omega) - stab_fh[1, 1]) - \
        stab_fh[0, 1] * stab_fh[1, 0]
    solsym = sympy.solve(func, omega)
    sol0 = complex(solsym[0])
    sol1 = complex(solsym[1])
    if sol0.real >= 0:
        sol = sol0
    elif sol1.real >= 0:
        sol = sol1
    else:
        print("Two roots with real part of same sign...")
        sol = sol0
    return sol 
开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:18,代码来源:plot_dispersion.py

示例7: test_integrate

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def test_integrate():
    moments = quadpy.tools.integrate(lambda x: [x ** k for k in range(5)], -1, +1)
    assert (moments == [2, 0, sympy.S(2) / 3, 0, sympy.S(2) / 5]).all()

    moments = quadpy.tools.integrate(
        lambda x: orthopy.line_segment.tree_legendre(x, 4, "monic", symbolic=True),
        -1,
        +1,
    )
    assert (moments == [2, 0, 0, 0, 0]).all()

    # Example from Gautschi's "How to and how not to" article
    moments = quadpy.tools.integrate(
        lambda x: [x ** k * sympy.exp(-(x ** 3) / 3) for k in range(5)], 0, sympy.oo
    )
    S = numpy.vectorize(sympy.S)
    gamma = numpy.vectorize(sympy.gamma)
    n = numpy.arange(5)
    reference = 3 ** (S(n - 2) / 3) * gamma(S(n + 1) / 3)
    assert numpy.all([sympy.simplify(m - r) == 0 for m, r in zip(moments, reference)]) 
开发者ID:nschloe,项目名称:quadpy,代码行数:22,代码来源:test_tools.py

示例8: test_get_odesys_1

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def test_get_odesys_1():
    k = .2
    a = Substance('A')
    b = Substance('B')
    r = Reaction({'A': 1}, {'B': 1}, param=k)
    rsys = ReactionSystem([r], [a, b])
    assert sorted(rsys.substances.keys()) == ['A', 'B']
    odesys = get_odesys(rsys, include_params=True)[0]
    c0 = {
        'A': 1.0,
        'B': 3.0,
    }
    t = np.linspace(0.0, 10.0)
    xout, yout, info = odesys.integrate(t, c0)
    yref = np.zeros((t.size, 2))
    yref[:, 0] = np.exp(-k*t)
    yref[:, 1] = 4 - np.exp(-k*t)
    assert np.allclose(yout, yref) 
开发者ID:bjodah,项目名称:chempy,代码行数:20,代码来源:test_ode.py

示例9: test_get_odesys__rate_exprs_cb

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def test_get_odesys__rate_exprs_cb():
    k = .2
    a = Substance('A')
    b = Substance('B')
    r = Reaction({'A': 1}, {'B': 1}, param=k)
    rsys = ReactionSystem([r], [a, b])
    assert sorted(rsys.substances.keys()) == ['A', 'B']
    odesys, extra = get_odesys(rsys)
    c0 = {'A': 1.0, 'B': 3.0}
    t = np.linspace(0.0, 10.0)
    res = odesys.integrate(t, c0)
    yref = np.zeros((t.size, 2))
    yref[:, 0] = np.exp(-k*t)
    yref[:, 1] = 4 - np.exp(-k*t)
    assert np.allclose(res.yout, yref)
    rate = extra['rate_exprs_cb'](res.xout, res.yout, res.params)
    assert np.allclose(rate[:, 0], k*yref[:, 0]) 
开发者ID:bjodah,项目名称:chempy,代码行数:19,代码来源:test_ode.py

示例10: test_get_odesys__ScaledSys

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def test_get_odesys__ScaledSys():
    from pyodesys.symbolic import ScaledSys
    k = .2
    a = Substance('A')
    b = Substance('B')
    r = Reaction({'A': 1}, {'B': 1}, param=k)
    rsys = ReactionSystem([r], [a, b])
    assert sorted(rsys.substances.keys()) == ['A', 'B']
    odesys = get_odesys(rsys, include_params=True, SymbolicSys=ScaledSys)[0]
    c0 = {
        'A': 1.0,
        'B': 3.0,
    }
    t = np.linspace(0.0, 10.0)
    xout, yout, info = odesys.integrate(t, c0)
    yref = np.zeros((t.size, 2))
    yref[:, 0] = np.exp(-k*t)
    yref[:, 1] = 4 - np.exp(-k*t)
    assert np.allclose(yout, yref) 
开发者ID:bjodah,项目名称:chempy,代码行数:21,代码来源:test_ode.py

示例11: test_create_odesys__validate__catalyst

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def test_create_odesys__validate__catalyst():
    rsys1 = ReactionSystem.from_string("""
    H2O2 + Pt -> 2 OH + Pt; 'k_decomp'
    """)
    ic1 = defaultdict(lambda: 0*u.molar, {'H2O2': 3.0*u.molar, 'Pt': 0.5*u.molar})
    t1 = linspace(0*u.s, .3*u.s, 7)
    p1 = dict(k_decomp=42/u.second/u.molar)
    odesys1, odesys_extra = create_odesys(rsys1)
    validation = odesys_extra['validate'](dict(ic1, **p1))
    assert not validation['not_seen']

    dedim_ctx = _mk_dedim(SI_base_registry)
    (t, c, _p), dedim_extra = dedim_ctx['dedim_tcp'](t1, [ic1[k] for k in odesys1.names], p1)
    result1 = odesys1.integrate(t, c, _p)
    tout = result1.xout * dedim_extra['unit_time']
    cout = result1.yout * dedim_extra['unit_conc']
    yref1 = ic1['H2O2']*np.exp(-tout*ic1['Pt']*p1['k_decomp'])
    assert allclose(yref1, cout[:, odesys1.names.index('H2O2')], rtol=1e-6) 
开发者ID:bjodah,项目名称:chempy,代码行数:20,代码来源:test_ode.py

示例12: test_gaussian

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def test_gaussian():
    """
    Make sure that symfit.distributions.Gaussians produces the expected
    sympy expression.
    """
    x0 = Parameter()
    sig = Parameter(positive=True)
    x = Variable()

    new = sympy.exp(-(x - x0)**2/(2*sig**2))/sympy.sqrt((2*sympy.pi*sig**2))
    assert isinstance(new, sympy.Expr)
    g = Gaussian(x, x0, sig)
    assert issubclass(g.__class__, sympy.Expr)
    assert new == g

    # A pdf should always integrate to 1 on its domain
    assert sympy.integrate(g, (x, -sympy.oo, sympy.oo)) == 1 
开发者ID:tBuLi,项目名称:symfit,代码行数:19,代码来源:test_distributions.py

示例13: test_exp

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def test_exp():
    """
    Make sure that symfit.distributions.Exp produces the expected
    sympy expression.
    """
    l = Parameter(positive=True)
    x = Variable()

    new = l * sympy.exp(- l * x)
    assert isinstance(new, sympy.Expr)
    e = Exp(x, l)
    assert issubclass(e.__class__, sympy.Expr)
    assert new == e

    # A pdf should always integrate to 1 on its domain
    assert sympy.integrate(e, (x, 0, sympy.oo)) == 1 
开发者ID:tBuLi,项目名称:symfit,代码行数:18,代码来源:test_distributions.py

示例14: BivariateGaussian

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def BivariateGaussian(x, y, mu_x, mu_y, sig_x, sig_y, rho):
    """
    `Bivariate Gaussian pdf
    <http://mathworld.wolfram.com/BivariateNormalDistribution.html>`_.

    :param x: :class:`symfit.core.argument.Variable`
    :param y: :class:`symfit.core.argument.Variable`
    :param mu_x: :class:`symfit.core.argument.Parameter` for the mean of `x`
    :param mu_y: :class:`symfit.core.argument.Parameter` for the mean of `y`
    :param sig_x: :class:`symfit.core.argument.Parameter` for the standard
        deviation of `x`
    :param sig_y: :class:`symfit.core.argument.Parameter` for the standard
        deviation of `y`
    :param rho: :class:`symfit.core.argument.Parameter` for the correlation
        between `x` and `y`.
    :return: sympy expression for a Bivariate Gaussian pdf.
    """
    exponent = - 1 / (2 * (1 - rho**2))
    exponent *= (x - mu_x)**2 / sig_x**2 + (y - mu_y)**2 / sig_y**2 \
                - 2 * rho * (x - mu_x) * (y - mu_y) / (sig_x * sig_y)
    return sympy.exp(exponent) / (2 * sympy.pi * sig_x * sig_y * sympy.sqrt(1 - rho**2)) 
开发者ID:tBuLi,项目名称:symfit,代码行数:23,代码来源:distributions.py

示例15: Exp

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import exp [as 别名]
def Exp(x, l):
    """
    .. math::

        f(x) = l e^{- l x}

    Exponential Distribution pdf.

    :param x: free variable.
    :param l: rate parameter.
    :return: sympy.Expr for an Exponential Distribution pdf.
    """
    return l * sympy.exp(- l * x)

# def Beta():
#     sympy.stats.Beta() 
开发者ID:tBuLi,项目名称:symfit,代码行数:18,代码来源:distributions.py


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