本文整理汇总了Python中tensorflow.python.ops.math_ops.sin函数的典型用法代码示例。如果您正苦于以下问题:Python sin函数的具体用法?Python sin怎么用?Python sin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sin函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: GetMultiEngineGraphDef
def GetMultiEngineGraphDef(dtype=dtypes.float32):
"""Create a graph containing multiple segment."""
g = ops.Graph()
with g.as_default():
inp = array_ops.placeholder(
dtype=dtype, shape=[None] + INPUT_DIMS[1:], name=INPUT_NAME)
with g.device("/GPU:0"):
conv_filter = constant_op.constant(
[[[[1., 0.5, 4., 6., 0.5, 1.], [1., 0.5, 1., 1., 0.5, 1.]]]],
name="weights",
dtype=dtype)
conv = nn.conv2d(
input=inp,
filter=conv_filter,
strides=[1, 2, 2, 1],
padding="SAME",
name="conv")
c1 = constant_op.constant(
np.random.randn(INPUT_DIMS[0], 12, 12, 6), dtype=dtype)
p = conv * c1
c2 = constant_op.constant(
np.random.randn(INPUT_DIMS[0], 12, 12, 6), dtype=dtype)
q = conv / c2
edge = math_ops.sin(q)
edge /= edge
r = edge + edge
p -= edge
q *= edge
s = p + q
s -= r
array_ops.squeeze(s, name=OUTPUT_NAME)
return g.as_graph_def()
开发者ID:Eagle732,项目名称:tensorflow,代码行数:34,代码来源:tf_trt_integration_test.py
示例2: _CosGrad
def _CosGrad(op, grad):
"""Returns grad * -sin(x)."""
x = op.inputs[0]
with ops.control_dependencies([grad.op]):
if x.dtype.is_complex:
x = math_ops.conj(x)
return -grad * math_ops.sin(x)
开发者ID:0ruben,项目名称:tensorflow,代码行数:7,代码来源:math_grad.py
示例3: input_fn
def input_fn():
start = random_ops.random_uniform(
(), minval=0, maxval=(np.pi * 2.0), dtype=dtypes.float32, seed=seed)
sin_curves = math_ops.sin(
math_ops.linspace(start, (sequence_length - 1) * increment,
sequence_length + 1))
inputs = array_ops.slice(sin_curves, [0], [sequence_length])
labels = array_ops.slice(sin_curves, [1], [sequence_length])
return {'inputs': inputs}, labels
开发者ID:finardi,项目名称:tensorflow,代码行数:9,代码来源:state_saving_rnn_estimator_test.py
示例4: angles_to_projective_transforms
def angles_to_projective_transforms(angles,
image_height,
image_width,
name=None):
"""Returns projective transform(s) for the given angle(s).
Args:
angles: A scalar angle to rotate all images by, or (for batches of images)
a vector with an angle to rotate each image in the batch. The rank must
be statically known (the shape is not `TensorShape(None)`.
image_height: Height of the image(s) to be transformed.
image_width: Width of the image(s) to be transformed.
Returns:
A tensor of shape (num_images, 8). Projective transforms which can be given
to `tf.contrib.image.transform`.
"""
with ops.name_scope(name, "angles_to_projective_transforms"):
angle_or_angles = ops.convert_to_tensor(
angles, name="angles", dtype=dtypes.float32)
if len(angle_or_angles.get_shape()) == 0: # pylint: disable=g-explicit-length-test
angles = angle_or_angles[None]
elif len(angle_or_angles.get_shape()) == 1:
angles = angle_or_angles
else:
raise TypeError("Angles should have rank 0 or 1.")
x_offset = ((image_width - 1) - (math_ops.cos(angles) *
(image_width - 1) - math_ops.sin(angles) *
(image_height - 1))) / 2.0
y_offset = ((image_height - 1) - (math_ops.sin(angles) *
(image_width - 1) + math_ops.cos(angles) *
(image_height - 1))) / 2.0
num_angles = array_ops.shape(angles)[0]
return array_ops.concat(
values=[
math_ops.cos(angles)[:, None],
-math_ops.sin(angles)[:, None],
x_offset[:, None],
math_ops.sin(angles)[:, None],
math_ops.cos(angles)[:, None],
y_offset[:, None],
array_ops.zeros((num_angles, 2), dtypes.float32),
],
axis=1)
开发者ID:Eagle732,项目名称:tensorflow,代码行数:44,代码来源:image_ops.py
示例5: Test
def Test(self):
np.random.seed(1)
n = shape_[-1]
batch_shape = shape_[:-2]
np_dtype = dtype_.as_numpy_dtype
a = np.random.uniform(
low=-1.0, high=1.0, size=n * n).reshape([n, n]).astype(np_dtype)
if dtype_.is_complex:
a += 1j * np.random.uniform(
low=-1.0, high=1.0, size=n * n).reshape([n, n]).astype(np_dtype)
a += np.conj(a.T)
a = np.tile(a, batch_shape + (1, 1))
# Optimal stepsize for central difference is O(epsilon^{1/3}).
epsilon = np.finfo(np_dtype).eps
delta = 0.1 * epsilon**(1.0 / 3.0)
# tolerance obtained by looking at actual differences using
# np.linalg.norm(theoretical-numerical, np.inf) on -mavx build
if dtype_ in (dtypes_lib.float32, dtypes_lib.complex64):
tol = 1e-2
else:
tol = 1e-7
with self.session(use_gpu=True):
tf_a = constant_op.constant(a)
if compute_v_:
tf_e, tf_v = linalg_ops.self_adjoint_eig(tf_a)
# (complex) Eigenvectors are only unique up to an arbitrary phase
# We normalize the vectors such that the first component has phase 0.
top_rows = tf_v[..., 0:1, :]
if tf_a.dtype.is_complex:
angle = -math_ops.angle(top_rows)
phase = math_ops.complex(math_ops.cos(angle), math_ops.sin(angle))
else:
phase = math_ops.sign(top_rows)
tf_v *= phase
outputs = [tf_e, tf_v]
else:
tf_e = linalg_ops.self_adjoint_eigvals(tf_a)
outputs = [tf_e]
for b in outputs:
x_init = np.random.uniform(
low=-1.0, high=1.0, size=n * n).reshape([n, n]).astype(np_dtype)
if dtype_.is_complex:
x_init += 1j * np.random.uniform(
low=-1.0, high=1.0, size=n * n).reshape([n, n]).astype(np_dtype)
x_init += np.conj(x_init.T)
x_init = np.tile(x_init, batch_shape + (1, 1))
theoretical, numerical = gradient_checker.compute_gradient(
tf_a,
tf_a.get_shape().as_list(),
b,
b.get_shape().as_list(),
x_init_value=x_init,
delta=delta)
self.assertAllClose(theoretical, numerical, atol=tol, rtol=tol)
开发者ID:bunbutter,项目名称:tensorflow,代码行数:54,代码来源:self_adjoint_eig_op_test.py
示例6: Compute
def Compute(x):
e, v = linalg_ops.self_adjoint_eig(x)
# (complex) Eigenvectors are only unique up to an arbitrary phase
# We normalize the vectors such that the first component has phase 0.
top_rows = v[..., 0:1, :]
if dtype_.is_complex:
angle = -math_ops.angle(top_rows)
phase = math_ops.complex(math_ops.cos(angle), math_ops.sin(angle))
else:
phase = math_ops.sign(top_rows)
v *= phase
return e, v
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:12,代码来源:self_adjoint_eig_op_test.py
示例7: input_fn
def input_fn():
start = random_ops.random_uniform(
(), minval=0, maxval=(np.pi * 2.0), dtype=dtypes.float32, seed=seed)
sin_curves = math_ops.sin(
math_ops.linspace(start, (sequence_length - 1) * increment,
sequence_length + 1))
inputs = array_ops.slice(sin_curves, [0], [sequence_length])
labels = array_ops.slice(sin_curves, [1], [sequence_length])
input_key = string_ops.string_join([
'key_',
string_ops.as_string(math_ops.cast(10000 * start, dtypes.int32))
])
return {'inputs': inputs, input_key_column_name: input_key}, labels
开发者ID:Jackhuang945,项目名称:tensorflow,代码行数:13,代码来源:state_saving_rnn_estimator_test.py
示例8: _add_sinusoids_signal
def _add_sinusoids_signal(x, time, min_timescale=1.0, max_timescale=1.0e4):
"""Adds a bunch of sinusoids of different frequencies to a Tensor.
Each channel of the input Tensor is incremented by a sinusoid of a different
frequency and phase.
This allows attention to learn to use absolute and relative positions.
Timing signals should be added to some precursors of both the query and the
memory inputs to attention.
The use of relative position is possible because sin(x+y) and cos(x+y) can be
experessed in terms of y, sin(x) and cos(x).
In particular, we use a geometric sequence of timescales starting with
min_timescale and ending with max_timescale. The number of different
timescales is equal to channels / 2. For each timescale, we
generate the two sinusoidal signals sin(timestep/timescale) and
cos(timestep/timescale). All of these sinusoids are concatenated in
the channels dimension.
Args:
x: a Tensor with shape [batch, length, channels]
min_timescale: a float
max_timescale: a float
Returns:
a Tensor the same shape as x.
"""
channels = x.get_shape().as_list()[-1]
if x.get_shape().ndims == 3: # [batch_size, timesteps, dim]
length = array_ops.shape(x)[1]
position = math_ops.to_float(math_ops.range(length))
elif x.get_shape().ndims == 2: # [batch_size, dim]
length = 1
position = math_ops.to_float(math_ops.range(time, time + 1))
else:
raise ValueError("need a Tensor with rank 2 or 3")
num_timescales = channels // 2
log_timescale_increment = (
math.log(float(max_timescale) / float(min_timescale)) /
(math_ops.to_float(num_timescales) - 1))
inv_timescales = min_timescale * math_ops.exp(
math_ops.to_float(math_ops.range(num_timescales)) * -log_timescale_increment)
scaled_time = array_ops.expand_dims(position, 1) * array_ops.expand_dims(inv_timescales, 0)
signal = array_ops.concat([math_ops.sin(scaled_time), math_ops.cos(scaled_time)], axis=1)
signal = array_ops.pad(signal, [[0, 0], [0, math_ops.mod(channels, 2)]])
if x.get_shape().ndims == 3:
signal = array_ops.reshape(signal, [1, length, channels])
else:
signal = array_ops.reshape(signal, [1, channels])
return x + signal
开发者ID:KIngpon,项目名称:NJUNMT-tf,代码行数:51,代码来源:embedding.py
示例9: test_stft_round_trip
def test_stft_round_trip(self):
# Tuples of (signal_length, frame_length, frame_step, fft_length).
test_configs = [
# 87.5% overlap.
(4096, 256, 32, 256),
# 75% overlap.
(4096, 256, 64, 256),
# Odd frame hop.
(4096, 128, 25, 128),
# Odd frame length.
(4096, 127, 32, 128),
]
for signal_length, frame_length, frame_step, fft_length in test_configs:
# Generate a 440Hz signal at 8kHz sample rate.
signal = math_ops.sin(2 * np.pi * 440 / 8000 *
math_ops.to_float(math_ops.range(signal_length)))
self._compare_round_trip(signal, frame_length, frame_step, fft_length)
开发者ID:1000sprites,项目名称:tensorflow,代码行数:18,代码来源:spectral_ops_test.py
示例10: _NormalizingSvd
def _NormalizingSvd(tf_a):
tf_s, tf_u, tf_v = linalg_ops.svd(tf_a, compute_uv=True, full_matrices=True)
# Singular vectors are only unique up to an arbitrary phase. We normalize
# the vectors such that the first component of u (if m >=n) or v (if n > m)
# have phase 0.
m = tf_a.shape[-2]
n = tf_a.shape[-1]
if m >= n:
top_rows = tf_u[..., 0:1, :]
else:
top_rows = tf_v[..., 0:1, :]
if tf_u.dtype.is_complex:
angle = -math_ops.angle(top_rows)
phase = math_ops.complex(math_ops.cos(angle), math_ops.sin(angle))
else:
phase = math_ops.sign(top_rows)
tf_u *= phase[..., :m]
tf_v *= phase[..., :n]
return tf_s, tf_u, tf_v
开发者ID:AbhinavJain13,项目名称:tensorflow,代码行数:19,代码来源:svd_op_test.py
示例11: test_gradients
def test_gradients(self):
"""Test that spectral_ops.stft has a working gradient."""
with spectral_ops_test_util.fft_kernel_label_map(), (
self.test_session(use_gpu=True)) as sess:
signal_length = 512
# An all-zero signal has all zero gradients with respect to the sum of the
# magnitude STFT.
empty_signal = array_ops.zeros([signal_length], dtype=dtypes.float32)
empty_signal_gradient = sess.run(
self._compute_stft_gradient(empty_signal))
self.assertTrue((empty_signal_gradient == 0.0).all())
# A sinusoid will have non-zero components of its gradient with respect to
# the sum of the magnitude STFT.
sinusoid = math_ops.sin(
2 * np.pi * math_ops.linspace(0.0, 1.0, signal_length))
sinusoid_gradient = sess.run(self._compute_stft_gradient(sinusoid))
self.assertFalse((sinusoid_gradient == 0.0).all())
开发者ID:1000sprites,项目名称:tensorflow,代码行数:19,代码来源:spectral_ops_test.py
示例12: get_multi_engine_graph_def
def get_multi_engine_graph_def(mode="FP32"):
"""Create a simple graph and return its graph_def."""
dtype = dtypes.float32
if mode.upper() == "FP16":
dtype = dtypes.float16
else:
pass
g = ops.Graph()
with g.as_default():
x = aops.placeholder(shape=[None, 3, 7, 5], name="input", dtype=dtype)
with g.name_scope("Global_scope"):
with g.name_scope("first_scope"):
e = cop.constant(
np.random.randn(3, 2, 3, 4), name="weights", dtype=dtype)
conv = nn.conv2d(
input=x,
filter=e,
data_format="NCHW",
strides=[1, 1, 1, 1],
padding="VALID",
name="conv")
b = cop.constant(np.random.randn(1, 4, 1, 1), name="bias1", dtype=dtype)
t = conv * b
b = cop.constant(np.random.randn(1, 4, 1, 1), name="bias2", dtype=dtype)
q = conv / b
edge = mops.sin(q)
edge1 = mops.cos(conv)
with g.name_scope("test_scope"):
de = edge + edge1
t -= edge1
q *= edge
t += q
t -= de
k = aops.squeeze(t, name="output")
print(k.dtype)
return g.as_graph_def()
开发者ID:Eagle732,项目名称:tensorflow,代码行数:38,代码来源:test_tftrt.py
示例13: _sin_fn
def _sin_fn(x):
ranger = math_ops.linspace(
array_ops.reshape(x[0], []), (sequence_length - 1) * increment,
sequence_length + 1)
return math_ops.sin(ranger)
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:5,代码来源:dynamic_rnn_estimator_test.py
示例14: _CosGrad
def _CosGrad(op, grad):
"""Returns grad * -sin(x)."""
x = op.inputs[0]
return -grad * math_ops.sin(x)
开发者ID:ray2020,项目名称:tensorflow,代码行数:4,代码来源:math_grad.py
示例15: tf_function
def tf_function(self, x):
"""Takes tf tensor, evaluates the test function, and returns tf tensor."""
return math_ops.reduce_sum(
math_ops.square(x - 0.5) + 0.25 * x + 1 * math_ops.sin(x * 15),
2,
keepdims=True)
开发者ID:Ajaycs99,项目名称:tensorflow,代码行数:6,代码来源:interpolate_spline_test.py
示例16: transition_to_powers
def transition_to_powers(self, powers):
"""Computes TransitionMatrix^power efficiently.
For an n x n transition matrix we have:
(TransitionMatrix**power)_{i, j) = (-1) ** i * sin(pi * power) / (n + 1)
* ((-1) ** j / sin(pi / (n + 1) * (power - i + j))
+ 1 / sin(pi / (n + 1) * (power - i - 1)))
The sin(pi * power) term is zero whenever "power" is an integer. However,
the 1 / sin(x) terms (cosecants) occasionally (when their arguments are
multiples of pi) cancel out this value. The limit as the argument approaches
an integer value gives the "correct" result, but computing these separately
gives 0 * inf = NaN. Instead, there is a special case for near-integer
values.
Args:
powers: A floating point Tensor of powers to raise the transition matrix
to.
Returns:
A [..., self._num_latent_values - 1, self._num_latent_values - 1] floating
point Tensor with the transition matrix raised to each power in
`powers`.
"""
num_latent_values_float = math_ops.cast(self._num_latent_values, self.dtype)
latent_values_per_period = (num_latent_values_float / math_ops.cast(
self._true_periodicity, dtype=self.dtype))
original_matrix_powers = (math_ops.cast(powers, self.dtype) *
latent_values_per_period)
global_coeff = (math_ops.sin(original_matrix_powers * numpy.pi) /
num_latent_values_float)[..., None, None]
matrix_dimension_range = array_ops.reshape(
math_ops.range(self._num_latent_values - 1),
array_ops.concat(
[
array_ops.ones(
[array_ops.rank(original_matrix_powers)],
dtype=dtypes.int32), [self._num_latent_values - 1]
],
axis=0))
matrix_dimension_range_float = math_ops.cast(matrix_dimension_range,
self.dtype)
alternating = math_ops.cast(1 - 2 * (matrix_dimension_range % 2),
self.dtype)
row_addend = 1. / math_ops.sin(numpy.pi / num_latent_values_float * (
original_matrix_powers[..., None] - matrix_dimension_range_float - 1))
column_minus_row = (matrix_dimension_range_float[..., None, :]
- matrix_dimension_range_float[..., None])
full_matrix_addend = (alternating[..., None, :] / math_ops.sin(
numpy.pi / num_latent_values_float *
(original_matrix_powers[..., None, None] + column_minus_row)))
continuous_construction = global_coeff * alternating[..., None] * (
row_addend[..., None] + full_matrix_addend)
# For integer powers, the above formula is only correct in the limit,
# yielding NaNs as written. We defer to the super-class in such cases, which
# computes integer powers exactly.
return array_ops.where(
self._close_to_integer(original_matrix_powers),
super(ResolutionCycleModel, self).transition_to_powers(
math_ops.cast(
gen_math_ops.round(original_matrix_powers), dtypes.int64)),
continuous_construction)
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:63,代码来源:periodic.py
示例17: rotate
def rotate(images, angles):
"""Rotate image(s) by the passed angle(s) in radians.
Args:
images: A tensor of shape (num_images, num_rows, num_columns, num_channels)
(NHWC), (num_rows, num_columns, num_channels) (HWC), or
(num_rows, num_columns) (HW).
angles: A scalar angle to rotate all images by, or (if images has rank 4)
a vector of length num_images, with an angle for each image in the batch.
Returns:
Image(s) with the same type and shape as `images`, rotated by the given
angle(s). Empty space due to the rotation will be filled with zeros.
Raises:
TypeError: If `image` is an invalid type.
"""
image_or_images = ops.convert_to_tensor(images, name="images")
angle_or_angles = ops.convert_to_tensor(
angles, name="angles", dtype=dtypes.float32)
if image_or_images.dtype.base_dtype not in _IMAGE_DTYPES:
raise TypeError("Invalid dtype %s." % image_or_images.dtype)
if len(image_or_images.get_shape()) == 2:
images = image_or_images[None, :, :, None]
elif len(image_or_images.get_shape()) == 3:
images = image_or_images[None, :, :, :]
elif len(image_or_images.get_shape()) == 4:
images = image_or_images
else:
raise TypeError("Images should have rank between 2 and 4.")
if len(angle_or_angles.get_shape()) == 0: # pylint: disable=g-explicit-length-test
angles = angle_or_angles[None]
elif len(angle_or_angles.get_shape()) == 1:
angles = angle_or_angles
else:
raise TypeError("Angles should have rank 0 or 1.")
image_width = math_ops.cast(array_ops.shape(images)[2], dtypes.float32)[None]
image_height = math_ops.cast(array_ops.shape(images)[1], dtypes.float32)[None]
x_offset = ((image_width - 1) - (math_ops.cos(angles) *
(image_width - 1) - math_ops.sin(angles) *
(image_height - 1))) / 2.0
y_offset = ((image_height - 1) - (math_ops.sin(angles) *
(image_width - 1) + math_ops.cos(angles) *
(image_height - 1))) / 2.0
num_angles = array_ops.shape(angles)[0]
transforms = array_ops.concat(
concat_dim=1,
values=[
math_ops.cos(angles)[:, None],
-math_ops.sin(angles)[:, None],
x_offset[:, None],
math_ops.sin(angles)[:, None],
math_ops.cos(angles)[:, None],
y_offset[:, None],
array_ops.zeros((num_angles, 2), dtypes.float32),
])
# pylint: disable=protected-access
output = transform(images, transforms)
if len(image_or_images.get_shape()) == 2:
return output[0, :, :, 0]
elif len(image_or_images.get_shape()) == 3:
return output[0, :, :, :]
else:
return output
开发者ID:curtiszimmerman,项目名称:tensorflow,代码行数:65,代码来源:image_ops.py
示例18: _cosecant_with_freq
def _cosecant_with_freq(coefficient):
return 1. / math_ops.sin(numpy.pi / num_latent_values_float * coefficient)
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:2,代码来源:periodic.py
示例19: _power_sum_array
def _power_sum_array(self, max_remaining_steps):
r"""Computes \sum_{i=0}^{N-1} A^i B (A^i)^T for N=0..max_remaining_steps.
A is the transition matrix and B is the noise covariance.
This is more efficient in practice than math_utils.power_sums_tensor, since
each A^i B (A^i)^T term has a closed-form expression not depending on i - 1.
Thus vectorization can replace explicit looping.
Uses a cumulative sum on the following expression:
(transition^p * transition_covariance * (transition^p)^T)_{i, j}
= (-1)^(i + j) * sin^2(pi * p) / num_latent_values^2
* (1/sin(pi / num_latent_values * (p - i))
+ 1/sin(pi / num_latent_values * (p - i - 1)))
* (1/sin(pi / num_latent_values * (p - j))
+ 1/sin(pi / num_latent_values * (p - j - 1)))
The expression being derived from the eigenvectors and eigenvalues given in
the class docstring (and as with CycleStateSpaceModel taking advantage of
the sparsity of the transition covariance).
Args:
max_remaining_steps: A scalar integer Tensor indicating the number of
non-trivial values to compute.
Returns:
A [max_remaining_steps + 1, self._num_latent_values - 1,
self._num_latent_values - 1] floating point Tensor S with cumulative power
sums.
S[N] = \sum_{i=0}^{N-1} A^i B (A^i)^T
S[0] is the zero matrix
S[1] is B
S[2] is A B A^T + B
"""
num_latent_values_float = math_ops.cast(self._num_latent_values, self.dtype)
latent_values_per_period = (num_latent_values_float / math_ops.cast(
self._true_periodicity, dtype=self.dtype))
original_matrix_powers = (math_ops.cast(
math_ops.range(max_remaining_steps),
self.dtype) * latent_values_per_period)
matrix_dimension_range = math_ops.range(
self._num_latent_values - 1)[None, ...]
matrix_dimension_range_float = math_ops.cast(matrix_dimension_range,
self.dtype)
def _cosecant_with_freq(coefficient):
return 1. / math_ops.sin(numpy.pi / num_latent_values_float * coefficient)
power_minus_index = (original_matrix_powers[..., None]
- matrix_dimension_range_float)
mesh_values = (_cosecant_with_freq(power_minus_index)
+ _cosecant_with_freq(power_minus_index - 1.))
meshed = mesh_values[..., None, :] * mesh_values[..., None]
full_matrix_alternating = math_ops.cast(1 - 2 * (
(matrix_dimension_range[..., None, :] +
matrix_dimension_range[..., None]) % 2), self.dtype)
def _sine_discontinuity(value):
"""A special case for dealing with discontinuities.
Decides whether `value` is close to an integer, and if so computes:
lim x->n |sin(x * pi)| / sin(x * pi) = sign(sin(n * pi))
= cos(n * pi)
Args:
value: The floating point Tensor value which may lead to a
discontinuity.
Returns:
A tuple of (is_discontinuous, sign):
is_discontinuous: A boolean Tensor of the same shape as `value`,
indicating whether it is near an integer.
sign: A floating point Tensor indicating the sign of the discontinuity
(being near 1 or -1 when `is_discontinuous` is True), of the same
shape and type as `value`.
"""
normalized = value / num_latent_values_float
is_discontinuous = self._close_to_integer(normalized)
sign = math_ops.cos(normalized * numpy.pi)
return is_discontinuous, sign
index_discontinuous, index_sign = _sine_discontinuity(
original_matrix_powers[..., None]
- matrix_dimension_range_float)
index_minus_discontinuous, index_minus_sign = _sine_discontinuity(
original_matrix_powers[..., None]
- matrix_dimension_range_float
- 1)
ones_mask_vector = math_ops.logical_or(index_discontinuous,
index_minus_discontinuous)
ones_sign_vector = array_ops.where(index_discontinuous, index_sign,
index_minus_sign)
ones_mask = math_ops.logical_and(ones_mask_vector[..., None],
ones_mask_vector[..., None, :])
zeros_mask = self._close_to_integer(original_matrix_powers)
zeroed = array_ops.where(zeros_mask, array_ops.zeros_like(meshed), meshed)
global_coefficient = (math_ops.sin(numpy.pi * original_matrix_powers) /
num_latent_values_float)
masked_meshed = array_ops.where(
ones_mask, ones_sign_vector[..., None] * ones_sign_vector[..., None, :],
zeroed * global_coefficient[..., None, None]**2)
powers_above_zero = full_matrix_alternating * masked_meshed
#.........这里部分代码省略.........
开发者ID:AutumnQYN,项目名称:tensorflow,代码行数:101,代码来源:periodic.py
示例20: _CosGrad
def _CosGrad(op, grad):
"""Returns grad * -sin(x)."""
x = op.inputs[0]
with ops.control_dependencies([grad]):
x = math_ops.conj(x)
return -grad * math_ops.sin(x)
开发者ID:neuroradiology,项目名称:tensorflow,代码行数:6,代码来源:math_grad.py
注:本文中的tensorflow.python.ops.math_ops.sin函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论