Logistic (Sigmoid) Function under FHE
The article details the solution provided by the winner of the Logistic Function challenge.
Author: Aikata, Ph.D. student at TU Graz
Introduction
The logistic (a.k.a., sigmoid) function forms the basis for logistic regression-based machine learning. It is commonly employed as a non-linear activation function in neural networks. Homomorphic schemes like CKKS only support polynomial arithmetic operations, and expressing the sigmoid function as a polynomial is not feasible. Various series, such as the Taylor series or the Chebyshev series, are utilized to approximate the sigmoid function. Recent efforts have focused on developing privacy-preserving models for logistic regression training and inference by employing similar approximations of the logistic function - works 1, 2, 3, and 4. Therefore, it is crucial to investigate the extent to which we can approximate the logistic function under constrained multiplicative depth.
Sigmoid Approximation
The challenge contains two sets of test cases, distinguished solely in terms of the permitted multiplicative depth. The input values for both sets of test cases are confined to the range of . The straightforward logistic evaluation of this range is illustrated in Figure 1.
![]() | ![]() |
|---|---|
| a) Sigmoid and its function approximation using Chebyshev series (64,128). | b) Sigmoid and its function approximation using Chebyshev series (8,16). |
Figure 1: Sigmoid function and its approximation using Chebyshev series.
As previously mentioned, one common method for approximating the logistic function involves employing the Chebyshev series. However, the Chebyshev series provides results over the domain [−1, 1]. To apply the Chebyshev series to broader ranges (e.g., ), the input polynomial (e.g., ) is scaled to bring it to the interval as outlined below, ensuring the applicability of the Chebyshev approximation.
The scaled ciphertext is subsequently employed for the approximation. However, note that this scaling results in the loss of one multiplicative depth. This aspect is explicitly mentioned in the library documentation for function evaluation.
Consequently, when presented with a challenge specifying a multiplicative depth over an arbitrary range , such that and , the available Chebyshev series approximation technique allows us to evaluate up to a depth of at best. To fully exploit this using OpenFHE, the technique described in the SIGN challenge solution can be applied. However, it becomes evident that although reducing the depth from 7 to 6 , as shown in Figure 1(a) does not result in a significant loss of accuracy, but dropping from 4 to 3 () entails a considerable loss (Figure 1(b)). Therefore, our exploration focuses on enhancing this existing technique to yield the best approximation results.
Test case #1
The first test case permits a multiplicative depth of 7. Initially, let's assess the capabilities of the current implementation to determine how well we can approximate. With OpenFHE's ChebyshevPS implementation, we find that we can evaluate the Chebyshev series up to the coefficient 59. Applying the SIGN challenge strategy can extend this evaluation to 63 coefficients, resulting in an impressive accuracy of 99.99%. To walk the extra mile (or 0.01%) for achieving complete accuracy, let's delve into the recursive unroll of as outlined below:
Note that this recursive breakdown is just one of the numerous possible approaches. Examining this breakdown, we notice that at each step the two coefficients to be multiplied are at different depths, and one consistently exceeds the exploitable multiplicative depth at that level. Thus, let's continue the breakdown until we reach and , which can be represented as follows:
Keep in mind that is at a higher depth compared to . The computation of relies on our ability to compute while remaining at the same multiplicative depth as . In this context, we emphasize that the sky is not the limit and indeed, there is a method to accomplish this, as illustrated in the equations below:
The logistic function is an odd function, and only the odd coefficients of the Chebyshev series contribute to its approximation. Leveraging recursive breakdowns like the one for , we calculate odd series coefficients up to , almost achieving our target of a 100% (99.9988%) accuracy for this particular test case. While approximating up to sufficed for the first test case, it remains to investigate how far we can extend this breakdown before reaching limitations.
Test case #2
In this particular test case, a multiplicative depth of 4 is mandated. The straightforward Chebyshev series computation up to coefficient 7 resulted in an accuracy of 88.12%, falling short of the minimum requirement of 90%. Therefore, a comprehensive exploration of the approach identified in the previous test case becomes necessary. It is important to highlight that Chebyshev series computation can be transformed into a simple polynomial evaluation. Given the low multiplicative depth, it becomes evident that converting the Chebyshev computation to polynomial evaluation is crucial for a thorough investigation of the limitations of the aforementioned technique.
An example of coefficients generated for evaluating an unscaled polynomial of degree 16 are as follows: {0.5, 0.19, 0.0, -0.004, 0.0, 4.83e-05, 0.0, -2.97e-07, 0.0, 1.02e-09, 0.0, -1.94e-12, 0.0, 1.94e-15, 0.0, -7.89e-19, 0.0}. Notably, the values of these coefficients decrease progressively. This diminishing trend arises because the scaling factor, previously managed by the ciphertext, is now concentrated at the coefficient level. We compute the evaluation up to in a very straightforward manner, as shown below
For the next evaluation, it is apparent that coefficients 9, 11, 13, and 15 are exceedingly small, nearly reaching the limits of the scaling factor. It will result in computational errors if not handled cautiously. Hence, we recommend breaking down the computation of higher coefficients into smaller chunks, as outlined below:
Applying this approach, we can extend the evaluation up to as depicted in the equation below. This limitation arises because the coefficient computation needs to be divided into at least two parts. The maximum degree achievable with two constant multiplications in this manner is . Thus, we have reached the limit of this technique.
The computation up to led to an enhancement in accuracy from 88.12% to 96.6%, which is a significant improvement in the attainable accuracy. Exploring the effectiveness of this approach in other approximating functions at different depths seems to be an interesting area for future investigation.
CITING THIS WORK
This write-up documents a component of the FHERMA library. If it informs your work, cite the two papers below rather than the article URL.
- 01FHERMA Cookbook: FHE Components for Privacy-Preserving ApplicationsJanis Adamek, Aikata Aikata, Ahmad Al Badawi, Andreea Alexandru, Armen Arakelov, Philipp Binfet, Victor Correa, Jules Dumezy, Sergey Gomenyuk, Valentina Kononova, Dmitrii Lekomtsev, Vivian Maloney, Chi-Hieu Nguyen, Yuriy Polyakov, Daria Pianykh, Hayim Shaul, Moritz Schulze Darup, Dieter Teichrib, Dmitry Tronin, Gurgen ArakelovCryptology ePrint Archive, Paper 2025/1302 · doi:10.1145/3733811.3767313
- 02FHERMA: Building the Open-Source FHE Components Library for Practical UseGurgen Arakelov, Nikita Kaskov, Daria Pianykh, Yuriy PolyakovCryptology ePrint Archive, Paper 2024/612


