$sigmoid (aggregation)
On this page
Definition
$sigmoid
Performs the sigmoid function, which calculates the percentile of a number in the normal distribution with standard deviation 1.
The
$sigmoid
expression has the following syntax:{ $sigmoid: { input: <numeric expression>, onNull: <expression>} } The arguments can be any valid expression as long as they resolve to all numbers.
The sigmoid function is equivalent to the following algebraic operation:
click to enlarge
Example
This example uses a myScores
collection that contains the following documents:
db.myScores.insertMany( [ { score: 1 }, { score: 5 }, {}, { score: 13 }, { score: null }, { score: 21 }, ] )
The following aggregation pipeline adds a scaled
field to each document and uses
$sigmoid
to calculate the scaled
field value:
db.myScores.aggregate( [ { $set: { scaled: { $sigmoid: "$score" } } } ] )
The operation returns the following documents:
{ score: 1, scaled: 0.7310585786 } { score: 5, scaled: 0.9933071491 } { scaled: null } { score: 13, scaled: 0.9999977397 } { score: null, scaled: null } { score: 19, scaled: 0.9999999992 }