本文整理汇总了Python中math.atanh函数的典型用法代码示例。如果您正苦于以下问题:Python atanh函数的具体用法?Python atanh怎么用?Python atanh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了atanh函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: correlation_MRRtest
def correlation_MRRtest(rx1y, rx2y, rx1x2, n):
"""Meng-Rosenthal-Rubin method comparing two correlated
correlation coefficients.
:param float rx1y: the correlation coefficient between variables x1 and y
:param float rx2y: the correlation coefficient between variables x2 and y
:param float rx1x2: the correlation coefficient between variables x1 and x2
:param int n: sample size
:return: two-tailed p-value
Reference: Meng et al. (1992), Psychol. Bull. 111, 172,
"""
assert (-1<=rx1y<=1) and (-1<=rx2y<=1) and (-1<=rx1x2<=1), \
"Correlation coefficients should be in ]-1,1["
from math import sqrt, atanh
z1 = atanh(rx1y) # Fisher's Z-transformation
z2 = atanh(rx2y)
rs = (rx1y**2 + rx2y**2)/2.
f = min((1 - rx1x2)/(2*(1 - rs)), 1)
h = (1 - f*rs) / (1 - rs)
dz = (z1 - z2) * sqrt((n - 3)/(2 * (1 - rx1x2) * h))
p = 2 * S.distributions.norm.sf(abs(dz)) # Two-tailed probability
return p
示例2: fromwgs84
def fromwgs84(lat, lng, pkm=False):
"""
Convert coordintes from WGS84 to TWD97
pkm true for Penghu, Kinmen and Matsu area
The latitude and longitude can be in the following formats:
[+/-]DDD°MMM'SSS.SSSS" (unicode)
[+/-]DDD°MMM.MMMM' (unicode)
[+/-]DDD.DDDDD (string, unicode or float)
The returned coordinates are in meters
"""
_lng0 = lng0pkm if pkm else lng0
lat = radians(todegdec(lat))
lng = radians(todegdec(lng))
t = sinh((atanh(sin(lat)) - 2*pow(n,0.5)/(1+n)*atanh(2*pow(n,0.5)/(1+n)*sin(lat))))
epsilonp = atan(t/cos(lng-_lng0))
etap = atan(sin(lng-_lng0) / pow(1+t*t, 0.5))
E = E0 + k0*A*(etap + alpha1*cos(2*1*epsilonp)*sinh(2*1*etap) +
alpha2*cos(2*2*epsilonp)*sinh(2*2*etap) +
alpha3*cos(2*3*epsilonp)*sinh(2*3*etap))
N = N0 + k0*A*(epsilonp + alpha1*sin(2*1*epsilonp)*cosh(2*1*etap) +
alpha2*sin(2*2*epsilonp)*cosh(2*2*etap) +
alpha3*sin(2*3*epsilonp)*cosh(2*3*etap))
return E*1000, N*1000
示例3: test_atanh
def test_atanh(self):
import math
self.ftest(math.atanh(0), 0)
self.ftest(math.atanh(0.5), 0.54930614433405489)
self.ftest(math.atanh(-0.5), -0.54930614433405489)
raises(ValueError, math.atanh, 1.)
assert math.isnan(math.atanh(float("nan")))
示例4: pwmTOu
def pwmTOu(pwm):
u = np.array([0.0,0.0])
u[0] = math.atanh((pwm[0]-1800)/200)+1
u[1] = math.atanh((pwm[1]-1500)/500)
return u
# # # FIN PARTIE SIMULATION # # #
示例5: testAtanh
def testAtanh(self):
self.assertRaises(TypeError, math.atan)
self.ftest('atanh(0)', math.atanh(0), 0)
self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
self.assertRaises(ValueError, math.atanh, 1)
self.assertRaises(ValueError, math.atanh, -1)
self.assertRaises(ValueError, math.atanh, INF)
self.assertRaises(ValueError, math.atanh, NINF)
self.assert_(math.isnan(math.atanh(NAN)))
示例6: min_f
def min_f(self, a, b):
"""Custom minimum function using inverse hyperbolic function."""
if a >= 2:
a = 1.99
if a <= 0:
a = 0.01
if b >= 2:
b = 1.99
if b <= 0:
b = 0.01
return 1 - math.tanh(math.atanh(1 - a) + math.atanh(1 - b))
示例7: correlation
def correlation(x, y):
"""Calculate correlation with p-value and confidence interval."""
assert len(x) == len(y)
#r, p = sp.stats.pearsonr(x, y)
#r, p = sp.stats.kendalltau(x, y)
r, p = sp.stats.spearmanr(x, y)
n = len(x)
stderr = 1.0 / math.sqrt(n-3)
delta = 1.96 * stderr
lower = math.tanh(math.atanh(r) - delta)
upper = math.tanh(math.atanh(r) + delta)
return dict(r=r, p=p, lower=lower, upper=upper)
示例8: _constants
def _constants(self, stages, bits):
if self.func_mode == "circular":
s = range(stages)
a = [atan(2**-i) for i in s]
g = [sqrt(1 + 2**(-2*i)) for i in s]
#zmax = sum(a)
# use pi anyway as the input z can cause overflow
# and we need the range for quadrant mapping
zmax = pi
elif self.func_mode == "linear":
s = range(stages)
a = [2**-i for i in s]
g = [1 for i in s]
#zmax = sum(a)
# use 2 anyway as this simplifies a and scaling
zmax = 2.
else: # hyperbolic
s = []
# need to repeat some stages:
j = 4
for i in range(stages):
if i == j:
s.append(j)
j = 3*j + 1
s.append(i + 1)
a = [atanh(2**-i) for i in s]
g = [sqrt(1 - 2**(-2*i)) for i in s]
zmax = sum(a)*2
a = [int(ai*2**(bits - 1)/zmax) for ai in a]
# round here helps the width=2**i - 1 case but hurts the
# important width=2**i case
gain = 1.
for gi in g:
gain *= gi
return a, s, zmax, gain
示例9: fromGeographic
def fromGeographic(self, lat, lon):
lat_rad = radians(lat)
lon_rad = radians(lon)
B = cos(lat_rad) * sin(lon_rad - self.lon_rad)
x = self.radius * atanh(B)
y = self.radius * (atan(tan(lat_rad) / cos(lon_rad - self.lon_rad)) - self.lat_rad)
return x, y
示例10: compute
def compute(self, plug, data):
# Check if output value is connected
if plug == self.aOutputVaue:
# Get input datas
operationTypeHandle = data.inputValue(self.aOperationType)
operationType = operationTypeHandle.asInt()
inputValueXHandle = data.inputValue(self.aInputValueX)
inputValueX = inputValueXHandle.asFloat()
inputValueYHandle = data.inputValue(self.aInputValueY)
inputValueY = inputValueYHandle.asFloat()
# Math tanus
outputValue = 0
if operationType == 0:
outputValue = math.atan(inputValueX)
if operationType == 1:
outputValue = math.tan(inputValueX)
if operationType == 2:
outputValue = math.atanh(inputValueX)
if operationType == 3:
outputValue = math.tanh(inputValueX)
if operationType == 4:
outputValue = math.tanh(inputValueY, inputValueX)
# Output Value
output_data = data.outputValue(self.aOutputVaue)
output_data.setFloat(outputValue)
# Clean plug
data.setClean(plug)
示例11: hyperbolic_fun_cal
def hyperbolic_fun_cal(inp_val1, opn_type):
oprn_dic = {
'1': 'inverse hyperbolic cosine of x', '2':'inverse hyperbolic sine of x',
'3':' inverse hyperbolic tangent of x', '4':'hyperbolic cosine of x',
'5':'hyperbolic sine of x', '6':'hyperbolic tangent of x'}
if int(opn_type) == 1:
output = math.acosh(float(inp_val1))
return str(output)
if int(opn_type) == 2:
output = math.asinh(float(inp_val1))
return str(output)
if int(opn_type) == 3:
output = math.atanh(float(inp_val1))
return str(output)
if int(opn_type) == 4:
output = math.cosh(float(inp_val1))
return str(output)
if int(opn_type) == 5:
output = math.sinh(float(inp_val1))
return str(output)
if int(opn_type) == 6:
output = math.tanh(float(inp_val1))
return str(output)
else:
return "Invalid Operation"
示例12: bachelierFormulaImpliedVol
def bachelierFormulaImpliedVol(optionType,
strike,
forward,
tte,
bachelierPrice,
discount=1.0):
strike = float(strike)
forward = float(forward)
tte = float(tte)
bachelierPrice = float(bachelierPrice)
discount = float(discount)
pyFinAssert(tte > 0, ValueError, "tte ({0:f}) must be positive".format(tte))
SQRT_QL_EPSILON = math.sqrt(MathConstants.QL_EPSILON)
forwardPremium = bachelierPrice / discount
if optionType == OptionType.Call:
straddlePremium = 2.0 * forwardPremium - (forward - strike)
else:
straddlePremium = 2.0 * forwardPremium + (forward - strike)
nu = (forward - strike) / straddlePremium
nu = max(-1.0 + MathConstants.QL_EPSILON, min(nu, 1.0 - MathConstants.QL_EPSILON))
eta = 1.0 if (abs(nu) < SQRT_QL_EPSILON) else (nu / math.atanh(nu))
heta = HCalculator.calculate(eta)
impliedBpvol = math.sqrt(MathConstants.M_PI / (2 * tte)) * straddlePremium * heta
return impliedBpvol
示例13: __init__
def __init__(self, file_name):
proc = subprocess.Popen("../bin/meas_moments %s" % file_name, stdout=subprocess.PIPE, shell=True)
buf = os.read(proc.stdout.fileno(), 1000)
while proc.poll() == None:
pass
if proc.returncode != 0:
raise RuntimeError("meas_moments exited with an error code")
results = buf.split()
if results[0] is not "0":
raise RuntimeError("meas_moments returned an error status")
self.mxx = float(results[1])
self.myy = float(results[2])
self.mxy = float(results[3])
self.e1 = float(results[4])
self.e2 = float(results[5])
# These are distortions e1,e2
# Find the corresponding shear:
esq = self.e1 * self.e1 + self.e2 * self.e2
if esq > 0.0:
e = math.sqrt(esq)
g = math.tanh(0.5 * math.atanh(e))
self.g1 = self.e1 * (g / e)
self.g2 = self.e2 * (g / e)
else:
self.g1 = 0.0
self.g2 = 0.0
示例14: test_funcs_multi
def test_funcs_multi(self):
pi = math.pi
# sin family
self.assertQuantity(data.sin(Quantity( (0,pi/2), (2,2))), (0,1), (2,0))
self.assertQuantity(data.sinh(Quantity((0,1), (2,2))), (0, math.sinh(1)), (2, math.cosh(1)*2))
self.assertQuantity(data.asin(Quantity((0,0.5), (2,2))), (0,math.asin(0.5)), (2,2/math.sqrt(1-0.5**2)))
self.assertQuantity(data.asinh(Quantity((0,1), (2,2))), (0,math.asinh(1)), (2,2/math.sqrt(1+1**2)))
# cos family
self.assertQuantity(data.cos(Quantity((0,pi/2), (2,2))), (1,0), (0,-2))
self.assertQuantity(data.cosh(Quantity((0,1), (2,2))), (1,math.cosh(1)), (0,math.sinh(1)*2))
self.assertQuantity(data.acos(Quantity((0,0.5), (2,2))), (math.acos(0),math.acos(0.5)), (-2,-2/math.sqrt(1-0.5**2)))
self.assertQuantity(data.acosh(Quantity((2,3), (2,2))), (math.acosh(2), math.acosh(3)), (2/math.sqrt(2**2-1),2/math.sqrt(3**2-1)))
# tan family
self.assertQuantity(data.tan(Quantity((0,1), (2,2))), (0,math.tan(1)), (2,2/math.cos(1)**2))
self.assertQuantity(data.tanh(Quantity((0,1), (2,2))), (0,math.tanh(1)), (2,2/math.cosh(1)**2))
self.assertQuantity(data.atan(Quantity((0,1), (2,2))), (0, math.atan(1)), (2,2/(1+1**2)))
self.assertQuantity(data.atan2(Quantity((0,1), (2,2)), Quantity((1,1), (0,0))), (0,math.atan(1)), (2,2/(1+1**2)))
self.assertQuantity(data.atanh(Quantity((0,0.5), (2,2))), (0,math.atanh(0.5)), (2,2/(1-0.5**2)))
#misc
self.assertQuantity(data.sqrt(Quantity((1,4), (2,2))), (1,2), (1,1/2))
self.assertQuantity(data.exp(Quantity((1,4), (2,2))), (math.e, math.e**4), (2 * math.e,2*math.e**4))
self.assertQuantity(data.log(Quantity((1,4), (2,2))), (0, math.log(4)), (2,1/2))
示例15: g1g2_to_eta1eta2
def g1g2_to_eta1eta2(g1,g2):
gtot=sqrt(g1**2 + g2**2)
if isinstance(gtot,numpy.ndarray):
eta1=numpy.zeros(gtot.size)
eta2=numpy.zeros(gtot.size)
w,=numpy.where(gtot != 0)
if w.size > 0:
cos2theta=g1[w]/gtot[w]
sin2theta=g2[w]/gtot[w]
eta = 2*arctanh(gtot[w])
eta1[w]=eta*cos2theta
eta2[w]=eta*sin2theta
else:
from math import atanh
if gtot == 0:
eta1,eta2=0.0,0.0
else:
cos2theta=g1/gtot
sin2theta=g2/gtot
eta = 2*atanh(gtot)
eta1=eta*cos2theta
eta2=eta*sin2theta
return eta1,eta2