本文整理匯總了Python中tensorflow.python.ops.gen_math_ops.exp方法的典型用法代碼示例。如果您正苦於以下問題:Python gen_math_ops.exp方法的具體用法?Python gen_math_ops.exp怎麽用?Python gen_math_ops.exp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensorflow.python.ops.gen_math_ops
的用法示例。
在下文中一共展示了gen_math_ops.exp方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: sigmoid
# 需要導入模塊: from tensorflow.python.ops import gen_math_ops [as 別名]
# 或者: from tensorflow.python.ops.gen_math_ops import exp [as 別名]
def sigmoid(x, name=None):
"""Computes sigmoid of `x` element-wise.
Specifically, `y = 1 / (1 + exp(-x))`.
Args:
x: A Tensor with type `float32`, `float64`, `int32`, `complex64`, `int64`,
or `qint32`.
name: A name for the operation (optional).
Returns:
A Tensor with the same type as `x` if `x.dtype != qint32`
otherwise the return type is `quint8`.
@compatibility(numpy)
Equivalent to np.scipy.special.expit
@end_compatibility
"""
with ops.name_scope(name, "Sigmoid", [x]) as name:
x = ops.convert_to_tensor(x, name="x")
return gen_math_ops._sigmoid(x, name=name)
示例2: log_sigmoid
# 需要導入模塊: from tensorflow.python.ops import gen_math_ops [as 別名]
# 或者: from tensorflow.python.ops.gen_math_ops import exp [as 別名]
def log_sigmoid(x, name=None):
"""Computes log sigmoid of `x` element-wise.
Specifically, `y = log(1 / (1 + exp(-x)))`. For numerical stability,
we use `y = -tf.nn.softplus(-x)`.
Args:
x: A Tensor with type `float32` or `float64`.
name: A name for the operation (optional).
Returns:
A Tensor with the same type as `x`.
"""
with ops.name_scope(name, "LogSigmoid", [x]) as name:
x = ops.convert_to_tensor(x, name="x")
return gen_math_ops._neg(gen_nn_ops.softplus(-x), name=name)
示例3: sigmoid
# 需要導入模塊: from tensorflow.python.ops import gen_math_ops [as 別名]
# 或者: from tensorflow.python.ops.gen_math_ops import exp [as 別名]
def sigmoid(x, name=None):
"""Computes sigmoid of `x` element-wise.
Specifically, `y = 1 / (1 + exp(-x))`.
Args:
x: A Tensor with type `float32`, `float64`, `int32`, `complex64`, `int64`,
or `qint32`.
name: A name for the operation (optional).
Returns:
A Tensor with the same type as `x` if `x.dtype != qint32`
otherwise the return type is `quint8`.
"""
with ops.name_scope(name, "Sigmoid", [x]) as name:
x = ops.convert_to_tensor(x, name="x")
return gen_math_ops._sigmoid(x, name=name)
示例4: _predicted_covariance_op
# 需要導入模塊: from tensorflow.python.ops import gen_math_ops [as 別名]
# 或者: from tensorflow.python.ops.gen_math_ops import exp [as 別名]
def _predicted_covariance_op(self, activations, num_values):
activation, activation_size = activations[-1]
if self.loss == ARModel.NORMAL_LIKELIHOOD_LOSS:
log_sigma_square = model_utils.fully_connected(
activation,
activation_size,
self.output_window_size * num_values,
name="log_sigma_square",
activation=None)
predicted_covariance = gen_math_ops.exp(log_sigma_square)
predicted_covariance = tf.reshape(
predicted_covariance, [-1, self.output_window_size, num_values])
else:
shape = tf.stack([
tf.compat.v1.shape(activation)[0],
tf.constant(self.output_window_size),
tf.constant(num_values)
])
predicted_covariance = tf.ones(shape=shape, dtype=activation.dtype)
return predicted_covariance
示例5: sigmoid
# 需要導入模塊: from tensorflow.python.ops import gen_math_ops [as 別名]
# 或者: from tensorflow.python.ops.gen_math_ops import exp [as 別名]
def sigmoid(x, name=None):
"""Computes sigmoid of `x` element-wise.
Specifically, `y = 1 / (1 + exp(-x))`.
Args:
x: A Tensor with type `float16`, `float32`, `float64`, `complex64`,
or `complex128`.
name: A name for the operation (optional).
Returns:
A Tensor with the same type as `x`.
@compatibility(numpy)
Equivalent to np.scipy.special.expit
@end_compatibility
"""
with ops.name_scope(name, "Sigmoid", [x]) as name:
x = ops.convert_to_tensor(x, name="x")
return gen_math_ops._sigmoid(x, name=name)
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:22,代碼來源:math_ops.py
示例6: call
# 需要導入模塊: from tensorflow.python.ops import gen_math_ops [as 別名]
# 或者: from tensorflow.python.ops.gen_math_ops import exp [as 別名]
def call(self, inputs):
inputs = ops.convert_to_tensor(inputs, dtype=self.dtype)
if common_shapes.rank(inputs) is not 2:
raise ValueError('`WalkerModel` only takes "rank 2" inputs.')
sig = 1/(1+gen_math_ops.exp(self.kernel[0]*inputs[:,1]))
gamma = sig*self.kernel[1]
C = self.kernel[2]/((1-inputs[:,1])**(self.kernel[3]*(1-gamma)))
output = C*(inputs[:,0]**self.kernel[3])
output = array_ops.reshape(output,(array_ops.shape(output)[0],1))
return output
示例7: call
# 需要導入模塊: from tensorflow.python.ops import gen_math_ops [as 別名]
# 或者: from tensorflow.python.ops.gen_math_ops import exp [as 別名]
def call(self, input_window_features, output_window_features):
"""Compute predictions from input and output windows."""
_, state_h, state_c = self._encoder(input_window_features)
encoder_states = [state_h, state_c]
decoder_output = self._decoder(
output_window_features, initial_state=encoder_states)
predicted_mean = self._mean_transform(decoder_output)
predicted_covariance = gen_math_ops.exp(
self._covariance_transform(decoder_output))
return {"mean": predicted_mean, "covariance": predicted_covariance}
示例8: reduce_logsumexp
# 需要導入模塊: from tensorflow.python.ops import gen_math_ops [as 別名]
# 或者: from tensorflow.python.ops.gen_math_ops import exp [as 別名]
def reduce_logsumexp(input_tensor,
axis=None,
keep_dims=False,
name=None,
reduction_indices=None):
"""Computes log(sum(exp(elements across dimensions of a tensor))).
Reduces `input_tensor` along the dimensions given in `axis`.
Unless `keep_dims` is true, the rank of the tensor is reduced by 1 for each
entry in `axis`. If `keep_dims` is true, the reduced dimensions
are retained with length 1.
If `axis` has no entries, all dimensions are reduced, and a
tensor with a single element is returned.
This function is more numerically stable than log(sum(exp(input))). It avoids
overflows caused by taking the exp of large inputs and underflows caused by
taking the log of small inputs.
For example:
```python
# 'x' is [[0, 0, 0]]
# [0, 0, 0]]
tf.reduce_logsumexp(x) ==> log(6)
tf.reduce_logsumexp(x, 0) ==> [log(2), log(2), log(2)]
tf.reduce_logsumexp(x, 1) ==> [log(3), log(3)]
tf.reduce_logsumexp(x, 1, keep_dims=True) ==> [[log(3)], [log(3)]]
tf.reduce_logsumexp(x, [0, 1]) ==> log(6)
```
Args:
input_tensor: The tensor to reduce. Should have numeric type.
axis: The dimensions to reduce. If `None` (the default),
reduces all dimensions.
keep_dims: If true, retains reduced dimensions with length 1.
name: A name for the operation (optional).
reduction_indices: The old (deprecated) name for axis.
Returns:
The reduced tensor.
"""
with ops.name_scope(name, "ReduceLogSumExp", [input_tensor]) as name:
my_max = array_ops.stop_gradient(
reduce_max(
input_tensor,
axis=axis,
reduction_indices=reduction_indices,
keep_dims=True))
result = gen_math_ops.log(
reduce_sum(
gen_math_ops.exp(input_tensor - my_max),
axis,
keep_dims=True,
reduction_indices=reduction_indices)) + my_max
if not keep_dims:
if isinstance(axis, int):
axis = [axis]
result = array_ops.squeeze(result, axis)
return result
示例9: reduce_logsumexp
# 需要導入模塊: from tensorflow.python.ops import gen_math_ops [as 別名]
# 或者: from tensorflow.python.ops.gen_math_ops import exp [as 別名]
def reduce_logsumexp(input_tensor, reduction_indices=None, keep_dims=False,
name=None):
"""Computes log(sum(exp(elements across dimensions of a tensor))).
Reduces `input_tensor` along the dimensions given in `reduction_indices`.
Unless `keep_dims` is true, the rank of the tensor is reduced by 1 for each
entry in `reduction_indices`. If `keep_dims` is true, the reduced dimensions
are retained with length 1.
If `reduction_indices` has no entries, all dimensions are reduced, and a
tensor with a single element is returned.
This function is more numerically stable than log(sum(exp(input))). It avoids
overflows caused by taking the exp of large inputs and underflows caused by
taking the log of small inputs.
For example:
```python
# 'x' is [[0, 0, 0]]
# [0, 0, 0]]
tf.reduce_logsumexp(x) ==> log(6)
tf.reduce_logsumexp(x, 0) ==> [log(2), log(2), log(2)]
tf.reduce_logsumexp(x, 1) ==> [log(3), log(3)]
tf.reduce_logsumexp(x, 1, keep_dims=True) ==> [[log(3)], [log(3)]]
tf.reduce_logsumexp(x, [0, 1]) ==> log(6)
```
Args:
input_tensor: The tensor to reduce. Should have numeric type.
reduction_indices: The dimensions to reduce. If `None` (the default),
reduces all dimensions.
keep_dims: If true, retains reduced dimensions with length 1.
name: A name for the operation (optional).
Returns:
The reduced tensor.
"""
with ops.name_scope(name, "ReduceLogSumExp", [input_tensor]) as name:
my_max = array_ops.stop_gradient(
reduce_max(input_tensor, reduction_indices, keep_dims=True))
result = gen_math_ops.log(reduce_sum(
gen_math_ops.exp(input_tensor - my_max),
reduction_indices,
keep_dims=True)) + my_max
if not keep_dims:
if isinstance(reduction_indices, int):
reduction_indices = [reduction_indices]
result = array_ops.squeeze(result, reduction_indices)
return result