$sigmoid
New from version 8.0.1.
The $sigmoid operator in Amazon DocumentDB applies the logistic sigmoid function, 1 / (1 + e^(-x)), to a numeric input. The function maps any real number to a value between 0 and 1, producing an S-shaped curve. This is useful when you need to normalize values into the 0–1 range, such as converting raw scores into probabilities or relevance scores.
Parameters
expression: An expression that resolves to a numeric value.
Example (MongoDB Shell)
The following example shows how to use the $sigmoid operator to convert logit values into probabilities.
Create sample documents
db.predictions.insertMany([ {_id: 1, logit: -2}, {_id: 2, logit: 0}, {_id: 3, logit: 2} ]);
Query example
db.predictions.aggregate([ { $project: { probability: { $sigmoid: "$logit" } } } ]);
Output
[
{_id: 1, probability: 0.11920292202211755},
{_id: 2, probability: 0.5},
{_id: 3, probability: 0.8807970779778823}
]
Code examples
To view a code example for using the $sigmoid operator, choose the tab for the language that you want to use: