# Sigmoid

The quantized sigmoid function is defined as follows:

$$\sigma\_Q(x) = \dfrac{Q}{1 + 2^{-x}}$$

where $Q$ is the quantization (scaling) factor. We use $2$ instead of $e$ to avoid floating point operations.

### Implementation

| Step | Operation       | Description                                                                          |
| ---- | --------------- | ------------------------------------------------------------------------------------ |
| 1    | VirtualConst(0) | Create constant zero tensor for comparisons                                          |
| 2    | Gte             | Compute `ge0 = (z >= 0)` to track sign of input                                      |
| 3    | Sub             | Compute `neg_z = -z` for absolute value calculation                                  |
| 4    | Select          | Compute `abs_z = select(ge0, z, -z)` (absolute value)                                |
| 5    | VirtualPow2     | Compute \`pow2 = 2^{                                                                 |
| 6    | VirtualConst(Q) | Load quantization constant `Q`                                                       |
| 7    | Mul             | Compute `Q² = Q * Q`                                                                 |
| 8    | Div             | Compute \`div\_Q\_pow = Q / 2^{                                                      |
| 9    | Mul             | Compute \`mul\_Q\_pow = Q \* 2^{                                                     |
| 10   | Select          | Compute `a = select(ge0, div_Q_pow, mul_Q_pow)` (choose branch based on sign of `z`) |
| 11   | Add             | Compute `b = Q + a`                                                                  |
| 12   | Div             | Compute `c = Q² / b` → final quantized sigmoid output `σ_Q(z)`                       |
| 13   | VirtualMove     | Move final tensor `c` to output destination                                          |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devs.novanet.xyz/jolt-atlas-zkml/onnx/tensor-instructions/virtual-instructions/sigmoid.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
