本文整理匯總了Python中sympy.log方法的典型用法代碼示例。如果您正苦於以下問題:Python sympy.log方法的具體用法?Python sympy.log怎麽用?Python sympy.log使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sympy
的用法示例。
在下文中一共展示了sympy.log方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Simple_manifold_with_scalar_function_derivative
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [as 別名]
def Simple_manifold_with_scalar_function_derivative():
coords = (x,y,z) = symbols('x y z')
basis = (e1, e2, e3, grad) = MV.setup('e_1 e_2 e_3',metric='[1,1,1]',coords=coords)
# Define surface
mfvar = (u,v) = symbols('u v')
X = u*e1+v*e2+(u**2+v**2)*e3
print X
MF = Manifold(X,mfvar)
# Define field on the surface.
g = (v+1)*log(u)
# Method 1: Using old Manifold routines.
VectorDerivative = (MF.rbasis[0]/MF.E_sq)*diff(g,u) + (MF.rbasis[1]/MF.E_sq)*diff(g,v)
print 'Vector derivative =', VectorDerivative.subs({u:1,v:0})
# Method 2: Using new Manifold routines.
dg = MF.Grad(g)
print 'Vector derivative =', dg.subs({u:1,v:0})
return
示例2: Simple_manifold_with_scalar_function_derivative
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [as 別名]
def Simple_manifold_with_scalar_function_derivative():
Print_Function()
coords = (x,y,z) = symbols('x y z')
basis = (e1, e2, e3, grad) = MV.setup('e_1 e_2 e_3',metric='[1,1,1]',coords=coords)
# Define surface
mfvar = (u,v) = symbols('u v')
X = u*e1+v*e2+(u**2+v**2)*e3
print '\\f{X}{u,v} =',X
MF = Manifold(X,mfvar)
(eu,ev) = MF.Basis()
# Define field on the surface.
g = (v+1)*log(u)
print '\\f{g}{u,v} =',g
# Method 1: Using old Manifold routines.
VectorDerivative = (MF.rbasis[0]/MF.E_sq)*diff(g,u) + (MF.rbasis[1]/MF.E_sq)*diff(g,v)
print '\\eval{\\nabla g}{u=1,v=0} =', VectorDerivative.subs({u:1,v:0})
# Method 2: Using new Manifold routines.
dg = MF.Grad(g)
print '\\eval{\\f{Grad}{g}}{u=1,v=0} =', dg.subs({u:1,v:0})
dg = MF.grad*g
print '\\eval{\\nabla g}{u=1,v=0} =', dg.subs({u:1,v:0})
return
示例3: grad_log_norm_symbolic
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [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
]
示例4: _compute_local_sens_gnmax
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [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)
示例5: test_expression_builder_complex
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [as 別名]
def test_expression_builder_complex(self, test_time_series):
from sympy import symbols, cos, sin, pi, log, sqrt
abc = list("abcdefghij")
syms = symbols(abc)
expression = syms[0]
for s in syms:
expression = expression + s
expression = (
(expression * expression)
+ sqrt(sin(pi * 0.1 ** syms[1]))
+ log(23 + syms[5] ** 1.234)
+ cos(syms[3] ** (1 + 0.1 ** syms[4]))
+ sqrt(log(abs(syms[8]) + 1))
)
dps1 = COGNITE_CLIENT.datapoints.synthetic.query(
expressions=[expression],
start=datetime(2017, 1, 1),
end="now",
limit=100,
variables={v: test_time_series[tsi] for v, tsi in zip(abc, range(10))},
)[0]
assert 100 == len(dps1)
示例6: test_singularities_non_rational
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [as 別名]
def test_singularities_non_rational():
x = Symbol('x', real=True)
assert singularities(exp(1/x), x) == (0)
assert singularities(log((x - 2)**2), x) == (2)
示例7: Distorted_manifold_with_scalar_function
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [as 別名]
def Distorted_manifold_with_scalar_function():
coords = symbols('x y z')
(ex,ey,ez,grad) = MV.setup('ex ey ez',metric='[1,1,1]',coords=coords)
mfvar = (u,v) = symbols('u v')
X = 2*u*ex+2*v*ey+(u**3+v**3/2)*ez
MF = Manifold(X,mfvar,I=MV.I)
(eu,ev) = MF.Basis()
g = (v+1)*log(u)
dg = MF.Grad(g)
print 'g =',g
print 'dg =',dg
print 'dg(1,0) =',dg.subs({u:1,v:0})
G = u*eu+v*ev
dG = MF.Grad(G)
print 'G =',G
print 'P(G) =',MF.Proj(G)
print 'zcoef =',simplify(2*(u**2 + v**2)*(-4*u**2 - 4*v**2 - 1))
print 'dG =',dG
print 'P(dG) =',MF.Proj(dG)
PS = u*v*eu^ev
print 'PS =',PS
print 'dPS =',MF.Grad(PS)
print 'P(dPS) =',MF.Proj(MF.Grad(PS))
return
示例8: Distorted_manifold_with_scalar_function
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [as 別名]
def Distorted_manifold_with_scalar_function():
Print_Function()
coords = symbols('x y z')
(ex,ey,ez,grad) = MV.setup('e_x e_y e_z',metric='[1,1,1]',coords=coords)
mfvar = (u,v) = symbols('u v')
X = 2*u*ex+2*v*ey+(u**3+v**3/2)*ez
MF = Manifold(X,mfvar,I=MV.I)
(eu,ev) = MF.Basis()
g = (v+1)*log(u)
dg = MF.Grad(g)
print 'g =',g
print 'dg =',dg
print '\\eval{dg}{u=1,v=0} =',dg.subs({u:1,v:0})
G = u*eu+v*ev
dG = MF.Grad(G)
print 'G =',G
print 'P(G) =',MF.Proj(G)
print 'dG =',dG
print 'P(dG) =',MF.Proj(dG)
PS = u*v*eu^ev
print 'P(S) =',PS
print 'dP(S) =',MF.Grad(PS)
print 'P(dP(S)) =',MF.Proj(MF.Grad(PS))
return
示例9: Simple_manifold_with_vector_function_derivative
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [as 別名]
def Simple_manifold_with_vector_function_derivative():
Print_Function()
coords = (x,y,z) = symbols('x y z')
basis = (ex, ey, ez, grad) = \
MV.setup('e_x e_y e_z',metric='[1,1,1]',coords=coords)
# Define surface
mfvar = (u,v) = symbols('u v')
X = u*ex+v*ey+(u**2+v**2)*ez
print '\\f{X}{u,v} =',X
MF = Manifold(X,mfvar)
(eu,ev) = MF.Basis()
# Define field on the surface.
g = (v+1)*log(u)
print '\\mbox{Scalar Function: } g =',g
dg = MF.grad*g
dg.Fmt(3,'\\mbox{Scalar Function Derivative: } \\nabla g')
print '\\eval{\\nabla g}{(1,0)} =',dg.subs({u:1,v:0})
# Define vector field on the surface
G = v**2*eu+u**2*ev
print '\\mbox{Vector Function: } G =',G
dG = MF.grad*G
dG.Fmt(3,'\\mbox{Vector Function Derivative: } \\nabla G')
print '\\eval{\\nabla G}{(1,0)} =',dG.subs({u:1,v:0})
return
示例10: log_norm
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [as 別名]
def log_norm(self, remove_duplicate_eigenvalues=True):
return np.log(self.norm(remove_duplicate_eigenvalues=remove_duplicate_eigenvalues))
示例11: _compute_logq1
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [as 別名]
def _compute_logq1(sigma, order, num_classes):
logq0 = _compute_logq0(sigma, order) # Most likely already cached.
logq1 = math.log(_compute_bl_gnmax(math.exp(logq0), sigma, num_classes))
assert logq1 <= logq0
return logq1
示例12: _compute_data_dep_bound_gnmax
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [as 別名]
def _compute_data_dep_bound_gnmax(sigma, logq, order):
# Applies Theorem 6 in Appendix without checking that logq satisfies necessary
# constraints. The pre-conditions must be assured by comparing logq against
# logq0 by the caller.
variance = sigma**2
mu1, mu2 = _compute_mu1_mu2_gnmax(sigma, logq)
eps1 = mu1 / variance
eps2 = mu2 / variance
log1q = np.log1p(-math.exp(logq)) # log1q = log(1-q)
log_a = (order - 1) * (
log1q - (np.log1p(-math.exp((logq + eps2) * (1 - 1 / mu2)))))
log_b = (order - 1) * (eps1 - logq / (mu1 - 1))
return np.logaddexp(log1q + log_a, logq + log_b) / (order - 1)
示例13: compute_rdp_of_smooth_sensitivity_gaussian
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [as 別名]
def compute_rdp_of_smooth_sensitivity_gaussian(beta, sigma, order):
"""Computes the RDP curve for the GNSS mechanism.
Implements Theorem 23 (https://arxiv.org/pdf/1802.08908.pdf).
"""
if beta > 0 and not 1 < order < 1 / (2 * beta):
raise ValueError("Order outside the (1, 1/(2*beta)) range.")
return order * math.exp(2 * beta) / sigma**2 + (
-.5 * math.log(1 - 2 * order * beta) + beta * order) / (
order - 1)
示例14: test_log
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [as 別名]
def test_log():
x = Symbol("x")
x1 = sympy.Symbol("x")
assert log(x) == log(x1)
assert log(x)._sympy_() == sympy.log(x1)
assert sympify(sympy.log(x1)) == log(x)
y = Symbol("y")
y1 = sympy.Symbol("y")
assert log(x, y) == log(x, y1)
assert log(x1, y) == log(x1, y1)
assert log(x, y)._sympy_() == sympy.log(x1, y1)
assert sympify(sympy.log(x1, y1)) == log(x, y)
示例15: test_entropy
# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import log [as 別名]
def test_entropy():
up = JzKet(S(1)/2, S(1)/2)
down = JzKet(S(1)/2, -S(1)/2)
d = Density((up, 0.5), (down, 0.5))
# test for density object
ent = entropy(d)
assert entropy(d) == 0.5*log(2)
assert d.entropy() == 0.5*log(2)
np = import_module('numpy', min_module_version='1.4.0')
if np:
#do this test only if 'numpy' is available on test machine
np_mat = represent(d, format='numpy')
ent = entropy(np_mat)
assert isinstance(np_mat, np.matrixlib.defmatrix.matrix)
assert ent.real == 0.69314718055994529
assert ent.imag == 0
scipy = import_module('scipy', __import__kwargs={'fromlist': ['sparse']})
if scipy and np:
#do this test only if numpy and scipy are available
mat = represent(d, format="scipy.sparse")
assert isinstance(mat, scipy_sparse_matrix)
assert ent.real == 0.69314718055994529
assert ent.imag == 0