Gurgen Arakelov
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Logistic Regression Function *The article details the solution provided by the winner of the Logistic Regression Challenge.* #### Author: [Aikata (Ph.D. student, TU Graz)](https://www.iaik.tugraz.at/person/aikata-aikata/) --- ## What is Logistic function <img src="https://hackmd.io/_uploads/SJBg0P3hp.png" alt="drawing" width="20" /> <p style="text-align: center;"><img src="https://hackmd.io/_uploads/Hk_Td06ha.png" width="650" /> <br> <small><small> Inspired from <a href="https://www.imaginary.org/gallery/maths-dance-moves">Imaginary</a></small></small> </p> The logistic (a.k.a., sigmoid) function- $\frac{1}{1+e^{-x}}$ forms the basis for logistic regression-based machine learning. It is also 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. Therefore, 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 [[KSK+18],[KSW+18],[XWBB16],[AHPW16]]. Therefore, it is crucial to investigate the extent to which we can approximate the logistic function under constrained multiplicative depth. ## <img src="https://hackmd.io/_uploads/SkcCXdh2p.png" alt="drawing" width="65"/> &nbsp; The FHERMA Challenge The challenge has 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 [−25, 25]. The straightforward logistic evaluation of this range is illustrated in Figure 1. <p float="left"> <img src="https://hackmd.io/_uploads/BkdAYe83a.png" width="350" /> <img src="https://hackmd.io/_uploads/HkT6FgLhp.png" width="350" /> </p> <p style="text-align: center;"><b>Figure 1:</b> Sigmoid function and its approximation using Chebyshev series.</p> One standard method for approximating the logistic function involves employing the Chebyshev series. However, the Chebyshev series provides results over the domain [−1, 1]. Therefore, to apply the Chebyshev series to broader domains (e.g., [a, b]), the input polynomial’s (e.g., $x$) domain is scaled to bring it to the interval [−1, 1] as outlined below, ensuring the applicability of the Chebyshev approximation. \begin{align} x' & = \frac{2x - (b+a)}{b-a} \\ x' & = \frac{x}{\omega} \hspace{20pt} \text{ when, } |a|=|b|, a \neq b,\text{ and }\omega=|b| \end{align} The scaled ciphertext $x'$ 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](https://github.com/openfheorg/openfhe-development/blob/main/src/pke/examples/FUNCTION_EVALUATION.md) for function evaluation. Consequently, when presented with a challenge specifying a multiplicative depth $d$ over an arbitrary range $[a,b]$, such that $a\neq-1$ and $b\neq1$, the available Chebyshev series approximation technique allows us to evaluate up to a depth of $d-1$ 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 $(2^7=128 \rightarrow 2^6=64),$ as shown in Figure 1 (a) does not result in a significant loss of accuracy, but dropping from 4 to 3 ($2^4 = 16 \rightarrow 2^3 = 8$) entails a considerable loss (Figure 1 (b)). Therefore, our exploration focuses on enhancing this existing technique to yield the best approximation results. ## <img src="https://hackmd.io/_uploads/BJUDuu336.png" alt="drawing" width="50" /> &nbsp; Test Case 1 The first test case permits a multiplicative depth of seven. Initially, we assess the capabilities of the current implementation to determine how well we can approximate. Notably, with OpenFHE's ChebyshevPS implementation, 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, we delve into the recursive unroll of $\textbf{T}_{65}$ as outlined below: \begin{align} \text{c}\times\textbf{T}_{65} && \rightarrow && \text{2c}\times\textbf{T}_{32}\times\textbf{T}_{33}-\text{c}\times\textbf{T}_{1} && \rightarrow && \textbf{T}_{32}\times(\text{2c}\times\textbf{T}_{33})-\text{c}\times\textbf{T}_{1}\\ \text{2c}\times\textbf{T}_{33} && \rightarrow && \text{4c}\times\textbf{T}_{16}\times\textbf{T}_{17}-\text{2c}\times\textbf{T}_{1} && \rightarrow && \textbf{T}_{16}\times(\text{4c}\times\textbf{T}_{17})-\text{2c}\times\textbf{T}_{1}\\ \text{4c}\times\textbf{T}_{17} && \rightarrow && \text{8c}\times\textbf{T}_{8}\times\textbf{T}_{9}-\text{4c}\times\textbf{T}_{1} && \rightarrow && \textbf{T}_{8}\times(\text{8c}\times\textbf{T}_{9})-\text{4c}\times\textbf{T}_{1}\\ \text{8c}\times\textbf{T}_{9} && \rightarrow && \text{16c}\times\textbf{T}_{4}\times\textbf{T}_{5}-\text{8c}\times\textbf{T}_{1} && \rightarrow && \textbf{T}_{4}\times(\text{16c}\times\textbf{T}_{5})-\text{8c}\times\textbf{T}_{1}\\ \text{16c}\times\textbf{T}_{5} && \rightarrow && \text{32c}\times\textbf{T}_{2}\times\textbf{T}_{3}-\text{16c}\times\textbf{T}_{1} && \rightarrow && \textbf{T}_{2}\times(\text{32c}\times\textbf{T}_{3})-\text{16c}\times\textbf{T}_{1} \end{align} 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, we continue the breakdown until we reach $\textbf{T}_2$ and $\textbf{T}_3$, which can be represented as follows: \begin{align} \textbf{T}_{2} && \rightarrow && \text{2x}'^2-1 && \text{// Multiplicative depth 2}\\ c\times\textbf{T}_{3} && \rightarrow && \text{4cx}'^3-\text{3cx}' && \text{// Multiplicative depth 3} \end{align} <img src="https://hackmd.io/_uploads/HJTLXC636.png" alt="drawing" width="25" /> $\textbf{T}_3$ is at a higher depth than $\textbf{T}_2$. The computation of $\textbf{T}_{65}$ relies on our ability to compute $32c\times\textbf{T}_3$ while remaining at the same multiplicative depth as $\textbf{T}_2$. In this context, we emphasize that '*the sky is not the limit*' <img src="https://hackmd.io/_uploads/BJx3CY_23p.png" alt="drawing" width="30"/> and indeed, there is a method to accomplish this, as illustrated in the equations below: \begin{align} 32c\times\textbf{T}_{3} && \rightarrow && \frac{128c}{\omega^3} x^3-\text{96cx}' && \text{// Multiplicative depth 2}\\ && \rightarrow && (\frac{128c}{\omega^3}x)(x^2)-\text{96cx}' && \text{// Multiplicative depth 2} \end{align} 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 $\textbf{T}_{65}$, we calculate odd series coefficients up to $\textbf{T}_{77}$, successfully achieving our target of $100\%$ (99.9988\%) accuracy for this particular test case. While approximating up to $\textbf{T}_{77}$ sufficed for the first test case, it remains interesting to investigate how far we can extend this breakdown before reaching limitations. ## <img src="https://hackmd.io/_uploads/BJUDuu336.png" alt="drawing" width="50" /> &nbsp; Test Case 2 In this particular test case, a multiplicative depth of four is mandated. <img src="https://hackmd.io/_uploads/HJjomKn3p.png" alt="drawing" width="45" /> The straight-forward Chebyshev series computation up to coefficient seven 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 $x^7$ in a very straightforward manner, as shown below. \begin{align} \texttt{SUM}_7 = (c_7\times x^4)\times x^3 +(c_5\times x^3)\times x^2 +(c_3\times x^2)\times x + c_1\times x+ c_0 \end{align} <img src="https://hackmd.io/_uploads/HJTLXC636.png" alt="drawing" width="28" /> For the subsequent 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: \begin{align} y_1 && = && (10^{-3}\times x )\times x && \text{// $10^{-3}\times x^2$ at depth 2}\\ y_2 && = && (c_9\times 10^{6} \times x )\times x && \text{// $c_9 \times 10^{6}\times x^2$ at depth 2}\\ c_9\times x^9 && = && (y_1\times y_1) \times (y_2\times x^3) && \end{align} <img src="https://hackmd.io/_uploads/HJTLXC636.png" alt="drawing" width="28" /> Applying this approach, we can extend the evaluation to $x^{13}$ 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 $x^{14}$. Thus, we have reached the limit of this technique. \begin{align} y_1 && = && (10^{-6}\times x )\times x^2 && \text{//$10^{-6}\times x^3$ at depth 2}\\ y_2 && = && (c_{13}\times 10^{12} \times x )\times x^2 && \text{// $c_{13} \times 10^{12}\times x^3$ at depth 2}\\ c_{13}\times x^{13} && = && (y_1\times y_1) \times (y_2\times x^4) && \end{align} The computation up to $x^{13}$ led to an enhancement in accuracy from $88.12\%$ to $96.6\%$ <img src="https://hackmd.io/_uploads/ryckn_n3a.png" alt="drawing" width="45" />, which is a significant improvement in the attainable accuracy. Exploring the effectiveness of this technique in approximating functions other than logistic functions at different depths would be an interesting avenue for future exploration. ___ ## <img src="https://hackmd.io/_uploads/BknuCw_pT.png" alt="drawing" width="30"/> Ready, set, LOG! Dive into the private Logistic function implementations live at: https://github.com/fairmath/components/ ___ [KSK+18]: http://eprint.iacr.org/2018/254 [KSW+18]: http://eprint.iacr.org/2018/074 [XWBB16]: http://arxiv.org/abs/1611.01170 [AHPW16]: https://doi.org/10.1145/2857705.2857731 [LLNK22]: https://doi.org/10.1109/TDSC.2021.3105111 [image]: ![](https://hackmd.io/_uploads/By08S_OTp.png) <p style="text-align:center;font-family:georgia,garamond;"> Made with ♥️ </p>

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully