本文整理汇总了Python中math.tanh方法的典型用法代码示例。如果您正苦于以下问题:Python math.tanh方法的具体用法?Python math.tanh怎么用?Python math.tanh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math
的用法示例。
在下文中一共展示了math.tanh方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FollowBallManualPolicy
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def FollowBallManualPolicy():
"""An example of a minitaur following a ball."""
env = minitaur_ball_gym_env.MinitaurBallGymEnv(render=True,
pd_control_enabled=True,
on_rack=False)
observation = env.reset()
sum_reward = 0
steps = 100000
for _ in range(steps):
action = [math.tanh(observation[0] * 4)]
observation, reward, done, _ = env.step(action)
sum_reward += reward
if done:
tf.logging.info("Return is {}".format(sum_reward))
observation = env.reset()
sum_reward = 0
示例2: __init__
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def __init__(self):
self.functions = {}
self.add('sigmoid', sigmoid_activation)
self.add('tanh', tanh_activation)
self.add('sin', sin_activation)
self.add('gauss', gauss_activation)
self.add('relu', relu_activation)
self.add('elu', elu_activation)
self.add('lelu', lelu_activation)
self.add('selu', selu_activation)
self.add('softplus', softplus_activation)
self.add('identity', identity_activation)
self.add('clamped', clamped_activation)
self.add('inv', inv_activation)
self.add('log', log_activation)
self.add('exp', exp_activation)
self.add('abs', abs_activation)
self.add('hat', hat_activation)
self.add('square', square_activation)
self.add('cube', cube_activation)
示例3: test_tanh
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def test_tanh():
from keras.activations import tanh as t
test_values = get_standard_values()
x = T.vector()
exp = t(x)
f = theano.function([x], exp)
result = f(test_values)
expected = [math.tanh(v) for v in test_values]
print(result)
print(expected)
list_assert_equal(result, expected)
示例4: trig
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def trig(a, b=' '):
if is_num(a) and isinstance(b, int):
funcs = [math.sin, math.cos, math.tan,
math.asin, math.acos, math.atan,
math.degrees, math.radians,
math.sinh, math.cosh, math.tanh,
math.asinh, math.acosh, math.atanh]
return funcs[b](a)
if is_lst(a):
width = max(len(row) for row in a)
padded_matrix = [list(row) + (width - len(row)) * [b] for row in a]
transpose = list(zip(*padded_matrix))
if all(isinstance(row, str) for row in a) and isinstance(b, str):
normalizer = ''.join
else:
normalizer = list
norm_trans = [normalizer(padded_row) for padded_row in transpose]
return norm_trans
return unknown_types(trig, ".t", a, b)
示例5: addToMemory
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def addToMemory(reward,averageReward):
prob = 0.1
if( reward > averageReward):
prob = prob + 0.9 * math.tanh(reward - averageReward)
else:
prob = prob + 0.1 * math.tanh(reward - averageReward)
print("average reward", averageReward, " reward ", reward, " prob", prob)
#prob = prob / (rangeH - rangeL)
#prob = reward / (1 + math.fabs(reward))
#prob = (prob+1)/2
if np.random.rand(1)<=prob :
print("Adding reward",reward," based on prob ", prob)
return True
else:
return False
示例6: get
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def get(self):
self.x += self.config.get('dx', 0.1)
val = eval(self.config.get('function', 'sin(x)'), {
'sin': math.sin,
'sinh': math.sinh,
'cos': math.cos,
'cosh': math.cosh,
'tan': math.tan,
'tanh': math.tanh,
'asin': math.asin,
'acos': math.acos,
'atan': math.atan,
'asinh': math.asinh,
'acosh': math.acosh,
'atanh': math.atanh,
'log': math.log,
'abs': abs,
'e': math.e,
'pi': math.pi,
'x': self.x
})
return self.createEvent('ok', 'Sine wave', val)
示例7: thetappp
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def thetappp(self,z_in):
T = self.T_k_in
G = self.G_ksi
J = self.J_in4
l = self.l_in
a = self.a
z = z_in
theta_tripleprime = (-(T*m.cosh(z/a)) + T*m.sinh(z/a)*m.tanh(l/(2*a)))/(G*J*a**2)
return theta_tripleprime
#Case 3 - Concentrated Torque at alpha*l with Pinned Ends
#T = Applied Concentrated Torsional Moment, Kip-in
#G = Shear Modulus of Elasticity, Ksi, 11200 for steel
#J = Torsinal Constant of Cross Section, in^4
#l = Span Lenght, in
#a = Torsional Constant
#alpa = load application point/l
示例8: _get_distorted_indices
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def _get_distorted_indices(self, nb_images):
inverse = random.randint(0, 1)
if inverse:
scale = random.random()
scale *= 0.21
scale += 0.6
else:
scale = random.random()
scale *= 0.6
scale += 0.8
frames_per_clip = nb_images
indices = np.linspace(-scale, scale, frames_per_clip).tolist()
if inverse:
values = [math.atanh(x) for x in indices]
else:
values = [math.tanh(x) for x in indices]
values = [x / values[-1] for x in values]
values = [int(round(((x + 1) / 2) * (frames_per_clip - 1), 0)) for x in values]
return values
示例9: step
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def step(self, action):
obs, rew, done, info = self.env.step(action)
self.raw_episode_return += rew
self.episode_length += info.get('num_frames', 1)
# optimistic asymmetric clipping from IMPALA paper
squeezed = tanh(rew / 5.0)
clipped = 0.3 * squeezed if rew < 0.0 else squeezed
rew = clipped * 5.0
if done:
score = self.raw_episode_return
info['episode_extra_stats'] = dict()
level_name = self.unwrapped.level_name
# add extra 'z_' to the summary key to put them towards the end on tensorboard (just convenience)
level_name_key = f'z_{self.unwrapped.task_id:02d}_{level_name}'
info['episode_extra_stats'][f'{level_name_key}_{RAW_SCORE_SUMMARY_KEY_SUFFIX}'] = score
info['episode_extra_stats'][f'{level_name_key}_len'] = self.episode_length
return obs, rew, done, info
示例10: adjust_learning_rate
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def adjust_learning_rate(optimizer, epoch, config):
lr = get_current_lr(optimizer)
if config.lr_scheduler.type == 'STEP':
if epoch in config.lr_scheduler.lr_epochs:
lr *= config.lr_scheduler.lr_mults
elif config.lr_scheduler.type == 'COSINE':
ratio = epoch / config.epochs
lr = config.lr_scheduler.min_lr + \
(config.lr_scheduler.base_lr - config.lr_scheduler.min_lr) * \
(1.0 + math.cos(math.pi * ratio)) / 2.0
elif config.lr_scheduler.type == 'HTD':
ratio = epoch / config.epochs
lr = config.lr_scheduler.min_lr + \
(config.lr_scheduler.base_lr - config.lr_scheduler.min_lr) * \
(1.0 - math.tanh(
config.lr_scheduler.lower_bound
+ (config.lr_scheduler.upper_bound
- config.lr_scheduler.lower_bound)
* ratio)
) / 2.0
for param_group in optimizer.param_groups:
param_group['lr'] = lr
return lr
示例11: color
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def color(p):
p = math.tanh(3*p)*.5+.5
q = 1.-p*1.3
r = 1.-abs(0.5-p)*1.3+.3*q
p=1.3*p-.3
i = int(p*255)
j = int(q*255)
k = int(r*255)
if j<0:
j=0
if k<0:
k=0
if k >255:
k=255
if i<0:
i = 0
return ('\033[38;2;%d;%d;%dm' % (j, k, i)).encode()
示例12: tanh_activation
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def tanh_activation(z):
z = max(-60.0, min(60.0, 2.5 * z))
return math.tanh(z)
示例13: __call__
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def __call__(self, state, scope, pos, paramTypes, x):
return unwrapForNorm(x, lambda y: math.tanh(y))
示例14: __call__
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def __call__(self, state, scope, pos, paramTypes, x, y, gamma, intercept):
return math.tanh(gamma * dot(x, y, self.errcodeBase + 0, self.name, pos) + intercept)
示例15: genpy
# 需要导入模块: import math [as 别名]
# 或者: from math import tanh [as 别名]
def genpy(self, paramTypes, args, pos):
return "math.tanh({0})".format(*args)