tf.math.sigmoid
Stay organized with collections
Save and categorize content based on your preferences.
Computes sigmoid of x
element-wise.
tf.math.sigmoid(
x, name=None
)
Used in the notebooks
Used in the guide |
Used in the tutorials |
|
|
Formula for calculating \(\mathrm{sigmoid}(x) = y = 1 / (1 + \exp(-x))\).
For \(x \in (-\infty, \infty)\), \(\mathrm{sigmoid}(x) \in (0, 1)\).
Example Usage:
If a positive number is large, then its sigmoid will approach to 1 since the
formula will be y = <large_num> / (1 + <large_num>)
x = tf.constant([0.0, 1.0, 50.0, 100.0])
tf.math.sigmoid(x)
<tf.Tensor: shape=(4,), dtype=float32,
numpy=array([0.5, 0.7310586, 1.0, 1.0], dtype=float32)>
If a negative number is large, its sigmoid will approach to 0 since the
formula will be y = 1 / (1 + <large_num>)
x = tf.constant([-100.0, -50.0, -1.0, 0.0])
tf.math.sigmoid(x)
<tf.Tensor: shape=(4,), dtype=float32, numpy=
array([0.0000000e+00, 1.9287499e-22, 2.6894143e-01, 0.5],
dtype=float32)>
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 .
|
Usage Example:
x = tf.constant([-128.0, 0.0, 128.0], dtype=tf.float32)
tf.sigmoid(x)
<tf.Tensor: shape=(3,), dtype=float32,
numpy=array([0. , 0.5, 1. ], dtype=float32)>
Equivalent to scipy.special.expit
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.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.math.sigmoid\n\n|------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/math_ops.py#L4069-L4119) |\n\nComputes sigmoid of `x` element-wise.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.nn.sigmoid`](https://www.tensorflow.org/api_docs/python/tf/math/sigmoid), [`tf.sigmoid`](https://www.tensorflow.org/api_docs/python/tf/math/sigmoid)\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.sigmoid`](https://www.tensorflow.org/api_docs/python/tf/math/sigmoid)\n\n\u003cbr /\u003e\n\n tf.math.sigmoid(\n x, name=None\n )\n\n### Used in the notebooks\n\n| Used in the guide | Used in the tutorials |\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Logistic regression for binary classification with Core APIs](https://www.tensorflow.org/guide/core/logistic_regression_core) - [Advanced automatic differentiation](https://www.tensorflow.org/guide/advanced_autodiff) - [Introduction to gradients and automatic differentiation](https://www.tensorflow.org/guide/autodiff) | - [Convolutional Variational Autoencoder](https://www.tensorflow.org/tutorials/generative/cvae) - [Transfer learning and fine-tuning](https://www.tensorflow.org/tutorials/images/transfer_learning) - [Classify structured data using Keras preprocessing layers](https://www.tensorflow.org/tutorials/structured_data/preprocessing_layers) - [Classify text with BERT](https://www.tensorflow.org/text/tutorials/classify_text_with_bert) - [Shape Constraints for Ethics with Tensorflow Lattice](https://www.tensorflow.org/lattice/tutorials/shape_constraints_for_ethics) |\n\nFormula for calculating \\\\(\\\\mathrm{sigmoid}(x) = y = 1 / (1 + \\\\exp(-x))\\\\).\n\nFor \\\\(x \\\\in (-\\\\infty, \\\\infty)\\\\), \\\\(\\\\mathrm{sigmoid}(x) \\\\in (0, 1)\\\\).\n\n#### Example Usage:\n\nIf a positive number is large, then its sigmoid will approach to 1 since the\nformula will be `y = \u003clarge_num\u003e / (1 + \u003clarge_num\u003e)` \n\n x = tf.constant([0.0, 1.0, 50.0, 100.0])\n tf.math.sigmoid(x)\n \u003ctf.Tensor: shape=(4,), dtype=float32,\n numpy=array([0.5, 0.7310586, 1.0, 1.0], dtype=float32)\u003e\n\nIf a negative number is large, its sigmoid will approach to 0 since the\nformula will be `y = 1 / (1 + \u003clarge_num\u003e)` \n\n x = tf.constant([-100.0, -50.0, -1.0, 0.0])\n tf.math.sigmoid(x)\n \u003ctf.Tensor: shape=(4,), dtype=float32, numpy=\n array([0.0000000e+00, 1.9287499e-22, 2.6894143e-01, 0.5],\n dtype=float32)\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|-----------------------------------------------------------------------------------|\n| `x` | A Tensor with type `float16`, `float32`, `float64`, `complex64`, or `complex128`. |\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\n x = tf.constant([-128.0, 0.0, 128.0], dtype=tf.float32)\n tf.sigmoid(x)\n \u003ctf.Tensor: shape=(3,), dtype=float32,\n numpy=array([0. , 0.5, 1. ], dtype=float32)\u003e\n\n\u003cbr /\u003e\n\nscipy compatibility\n-------------------\n\n\u003cbr /\u003e\n\nEquivalent to scipy.special.expit\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]