Database Manual / Reference / Query Language / Expressions

$sigmoid (aggregation)(聚合)

Definition定义

$sigmoid

Performs the sigmoid function, which calculates the percentile of a number in the normal distribution with standard deviation 1.执行sigmoid函数,该函数计算标准偏差为1的正态分布中数字的百分位数。

The $sigmoid expression has the following syntax:$sigmoid表达式具有以下语法:

{ $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:sigmoid函数等价于以下代数运算:

The sigmoid function

Example示例

This example uses a myScores collection that contains the following documents:此示例使用包含以下文档的myScores集合:

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:以下聚合管道为每个文档添加一个scaled字段,并使用$sigmoid计算scaled字段值:

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 }