本文整理汇总了Python中tensorflow.cos方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.cos方法的具体用法?Python tensorflow.cos怎么用?Python tensorflow.cos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.cos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_timing_signal
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def get_timing_signal(length,
min_timescale=1,
max_timescale=1e4,
num_timescales=16):
"""Create Tensor of sinusoids of different frequencies.
Args:
length: Length of the Tensor to create, i.e. Number of steps.
min_timescale: a float
max_timescale: a float
num_timescales: an int
Returns:
Tensor of shape (length, 2*num_timescales)
"""
positions = tf.to_float(tf.range(length))
log_timescale_increment = (
math.log(max_timescale / min_timescale) / (num_timescales - 1))
inv_timescales = min_timescale * tf.exp(
tf.to_float(tf.range(num_timescales)) * -log_timescale_increment)
scaled_time = tf.expand_dims(positions, 1) * tf.expand_dims(inv_timescales, 0)
return tf.concat([tf.sin(scaled_time), tf.cos(scaled_time)], axis=1)
示例2: rotate_point_cloud_by_angle_y
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def rotate_point_cloud_by_angle_y(batch_data, rotation_angle):
""" Rotate the point cloud along up direction with certain angle.
Input:
BxNx3 array, original batch of point clouds
Return:
BxNx3 array, rotated batch of point clouds
"""
rotated_data = np.zeros(batch_data.shape, dtype=np.float32)
for k in range(batch_data.shape[0]):
#rotation_angle = np.random.uniform() * 2 * np.pi
cosval = np.cos(rotation_angle)
sinval = np.sin(rotation_angle)
rotation_matrix = np.array([[cosval, 0, sinval],
[0, 1, 0],
[-sinval, 0, cosval]])
shape_pc = batch_data[k, ...]
# rotated_data[k, ...] = np.dot(shape_pc.reshape((-1, 3)), rotation_matrix)
rotated_data[k, ...] = np.dot(rotation_matrix, shape_pc.reshape((-1, 3)).T).T # Pre-Multiplication (changes done)
return rotated_data
示例3: rotate_point_cloud_by_angle_x
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def rotate_point_cloud_by_angle_x(batch_data, rotation_angle):
""" Rotate the point cloud along up direction with certain angle.
Input:
BxNx3 array, original batch of point clouds
Return:
BxNx3 array, rotated batch of point clouds
"""
rotated_data = np.zeros(batch_data.shape, dtype=np.float32)
for k in range(batch_data.shape[0]):
#rotation_angle = np.random.uniform() * 2 * np.pi
cosval = np.cos(rotation_angle)
sinval = np.sin(rotation_angle)
rotation_matrix = np.array([[1, 0, 0],
[0, cosval, -sinval],
[0, sinval, cosval]])
shape_pc = batch_data[k, ...]
# rotated_data[k, ...] = np.dot(shape_pc.reshape((-1, 3)), rotation_matrix)
rotated_data[k, ...] = np.dot(rotation_matrix, shape_pc.reshape((-1, 3)).T).T # Pre-Multiplication (changes done)
return rotated_data
示例4: rotate_point_cloud_by_angle_z
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def rotate_point_cloud_by_angle_z(batch_data, rotation_angle):
""" Rotate the point cloud along up direction with certain angle.
Input:
BxNx3 array, original batch of point clouds
Return:
BxNx3 array, rotated batch of point clouds
"""
rotated_data = np.zeros(batch_data.shape, dtype=np.float32)
for k in range(batch_data.shape[0]):
#rotation_angle = np.random.uniform() * 2 * np.pi
cosval = np.cos(rotation_angle)
sinval = np.sin(rotation_angle)
rotation_matrix = np.array([[cosval, -sinval, 0],
[sinval, cosval, 0],
[0, 0, 1]])
shape_pc = batch_data[k, ...]
# rotated_data[k, ...] = np.dot(shape_pc.reshape((-1, 3)), rotation_matrix)
rotated_data[k, ...] = np.dot(rotation_matrix, shape_pc.reshape((-1, 3)).T).T # Pre-Multiplication (changes done)
return rotated_data
# Translate the data as per given translation vector.
示例5: locationPE
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def locationPE(h, w, dim, outDim = -1, addBias = True):
x = tf.expand_dims(tf.to_float(tf.linspace(-config.locationBias, config.locationBias, w)), axis = -1)
y = tf.expand_dims(tf.to_float(tf.linspace(-config.locationBias, config.locationBias, h)), axis = -1)
i = tf.expand_dims(tf.to_float(tf.range(dim)), axis = 0)
peSinX = tf.sin(x / (tf.pow(10000.0, i / dim)))
peCosX = tf.cos(x / (tf.pow(10000.0, i / dim)))
peSinY = tf.sin(y / (tf.pow(10000.0, i / dim)))
peCosY = tf.cos(y / (tf.pow(10000.0, i / dim)))
peSinX = tf.tile(tf.expand_dims(peSinX, axis = 0), [h, 1, 1])
peCosX = tf.tile(tf.expand_dims(peCosX, axis = 0), [h, 1, 1])
peSinY = tf.tile(tf.expand_dims(peSinY, axis = 1), [1, w, 1])
peCosY = tf.tile(tf.expand_dims(peCosY, axis = 1), [1, w, 1])
grid = tf.concat([peSinX, peCosX, peSinY, peCosY], axis = -1)
dim *= 4
if outDim > 0:
grid = linear(grid, dim, outDim, addBias = addBias, name = "locationPE")
dim = outDim
return grid, dim
示例6: __init__
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def __init__(self, position_size, hparams=None):
EmbedderBase.__init__(self, hparams=hparams)
dim = self._hparams.dim
num_timescales = dim // 2
min_timescale = self._hparams.min_timescale
max_timescale = self._hparams.max_timescale
positions = tf.to_float(tf.range(position_size, dtype=tf.int32))
log_timescale_increment = (
math.log(float(max_timescale) / float(min_timescale)) /
(tf.to_float(num_timescales) - 1))
inv_timescales = min_timescale * tf.exp(
tf.to_float(tf.range(num_timescales)) * -log_timescale_increment)
scaled_time = tf.expand_dims(positions, 1) \
* tf.expand_dims(inv_timescales, 0)
signal = tf.concat([tf.sin(scaled_time), tf.cos(scaled_time)], axis=1)
signal = tf.pad(signal, [[0, 0], [0, tf.mod(dim, 2)]])
self.signal = signal
示例7: radial_cutoff
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def radial_cutoff(self, R, rc):
"""Calculates radial cutoff matrix.
B = batch_size, N = max_num_atoms, M = max_num_neighbors
Parameters
----------
R [B, N, M]: tf.Tensor
Distance matrix.
rc: tf.Variable
Interaction cutoff [Angstrom].
Returns
-------
FC [B, N, M]: tf.Tensor
Radial cutoff matrix.
"""
T = 0.5 * (tf.cos(np.pi * R / (rc)) + 1)
E = tf.zeros_like(T)
cond = tf.less_equal(R, rc)
FC = tf.where(cond, T, E)
return FC
示例8: test_ODEbadprecision
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def test_ODEbadprecision(self): # make sure float32 is not enough for very precise integration
t = tf.constant(np.linspace(0, 10, 1000), dtype=tf.float32)
# initial condition
true_y0 = tf.constant([0., 5.], dtype=tf.float32)
true_func = lambda y, t: np.sin(5*t)
ode_func = lambda y, t: tf.cast(tf.stack([5*tf.cos(5*t), -25*tf.sin(5*t)]), tf.float32)
true_y = odeint(ode_func, true_y0, t, method='dop853', precision=tf.float32)
self.assertRaises(AssertionError, npt.assert_array_almost_equal, true_y.numpy()[:, 0], true_func(true_y0, t))
true_y0_pretend_multidims = [[0., 5.]] # to introduce a mix of list, np array, tensor to make sure no issue
true_y_pretend_multidims = odeint(ode_func, true_y0_pretend_multidims, t, method='dop853', precision=tf.float32)
# assert equal pretendinging multidim or not
np.testing.assert_array_almost_equal(true_y_pretend_multidims[0], true_y)
true_y0_multidims = tf.constant([[1., 2.], [0., 5.]], dtype=tf.float32)
t = np.linspace(0, 10, 1000)
true_y_multidims = odeint(ode_func, true_y0_multidims, t, method='dop853', precision=tf.float32)
# assert equal in multidim or not
np.testing.assert_array_almost_equal(true_y_multidims[1], true_y)
示例9: gaussian
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def gaussian(config, gan, net):
z_dim = net.get_shape().as_list()[-1]
net = (net + 1) / 2
if len(gan.ops.shape(net)) == 4:
za = tf.slice(net, [0,0,0,0], [gan.batch_size(), -1, -1, z_dim//2])
zb = tf.slice(net, [0,0,0,z_dim//2], [gan.batch_size(), -1, -1, z_dim//2])
else:
za = tf.slice(net, [0,0], [gan.batch_size(), z_dim//2])
zb = tf.slice(net, [0,z_dim//2], [gan.batch_size(), z_dim//2])
pi = np.pi
ra = tf.sqrt(-2 * tf.log(za+TINY))*tf.cos(2*pi*zb)
rb = tf.sqrt(-2 * tf.log(za+TINY))*tf.sin(2*pi*zb)
return tf.reshape(tf.concat(axis=len(net.get_shape())-1, values=[ra, rb]), net.get_shape())
示例10: _configure_learning_rate
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def _configure_learning_rate(train_config, global_step):
lr_config = train_config['lr_config']
num_batches_per_epoch = \
int(train_config['train_data_config']['num_examples_per_epoch'] / train_config['train_data_config']['batch_size'])
lr_policy = lr_config['policy']
if lr_policy == 'piecewise_constant':
lr_boundaries = [int(e * num_batches_per_epoch) for e in lr_config['lr_boundaries']]
return tf.train.piecewise_constant(global_step,
lr_boundaries,
lr_config['lr_values'])
elif lr_policy == 'exponential':
decay_steps = int(num_batches_per_epoch) * lr_config['num_epochs_per_decay']
return tf.train.exponential_decay(lr_config['initial_lr'],
global_step,
decay_steps=decay_steps,
decay_rate=lr_config['lr_decay_factor'],
staircase=lr_config['staircase'])
elif lr_policy == 'cosine':
T_total = train_config['train_data_config']['epoch'] * num_batches_per_epoch
return 0.5 * lr_config['initial_lr'] * (1 + tf.cos(np.pi * tf.to_float(global_step) / T_total))
else:
raise ValueError('Learning rate policy [%s] was not recognized', lr_policy)
示例11: batch_rodrigues
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def batch_rodrigues(theta, name=None):
"""
Theta is N x 3
"""
with tf.variable_scope(name, "batch_rodrigues", [theta]):
batch_size = tf.shape(theta)[0]
angle = tf.expand_dims(tf.norm(theta + 1e-8, axis=1), -1)
r = tf.expand_dims(tf.div(theta, angle), -1)
angle = tf.expand_dims(angle, -1)
cos = tf.cos(angle)
sin = tf.sin(angle)
outer = tf.matmul(r, r, transpose_b=True, name="outer")
eyes = tf.tile(tf.expand_dims(tf.eye(3), 0), [batch_size, 1, 1])
R = cos * eyes + (1 - cos) * outer + sin * batch_skew(
r, batch_size=batch_size)
return R
示例12: radial_cutoff
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def radial_cutoff(self, R, rc):
"""Calculates radial cutoff matrix.
B = batch_size, N = max_num_atoms, M = max_num_neighbors
Parameters
----------
R [B, N, M]: tf.Tensor
Distance matrix.
rc: tf.Variable
Interaction cutoff [Angstrom].
Returns
-------
FC [B, N, M]: tf.Tensor
Radial cutoff matrix.
"""
T = 0.5 * (tf.cos(np.pi * R / (rc)) + 1)
E = tf.zeros_like(T)
cond = tf.less_equal(R, rc)
FC = tf.where(cond, T, E)
return FC
示例13: add_timing_signal
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def add_timing_signal(x, scope='', min_timescale=1.0, max_timescale=1.0e4):
with tf.name_scope(scope, values=[x]):
length = tf.shape(x)[1]
channels = tf.shape(x)[2]
position = tf.to_float(tf.range(length))
num_timescales = channels // 2
log_timescale_increment = (
math.log(float(max_timescale) / float(min_timescale)) /
(tf.to_float(num_timescales) - 1)
)
inv_timescales = min_timescale * tf.exp(
tf.to_float(tf.range(num_timescales)) * -log_timescale_increment
)
scaled_time = (tf.expand_dims(position, 1) *
tf.expand_dims(inv_timescales, 0))
signal = tf.concat([tf.sin(scaled_time), tf.cos(scaled_time)], axis=1)
signal = tf.pad(signal, [[0, 0], [0, tf.mod(channels, 2)]])
signal = tf.reshape(signal, [1, length, channels])
return x + signal
示例14: get_timing_signal
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def get_timing_signal(length,
min_timescale=1,
max_timescale=1e4,
num_timescales=16):
"""Create Tensor of sinusoids of different frequencies.
Args:
length: Length of the Tensor to create, i.e. Number of steps.
min_timescale: a float
max_timescale: a float
num_timescales: an int
Returns:
Tensor of shape (length, 2*num_timescales)
"""
positions = to_float(tf.range(length))
log_timescale_increment = (
math.log(max_timescale / min_timescale) / (num_timescales - 1))
inv_timescales = min_timescale * tf.exp(
to_float(tf.range(num_timescales)) * -log_timescale_increment)
scaled_time = tf.expand_dims(positions, 1) * tf.expand_dims(inv_timescales, 0)
return tf.concat([tf.sin(scaled_time), tf.cos(scaled_time)], axis=1)
示例15: _position_encoding
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import cos [as 别名]
def _position_encoding(position_size, dim,
min_timescale=1.0,
max_timescale=1.0e4):
position = tf.to_float(tf.range(position_size))
num_timescales = dim // 2
log_timescale_increment = (
math.log(float(max_timescale) / float(min_timescale)) /
(tf.to_float(num_timescales) - 1))
inv_timescales = min_timescale * tf.exp(
tf.to_float(tf.range(num_timescales)) * -log_timescale_increment)
scaled_time = tf.expand_dims(position, 1) \
* tf.expand_dims(inv_timescales, 0)
signal = tf.concat([tf.sin(scaled_time), tf.cos(scaled_time)], axis=1)
signal = tf.pad(signal, [[0, 0], [0, tf.mod(dim, 2)]])
signal = tf.reshape(signal, [1, position_size, dim])
return signal