tf.math.log_sigmoid
Stay organized with collections
Save and categorize content based on your preferences.
Computes log sigmoid of x
element-wise.
tf.math.log_sigmoid(
x, name=None
)
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 .
|
Usage Example:
If a positive number is large, then its log_sigmoid will approach to 0 since
the formula will be y = log( <large_num> / (1 + <large_num>) )
which
approximates to log (1)
which is 0.
x = tf.constant([0.0, 1.0, 50.0, 100.0])
tf.math.log_sigmoid(x)
<tf.Tensor: shape=(4,), dtype=float32, numpy=
array([-6.9314718e-01, -3.1326169e-01, -1.9287499e-22, -0.0000000e+00],
dtype=float32)>
If a negative number is large, its log_sigmoid will approach to the number
itself since the formula will be y = log( 1 / (1 + <large_num>) )
which is
log (1) - log ( (1 + <large_num>) )
which approximates to - <large_num>
that is the number itself.
x = tf.constant([-100.0, -50.0, -1.0, 0.0])
tf.math.log_sigmoid(x)
<tf.Tensor: shape=(4,), dtype=float32, numpy=
array([-100. , -50. , -1.3132616, -0.6931472],
dtype=float32)>
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.math.log_sigmoid\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/math_ops.py#L4122-L4164) |\n\nComputes log sigmoid of `x` element-wise.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.log_sigmoid`](https://www.tensorflow.org/api_docs/python/tf/math/log_sigmoid)\n\n\u003cbr /\u003e\n\n tf.math.log_sigmoid(\n x, name=None\n )\n\nSpecifically, `y = log(1 / (1 + exp(-x)))`. For numerical stability,\nwe use `y = -tf.nn.softplus(-x)`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|--------------------------------------------|\n| `x` | A Tensor with type `float32` or `float64`. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A Tensor with the same type as `x`. ||\n\n\u003cbr /\u003e\n\n#### Usage Example:\n\nIf a positive number is large, then its log_sigmoid will approach to 0 since\nthe formula will be `y = log( \u003clarge_num\u003e / (1 + \u003clarge_num\u003e) )` which\napproximates to `log (1)` which is 0. \n\n x = tf.constant([0.0, 1.0, 50.0, 100.0])\n tf.math.log_sigmoid(x)\n \u003ctf.Tensor: shape=(4,), dtype=float32, numpy=\n array([-6.9314718e-01, -3.1326169e-01, -1.9287499e-22, -0.0000000e+00],\n dtype=float32)\u003e\n\nIf a negative number is large, its log_sigmoid will approach to the number\nitself since the formula will be `y = log( 1 / (1 + \u003clarge_num\u003e) )` which is\n`log (1) - log ( (1 + \u003clarge_num\u003e) )` which approximates to `- \u003clarge_num\u003e`\nthat is the number itself. \n\n x = tf.constant([-100.0, -50.0, -1.0, 0.0])\n tf.math.log_sigmoid(x)\n \u003ctf.Tensor: shape=(4,), dtype=float32, numpy=\n array([-100. , -50. , -1.3132616, -0.6931472],\n dtype=float32)\u003e"]]