<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jahanzeb on Medium]]></title>
        <description><![CDATA[Stories by Jahanzeb on Medium]]></description>
        <link>https://medium.com/@jahanxb?source=rss-ffc096f79a5b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JR1pdT4SLnvbJW5MK_OM6Q.jpeg</url>
            <title>Stories by Jahanzeb on Medium</title>
            <link>https://medium.com/@jahanxb?source=rss-ffc096f79a5b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 16:32:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jahanxb/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How does floating point multiplication works in CKKS and how much accurate points it can produce ?]]></title>
            <link>https://medium.com/@jahanxb/how-does-floating-point-multiplication-works-in-ckks-and-how-much-accurate-points-it-can-produce-be8a5fe396c8?source=rss-ffc096f79a5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/be8a5fe396c8</guid>
            <category><![CDATA[multiplication]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[arithmetic]]></category>
            <category><![CDATA[floating-points]]></category>
            <category><![CDATA[homomorphic-encryption]]></category>
            <dc:creator><![CDATA[Jahanzeb]]></dc:creator>
            <pubDate>Tue, 29 Aug 2023 20:03:16 GMT</pubDate>
            <atom:updated>2023-08-29T20:03:16.410Z</atom:updated>
            <content:encoded><![CDATA[<h3>How does floating point multiplication works in CKKS and how much accurate points it can produce ?</h3><p>Floating point multiplication in the CKKS scheme follows the polynomial multiplication along with handling the scaling factor that represents the floating point numbers. Here’s an overview:</p><p>Floating-Point Multiplication in CKKS:</p><ol><li><strong>Encoding:</strong> Real or complex floating-point numbers are encoded into plaintext polynomials. This encoding scales the numbers by a large factor (often a power of 2) to handle the fractional part, effectively converting them into integers.</li><li><strong>Encryption:</strong> The plaintext polynomials are encrypted to produce ciphertexts.</li><li><strong>Ciphertext Multiplication:</strong> Multiply the corresponding ciphertexts using polynomial multiplication, followed by reduction modulo the cyclotomic polynomial and the co-efficient modulus.</li><li><strong>Rescaling:</strong> Since both of the encoded values were scaled, the product will have a squared scaling factor. Rescaling is performed to reduce this back to the original scaling factor. This operation effectively divides the ciphertext by the scaling factor, and it involves a modular reduction that reduces the noise level.</li><li><strong>Relinearization:</strong> If necessary, relinearization maybe performed to reduce the size of the ciphertext back to its original level.</li><li><strong>Decryption and Decoding:</strong> The resulting ciphertext is decrypted using the secret key, and the plaintext polynomial is decoded back into a floating-point number.</li></ol><p><strong>Accuracy Considerations:</strong></p><p>The accuracy of floating-point multiplication in CKKS depends on several factors:</p><ol><li><strong>Scaling Factor: </strong>The choice of scaling factor during encoding has a big impact on precision. A larger scaling factor allows for more accurate representation but requires careful management during operations like rescaling.</li><li><strong>Noise Growth: </strong>Multiplication significantly increases the noise in the ciphertext, and this can affect accuracy. Rescaling helps to manage this, but it needs to be done with attention to the impact on precision.</li><li><strong>Parameter Selection:</strong> The choice of parameters like polynomial degree and coefficient modulus can influence the achievable accuracy.</li><li><strong>Complexity of Computations:</strong> If multiplication is a part of a larger computation, other factors like the order of operations and the handling of intermediate results can also affect accuracy.</li></ol><p><strong>How many decimal points:</strong></p><p>The number of accurate decimal points achievable with CKKS can vary based on the factors mentioned above. In typical settings it might be in range of 10 to 20 decimal points, but this can vary widely depending on specific choices for scaling, parameters and overall computation.</p><p>Floating-point multiplication in CKKS is implemented using polynomial multiplication along with careful handling of scaling factors to represent floating-point numbers. The precision of the result depends on various factors, and achieving high accuracy may require careful design and analysis. CKKS provides a powerful capability to perform complex floating-point arithmetic on encrypted data, but it does so with an approximate, rather than exact, arithmetic that requires attention to numerical details.</p><p>Multiplication of encrypted floating-point numbers in CKKS scheme is a more complex operation than addition and subtraction. Here’s an overview of how it’s done with a focus on the conceptual details.</p><p><strong>Multiplication in CKKS:</strong></p><p>Given two floating-point numbers a and b, their product c is given by:</p><p>C = a.b</p><p>In CKKS, floating-point numbers are scaled by a large power of 2 and ecoded as polynomials. Let’s assume P(x) and Q(x) represent the encrypted scaled version of a and b, respectively.</p><p>The encrypted product is obtained by multiplying these polynomials and then performing a rescale operation:</p><p>R(x) = Rescale( P(x) . Q(x) )</p><p>The rescale operation is essential to manage the “scale” (i.e the large power of 2 by which numbers are multiplied before encryption) and keep it consistent.</p><p>Example, consider two floating-point numbers 3.5 and 2.25. Let’s say we are using a scale factor of 2⁴⁰ ( as is common in many CKKS implementations)</p><ol><li>Scale and Encrypt: Scale the numbers by 2⁴⁰.<br>a’ = 3.5 * 2⁴⁰<br>b’ = 2.25 * 2⁴⁰</li><li>Encode and Encrypt: Encode a’ and b’ as polynomials P(x) and Q(x) and encrypt them.</li><li>Multiply: Apply the rescale operation to manage the scale. <br>R’(x) = P(x) . Q(x)</li><li>Rescale: Apply the rescale operation to manage the scale: <br>R(x) = Rescale ( R’(x) )</li><li>Decrypt: Decrypt R(x) and divide by the scale factor to obtain the result: <br>3.5 * 2.25 = 7.875</li></ol><p><strong>Challenges:</strong> Multiplication in CKKS can lead to “noise” growth, which can affect the precision of the result. Proper parameter selection and careful management of the scale are essential to minimize this effect.</p><p>Multiplication in the CKKS scheme involves not only multiplying the encrypted polynomials but also managing the scale through a rescale operation. It’s a more complex process than addition or subtraction, requiring careful consideration of the scale and noise.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be8a5fe396c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How does subtraction works in CKKS ?]]></title>
            <link>https://medium.com/@jahanxb/how-does-subtraction-works-in-ckks-4366fee7be4d?source=rss-ffc096f79a5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4366fee7be4d</guid>
            <category><![CDATA[floating]]></category>
            <category><![CDATA[homomorphic-encryption]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[subtraction]]></category>
            <dc:creator><![CDATA[Jahanzeb]]></dc:creator>
            <pubDate>Tue, 29 Aug 2023 19:58:44 GMT</pubDate>
            <atom:updated>2023-08-29T19:58:44.402Z</atom:updated>
            <content:encoded><![CDATA[<h3>How does subtraction works in CKKS ?</h3><p>Subtraction in the CKKS encryption scheme works similarly to the addition, except that the corresponding components of the ciphertexts are subtracted from each other rather than added.</p><ol><li><strong>Plaintext Encoding:</strong> The real or complex numbers are encoded into plaintext polynomials, just as in addition.</li><li><strong>Encryption:</strong> These polynomials are then encrypted using the public key.</li><li><strong>Ciphertext Subtraction:</strong> To subtract two encrypted numbers, you subtract the corresponding ciphertexts component-wise. Mathematically, this means performing subtraction in the polynomial ring, modulo the chosen cyclotomic polynomial and coefficients modulus.<br>- Lets say C1 and C2 are two ciphertexts representing encrypted values m1 and m2, respectively.<br>- The subtraction of the ciphertexts is performed as Cresult = C1 — C2</li><li><strong>Noise Growth:</strong> Just like addition, subtraction also causes a small increase in the noise within the ciphertexts. But the noise growth in subtraction is also generally manageable, and there is no need for additional steps like rescaling for this operation.</li><li><strong>Decryption:</strong> You can decrypt the resulting ciphertext using the secret key, which will give you an approximate plaintext polynomial representing the difference between the original plaintext values.</li><li><strong>Decoding: </strong>Finally, you decode the resulting plaintext polynomial back into a real or complex number, reversing the original encoding step.</li></ol><p>Subtraction in CKKS is a straightforward operation directly corresponds to the subtraction of the underlying plaintext values. It leverages the same homomorphic properties as other operations in CKKS, allowing you to perform subtraction on encrypted data without needing to first decrypt it. Its computationally efficient and has a minimal impact on noise growth, making it a practical operation for many applications of CKKS.</p><p><strong>How does floating point subtraction works in CKKS and how much accurate decimal points it can Produce ?</strong></p><p>Floating-point subtraction in CKKS is very similar to floating-point addition, with the main difference being the arithmetic operation performed on the ciphertexts. Here’s an overview of how it works, along with considerations for accuracy:</p><p>Floating-Point Subtraction in CKKS:</p><ol><li><strong>Encoding:</strong> The floating point numbers are encoded into plaintext polynomials, scaled by a large factor, usually a power of 2, to represent the fractional part.</li><li><strong>Encryption:</strong> The plaintext polynomials are encrypted using the public key.</li><li><strong>Ciphertext Subtraction:</strong> Subtraction is performed by subtracting the corresponding ciphertexts component-wise. The encoded scaling ensures that the floating-point subtraction is carried out correctly.</li><li><strong>Decryption and Decoding:</strong> The resulting ciphertext is decrypted using the secret key, and the resulting plaintext polynomial is decoded back into a floating-point number.</li></ol><p><strong>Accuracy Considerations:</strong><br>The accuracy considerations for floating-point subtraction in CKKS are very similar to those for addition:</p><ol><li><strong>Scaling Factor:</strong> The Choice of scaling factor during encoding plays a key role in determining the precision.</li><li><strong>Noise:</strong> While subtraction itself doesn’t significantly increase noise, accumulated noise from prior operations, especially multiplications, can affect precision.</li><li><strong>Parameter Selection: </strong>Choosing appropriate parameters, such as the polynomial degree and coefficient modulus, influences accuracy.</li><li><strong>Rescaling and Leveling: </strong>Careful management of rescaling and leveling steps is crucial in more complex computations to maintain precision.</li></ol><p>How many Decimal Points:</p><p>The number of accurate decimal points you can achieve with CKKS depends on the factors mentioned above. Typically, it can be in range of 10 to 20 decimal points, depending on specific choices for scaling, parameters, and the complexity of the computations.</p><p>Floating-point subtraction in CKKS is achieved using a similar process to addition, with the subtraction operation applied to the corresponding ciphertexts. The precision of the results is influenced by various factors, including encoding, noise, parameter selection, and the complexity of the computations. Careful design and analysis maybe required to achieve the desired trade-offs between accuracy, efficiency, and security for a given application. The achieved accuracy in terms of decimal points is generally consistent with what can be achieved for addition, as the two operations are closely related in the context.</p><p>Math behind it is as of same as addition.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4366fee7be4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How does addition works in CKKS?]]></title>
            <link>https://medium.com/@jahanxb/how-does-addition-works-in-ckks-233d824d4cc7?source=rss-ffc096f79a5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/233d824d4cc7</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[addition]]></category>
            <category><![CDATA[floating]]></category>
            <category><![CDATA[homomorphic-encryption]]></category>
            <category><![CDATA[floating-points]]></category>
            <dc:creator><![CDATA[Jahanzeb]]></dc:creator>
            <pubDate>Tue, 29 Aug 2023 19:53:22 GMT</pubDate>
            <atom:updated>2023-08-29T19:53:22.884Z</atom:updated>
            <content:encoded><![CDATA[<p>In the CKKS encryption scheme, addition of encrypted values is relatively simple and works in a component-wise manner.</p><ol><li><strong>Plaintext Encoding:</strong> First, real or complex numbers are encoded into plaintext polynomials in a selected polynomial ring. This usually involves scaling by a large factor to ensure precision in the computation.</li><li><strong>Encryption: </strong>The plaintext polynomials are then encrypted using the public key to produce ciphertexts.</li><li><strong>Ciphertext Addition:</strong> To add two encrypted numbers, you simply add their corresponding ciphertexts component-wise. Mathematically, this means performing addition in the polynomial ring, modulo the chosen cyclotomic polynomial and coefficient modulus.<br>- Lets say C1 and C2 are two ciphertexts representing encrypted values m1 and m2, respectively. <br>- The addition of the ciphertexts is performed as: Cresult = C1 + C2</li><li><strong>Noise Growth: </strong>One of the important things to note is that the noise within the ciphertexts grows as operations are performed. Simple operations like addition cause a small increase in noise. However, this noise growth is generally manageable and doesn’t typically require additional steps like rescaling for addition alone.</li><li><strong>Decryption:</strong> To obtain the result of the addition, you decrypt the resulting ciphertext using the secret key. This will give you an approximate plaintext polynomial representing the sum of the original plaintext values.</li><li><strong>Decoding</strong>: Finally, you decode the resulting plaintext polynomial back into a real or complex number, reversing the original encoding step.</li></ol><p>The addition operation in CKKS is essentially a component-wise addition of ciphertexts, carried out in the chosen polynomial ring. This addition process leverages the homomorphic properties of the CKKS scheme, which allows arithmetic operations on ciphertexts to correspond to the same operations on the plaintexts they encrypt. It is one of the simplest and most efficient operations in CKKS, both in terms of computational complexity and its impact on noise growth.</p><p><strong>How does floating point addition works in CKKS and how much accurate decimal points it can produce ?</strong></p><p>The CKKS encryption scheme is specifically designed to handle approximate arithmetic on encrypted floating point numbers. Given below is the high-level overview of how floating-point addition works in CKKS, along with considerations for accuracy:</p><p>Floating-Point Addition in CKKS:</p><ol><li><strong>Encoding: </strong>The floating-point numbers are encoded into plaintext polynomials. This encoding involves scaling by a large factor, typically a power of 2, to represent the fractional part.</li><li><strong>Encryption: </strong>The plaintext polynomials are encrypted using the public key.</li><li><strong>Ciphertext Addition:</strong> Addition is performed by adding the corresponding ciphertexts component-wise. The encoded scaling ensures that the floating-point addition is carried out correctly.</li><li><strong>Decryption and Decoding:</strong> The resulting ciphertext is decrypted using the secret Key, and the resulting plaintext polynomial is decoded back into a floating-point number.</li></ol><p><strong>Accuracy Considerations: </strong><br>The accuracy of floating-point addition in CKKS depends on several factors:</p><ol><li><strong>Scaling Factor:</strong> The scaling factor used during encoding plays a significant role in determining the precision. A larger scaling factor will allow for more accurate representation of the factorial part but will also require larger parameters, affecting efficiency.</li><li><strong>Noise: </strong>CKKS is a noisy encryption scheme, meaning that every operation introduces some amount of noise. Over time, and especially after multiplicative operations, this noise can grow and impact accuracy. Addition itself doesn’t significantly increase noise, but accumulated noise from prior operations might affect precision.</li><li><strong>Parameter Selection:</strong> The choice of parameters, such as the polynomial degree and coefficient modulus, also impacts accuracy. Higher degrees and larger moduli typically provide greater accuracy but at the cost of increased computational complexity.</li><li><strong>Rescaling and Leveling:</strong> In more complex computations involving both addition and multiplication, rescaling steps must be carefully managed to ensure that the operations are compatible and that precision is maintained.</li></ol><p><strong>How many Decimal Points ?</strong></p><p>The number of accurate decimal points can vary depending on the factors mentioned above. In practice, its common to achieve somewhere between 10 to 20 decimal points of accuracy, but this can vary widely based on the specific choices made for scaling, parameters, and the complexity of the overall computation.</p><p>The Math Behind Addition:</p><p>Encoding floating-Point Numbers: Floating-point numbers are represented using a standard known as IEEE-754, which breaks down a number into a sign bit, exponent, and matissa. In CKKS, floating-point numbers are scaled by a large power of 2 to turn them to integers (or rational numbers in specific format), and then they are encoded into polynomial representations.</p><p>Addition in CKKS: Given two floating point numbers a and b, their sum c is given by:</p><p>C = a + b</p><p>In ckks, these numbers are first scaled and ecoded into polynomial P(x) and Q(x) representing a and b, respectively. The encrypted sum is then obtained by adding these polynomials:</p><p>R(x) = P(x) + Q(x)</p><p>Example, Lets say we have two floating-point numbers 3.5 and 5.5, they are scaled by 2⁴⁰</p><p>(Assuming that’s the scale factor used in CKKS context) and then encoded into polynomials:</p><p>P(x) representing 3.5 * 2⁴⁰</p><p>Q(x) representing 2.25 * 2⁴⁰</p><p>Their encrypted sum would be the polynomial R(x):</p><p>R(x) = P(x) + Q(x)</p><p>And the decrypted result would be:</p><p>3.5 + 2.25 = 5.75</p><p>Floating point addition in CKKS is achieved through careful encoding and scaling that allow the encrypted arithmetic to mirror the corresponding floating-point arithmetic. The precision of the results depends on various factors related to the encoding, noise management, and parameter selection. In practice, its often necessary to carefully balance accuracy with efficiency and security considerations, and detailed analysis or experimentation may be needed to achieve the desired trade-offs for a particular application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=233d824d4cc7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How does CKKS encryption Works ?]]></title>
            <link>https://medium.com/@jahanxb/how-does-ckks-encryption-works-3ca64270b8a0?source=rss-ffc096f79a5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ca64270b8a0</guid>
            <category><![CDATA[homomorphic-encryption]]></category>
            <category><![CDATA[cheong-sheng-hee]]></category>
            <category><![CDATA[arithmetic]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[floating]]></category>
            <dc:creator><![CDATA[Jahanzeb]]></dc:creator>
            <pubDate>Tue, 29 Aug 2023 19:47:27 GMT</pubDate>
            <atom:updated>2023-08-29T19:47:27.985Z</atom:updated>
            <content:encoded><![CDATA[<h3>How does CKKS encryption Works ?</h3><p>CKKS is a somewhat homomorphic encryption (SHE) scheme that allows computations to be performed on encrypted data without needing to decrypt it first.</p><p>Its especially designed for approximating computations on encrypted floating-point numbers, making it attractive for privacy-preserving numerical computations. Here’s an overview of how CKKS works:</p><ol><li><strong>Setup and Encoding:</strong></li><li><strong>Parameter Selection: </strong>Like many lattice-based encryption schemes, CKKS requires the selection of parameters, including a cyclotomic polynomial ring of degree n, and a modulus q, typically to be power of 2.<br> <strong>Encoding: </strong>Real or Complex numbers are encoded into plaintext polynomials in the chosen polynomial ring. This encoding process involves scaling by a large factor to allow approximations.</li><li><strong>Key Generation:</strong><br><strong>Secret Key:</strong> A random polynomial whose coefficients are small (e.g from a small integer range) is chosen as the secret Key.<br><strong>Public Key:</strong> The public Key is generated using the secret key, the chosen parameters, and some randomness, it can be used to encrypt messages.</li><li><strong>Encryption:</strong><br><strong>Encrypting:</strong> The plaintext polynomial is encrypted using the public key to create a ciphertext. Noise is added to the plaintext during encryption, enhancing security but also making the scheme approximate rather than exact.</li><li>Homomorphic Operations:<br><strong>Addition:</strong> Encrypted Numbers can be added together by adding the corresponding ciphertexts.<br><strong>Multiplication: </strong>Encrypted numbers can be multiplied by multiplying the corresponding ciphertexts and then performing a relinearization step to reduce the size and noise of the result.<br><strong>Rescaling:</strong> After performing an operation like multiplication, a rescaling step is typically performed to manage the noise and keep the ciphertext at the appropriate level.</li><li><strong>Decryption:<br>Decrypting: </strong>The secret key is used to decrypt the ciphertext and retrieve an approximate version of the original plaintext polynomial.<br><strong>Decoding:</strong> The approximate plaintext polynomial is decoded back into a real or complex number, reversing the encoding step performed initially.</li></ol><p><strong>Challenges and Limitations:</strong></p><ol><li><strong>Noise:</strong> The Noise in the system grows with each operation, and there is a limit to how many operations can be performed before the noise overwhelms the signal, rendering the decryption meaningless.</li><li><strong>Approximation: </strong>Because CKKS deals with approximations, errors can accumulate through computations.</li><li><strong>Efficiency: </strong>Performing homomorphic operations on encrypted data is more computationally intensive than performing the same operations on unencrypted data.</li></ol><p>CKKS has been an essential tool in enabling privacy-preserving computations, especially in fields like data analysis, machine learning, and medical research, where the need to perform computations on sensitive data is common. It offers a way to do this without compromising the privacy of the underlying data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ca64270b8a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Describe how the floating point Homomorphic Encryption actually works ?]]></title>
            <link>https://medium.com/@jahanxb/describe-how-the-floating-point-homomorphic-encryption-actually-works-afeaa14e1649?source=rss-ffc096f79a5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/afeaa14e1649</guid>
            <category><![CDATA[encryption-software]]></category>
            <category><![CDATA[floating]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[homomorphic-encryption]]></category>
            <category><![CDATA[floating-points]]></category>
            <dc:creator><![CDATA[Jahanzeb]]></dc:creator>
            <pubDate>Tue, 29 Aug 2023 19:42:22 GMT</pubDate>
            <atom:updated>2023-08-29T19:42:22.388Z</atom:updated>
            <content:encoded><![CDATA[<h3>Describe how the floating point Homomorphic Encryption actually works ?</h3><p>Homomorphic encryption (HE) enables computations on encrypted data without requiring access to the secret key. The CKKS (Cheon-Kim-Kim-Song) scheme is one of the prominent homomorphic encryption schemes specifically designed to handle floating-point numbers, allowing for approximate arithmetic over encrypted data.</p><p>How does it Works ?</p><ol><li><strong>Encoding: </strong>Floating-Point numbers are typically represented in the <strong>IEEE 754 format</strong>. In CKKS, these numbers are scaled by a large power of 2 ( called the scale) to transform them into integers or rational numbers with a specific format.</li><li><strong>Encryption: </strong>Once scaled and encoded, these numbers are encrypted using the CKKS scheme. This involves representing the numbers as polynomials and performing polynomial encryption, taking into account specific parameters like polynomial modulus degree and coefficient modulus bit sizes.</li><li><strong>Arithmetic Operations:</strong> Encrypted floating-point numbers can be subjected to various arithmetic operations like addition, subtraction, multiplication and division. These are performed through polynomial arithmetic, with special considerations to handle the scale and noise.</li><li><strong>Noise Management:</strong> Operations in CKKS introduce noise into encrypted data. The noise grows with computation, and if it becomes too large, it can prevent successful decryption. Parameters and operations must be chosen carefully to manage noise growth.</li><li><strong>Decryption:</strong> The decryption process involves reversing the encryption process, transforming the encrypted polynomial back to the scaler integer or rational number, and then dividing by the scale to recover the original floating-point number.</li><li><strong>Approximations:</strong> Since CKKS is designed for approximate arithmetic, some loss of precision can occur. The level of approximation depends on parameters like scale and polynomial modulus degree.</li></ol><p>Floating-Point Homomorphic encryption in CKKS allows for encrypted computations over real numbers. By scaling and encoding the numbers as polynomials, arithmetic operations can be performed in the encrypted domain, with considerations for managing scale and noise.</p><p>This approach has various applications in privacy-preserving computations, such as secure data analysis and privacy-preserving machine learning, where it’s essential to perform computations on sensitive data without exposing the actual values.</p><p><strong>What are the other Schemes being used in Homomorphic Encryption for Floating Point?</strong></p><p>Homomorphic encryption (HE) for floating point numbers is a complex task, and the CKKS scheme is specifically designed for this purpose. Other HE schemes are typically designed for integer arithmetic and logical operations, but they can be adapted to handle floating-point numbers using specific encoding techniques. Some of the popular HE schemes include:</p><ol><li><strong>BFV Scheme (B/FV): </strong>The BFV scheme supports integer arithmetic and can be adapted to handle floating-point numbers using fixed-point encoding. <br>It provides better noise management compared to CKKS but requires encoding/decoding techniques to work with floating-point numbers.</li><li><strong>BGN Scheme: </strong>the BGN scheme supports limited arithmetic operations. <br>It’s generally not used for full-fledged floating-point computations but can be adapted for specific tasks.</li><li><strong>Paillier Cryptosystem:</strong> Paillier is a probabilistic asymmetric algorithm that supports addition of encrypted data. <br>Although not specifically designed for floating-point arithmetic, it can be adapted using proper encoding techniques.</li><li><strong>ElGamal Cryptosystem:</strong> ElGamal encryption provides a way to perform certain homomorphic operations. <br>Like Paillier, it’s not inherently suited for floating-point numbers but can be adapted using appropriate encoding.</li><li><strong>NTS (Number Theoretic Transform) Schemes:</strong> Some newer HE schemes leverage number theoretic transforms, which can also be adapted for floating-point computations with careful encoding and scaling.</li><li><strong>Lattice-Based Schemes: </strong><br>Many homomorphic encryption schemes, including CKKS, are built on lattice-based cryptography. <br>Some custom lattice-based schemes could be designed to handle floating-point numbers, though they might not be as widely adopted or standarized.</li></ol><p>Its worth noting that adapting integer-based HE schemes to floating-point arithmetic typically involves trade-offs in terms of complexity, efficiency and precision. Floating-point numbers must be encoded as integers (e.g using fixed-point representation), and decoding must be applied after computation. This can introduce approximations and complexities in handling rounding, overflow and underflow.</p><p>In practice, if floating-point computations are the primary requirement, the CKKS scheme is typically preferred as its specifically designed to handle these types of numbers. Other schemes may require significant adaptation and careful parameter tuning to work efficiently with floating-point data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afeaa14e1649" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Homomorphic Encryption?]]></title>
            <link>https://medium.com/@jahanxb/what-is-homomorphic-encryption-ab35628c651e?source=rss-ffc096f79a5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab35628c651e</guid>
            <category><![CDATA[homomorphic-encryption]]></category>
            <category><![CDATA[encryption]]></category>
            <dc:creator><![CDATA[Jahanzeb]]></dc:creator>
            <pubDate>Tue, 29 Aug 2023 19:37:57 GMT</pubDate>
            <atom:updated>2023-08-29T19:37:57.788Z</atom:updated>
            <content:encoded><![CDATA[<p>Homomorphic Encryption is a form of encryption that allows computations to be carried out on ciphertexts, generating an encrypted result that, when decrypted, matches the result of the operations performed on the plaintext.</p><p>In other words, it allows for the execution of calculations on encrypted data without needing to first decrypt the data. This enables secure data processing, where the underlying information remains confidential.</p><p>Types of Homomorphic Encryption:</p><ol><li><strong>Partial Homomorphic Encryption (PHE)</strong>: It supports unlimited operations of a single type, such as addition or multiplication.</li><li><strong>Somewhat Homomorphic Encryption (SHE)</strong>: It allows limited combinations of addition and multiplication before the noise becomes too great to decrypt accurately.</li><li><strong>Fully Homomorphic Encryption (FHE)</strong>: It supports unlimited and mixed operations of both addition and multiplication.</li></ol><p><strong>Mathematical Overview:</strong></p><p>The core idea behind homomorphic encryption can be described mathematically as follow:</p><p>If you have two plaintexts p1 and p2, and you encrypt them using a homomorphic encryption scheme, you get:</p><p>C1 = Encrypt(p1)</p><p>C2 = Encrypt(p2)</p><p>With a homomorphic encryption scheme, you can compute an operation such as addition on the ciphertexts, and the result will be equivalent to performing the same operation on the plaintexts and then encrypting the result:</p><p>Encrypt(p1+p2) = c1+c2</p><p><strong>Applications:</strong></p><p>Homomorphic encryption has a wide array of applications, particularly in scenarios where privacy and security are paramount:</p><p><em>Secure Data Analysis:</em> Analysis on encrypted medical, financial, or personal data without exposing the actual data.</p><p><em>Privacy-Preserving Cloud Computing: </em>Enabling computations on encrypted data in the cloud, keeping data secure from the cloud provider.</p><p><em>Secure Voting Systems:</em> Conducting elections in a way that maintains confidentiality of the voter’s choices.</p><p>Encrypted Search: Searching through encrypted data without having to decrypt it.</p><p><strong>Challenges and Considerations:</strong></p><p><strong>Computational Overhead:</strong> Homomorphic encryption involves significant computational complexity, leading to higher computational costs and latency.</p><p><strong>Noise Management:</strong> Operations on encrypted data introduce noise, which must be managed to avoid compromising the accuracy of the computations.</p><p>Homomorphic Encryption is a powerful cryptographic tool that has the potential to revolutionize the way we handle and compute on sensitive data, making it possible to leverage cloud computing and data analytics without sacrificing privacy. The development and optimization of efficient homomorphic encryption schemes are active areas of research in cryptography.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab35628c651e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Federated Learning with PyTorch: Training a CNN Classifier on Fashion-MNIST Dataset]]></title>
            <link>https://medium.com/@jahanxb/federated-learning-with-pytorch-training-a-cnn-classifier-on-fashion-mnist-dataset-e190ad9fda4e?source=rss-ffc096f79a5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e190ad9fda4e</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[fashion-mnist]]></category>
            <category><![CDATA[federated-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[pytorch]]></category>
            <dc:creator><![CDATA[Jahanzeb]]></dc:creator>
            <pubDate>Sun, 02 Apr 2023 00:35:25 GMT</pubDate>
            <atom:updated>2023-04-02T00:35:25.169Z</atom:updated>
            <content:encoded><![CDATA[<p>Federated Learning is a distributed machine learning technique that allows multiple parties to collaboratively train a machine learning model without sharing their data with each other. In this article, we will learn how to train a CNN classifier on the Fashion-MNIST dataset using PyTorch and Federated Learning.</p><h4>Step 1: Loading and Preprocessing the Data</h4><p>First, let’s load and preprocess the Fashion-MNIST dataset. We will use the same preprocessing steps as in the previous article. However, since we will be using Federated Learning, we need to split the data into multiple parties. For simplicity, we will split the data into two parties, but you can split it into as many parties as you like.</p><pre>import torch<br>import torchvision<br>import torchvision.transforms as transforms<br><br>transform = transforms.Compose(<br>    [transforms.ToTensor(),<br>     transforms.Normalize((0.5,), (0.5,))])<br><br>trainset = torchvision.datasets.FashionMNIST(root=&#39;./data&#39;, train=True,<br>                                        download=True, transform=transform)<br>testset = torchvision.datasets.FashionMNIST(root=&#39;./data&#39;, train=False,<br>                                       download=True, transform=transform)<br><br># Split the data into two parties<br>trainset1, trainset2 = torch.utils.data.random_split(trainset, [30000, 30000])<br>testset1, testset2 = torch.utils.data.random_split(testset, [5000, 5000])</pre><p>In the code above, we load and preprocess the Fashion-MNIST dataset using the same preprocessing steps as before. We then split the dataset into two parties, each with 30,000 training samples and 5,000 test samples.</p><h4>Step 2: Defining the Model</h4><p>Next, we define the CNN classifier model that we will use for this task. We will use the same model as in the previous article.</p><pre>import torch.nn as nn<br>import torch.nn.functional as F<br><br>class Net(nn.Module):<br>    def __init__(self):<br>        super(Net, self).__init__()<br>        self.conv1 = nn.Conv2d(1, 32, 5)<br>        self.pool = nn.MaxPool2d(2, 2)<br>        self.conv2 = nn.Conv2d(32, 64, 5)<br>        self.fc1 = nn.Linear(1024, 128)<br>        self.fc2 = nn.Linear(128, 10)<br><br>    def forward(self, x):<br>        x = self.pool(F.relu(self.conv1(x)))<br>        x = self.pool(F.relu(self.conv2(x)))<br>        x = x.view(-1, 1024)<br>        x = F.relu(self.fc1(x))<br>        x = self.fc2(x)<br>        return x<br><br>model = Net()</pre><p>In the code above, we define the Net class, which inherits from the nn.Module class in PyTorch. The Net class defines the CNN architecture for the classifier, which consists of two convolutional layers followed by two fully connected layers.</p><h4>Step 3: Federated Learning</h4><p>Now, we are ready to perform Federated Learning. We will use PyTorch’s FederatedDataLoader and FederatedOptimizer classes to perform Federated Learning.</p><pre>import syft as sy<br>hook = sy.TorchHook(torch)<br><br># Define the parties<br>bob = sy.VirtualWorker(hook, id=&quot;bob&quot;)<br>alice = sy.VirtualWorker(hook, id=&quot;alice&quot;)<br><br># Send the datasets to the parties<br>federated_train_loader = sy.FederatedDataLoader(<br>    [trainset1.federate((bob, alice)), trainset2.federate((bob, alice))],<br>batch_size=64, shuffle=True)<br><br>federated_test_loader = sy.FederatedDataLoader(<br>[testset1.federate((bob, alice)), testset2.federate((bob, alice))],<br>batch_size=64, shuffle=False)</pre><p>In the code above, we first import the syft library and create a hook for PyTorch to enable Federated Learning. We then define two virtual workers, bob and alice, which represent the two parties in our Federated Learning setting.</p><p>We use the federate() method to split the datasets and send them to the parties. We then use the FederatedDataLoader class to create a Federated DataLoader for both the training and test sets.</p><h4>Define the FederatedOptimizer</h4><pre>optimizer = torch.optim.Adam(model.parameters(), lr=0.001)<br>criterion = nn.CrossEntropyLoss()<br>federated_optimizer = sy.FederatedOptimizer(optimizer, [bob, alice])</pre><p>we defined the FederatedOptimizer using the FederatedOptimizer class, which takes the global optimizer and the list of workers as input. We train the model using Federated Learning for 10 epochs and evaluate the model on the test set.</p><h4>Train the model using Federated Learning</h4><pre>epochs = 10<br>for epoch in range(epochs):<br>    running_loss = 0.0<br>    for batch_idx, (data, target) in enumerate(federated_train_loader):<br>        data, target = data.to(device), target.to(device)<br>        federated_optimizer.zero_grad()<br>        output = model(data)<br>        loss = criterion(output, target)<br>        loss.backward()<br>        federated_optimizer.step()<br>        running_loss += loss.item()<br>    print(&#39;Epoch: %d, Loss: %.3f&#39; % <br>        (epoch + 1, running_loss / len(federated_train_loader)))</pre><h4>Evaluate the model on the test set</h4><pre>model.eval()<br>test_loss = 0<br>correct = 0<br><br>with torch.no_grad():<br>    for data, target in federated_test_loader:<br>        data, target = data.to(device), target.to(device)<br>        output = model(data)<br>        test_loss += criterion(output, target).item() * data.size(0)<br>        pred = output.argmax(1, keepdim=True)<br>        correct += pred.eq(target.view_as(pred)).sum().item()<br><br>test_loss /= len(federated_test_loader.dataset)<br>accuracy = 100. * correct / len(federated_test_loader.dataset)<br><br>print(&#39;Test set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n&#39;.format(<br>    test_loss, correct, len(federated_test_loader.dataset), accuracy))</pre><h4>Send the model to Alice and Bob</h4><pre>model_ptr = model.send(bob, alice)</pre><h4>Get the aggregated model back</h4><pre>agg_model_ptr = model_ptr.average_precision()</pre><h4>Move the model back to the local machine</h4><pre>agg_model = agg_model_ptr.get()</pre><h4>Test the aggregated model on the test set</h4><pre>agg_model.eval()<br>test_loss = 0<br>correct = 0<br><br>with torch.no_grad():<br>    for data, target in testloader:<br>        data, target = data.to(device), target.to(device)<br>        output = agg_model(data)<br>        test_loss += criterion(output, target).item() * data.size(0)<br>        pred = output.argmax(1, keepdim=True)<br>        correct += pred.eq(target.view_as(pred)).sum().item()<br><br>test_loss /= len(testloader.dataset)<br>accuracy = 100. * correct / len(testloader.dataset)<br><br>print(&#39;Aggregated model: Test set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n&#39;.format(<br>    test_loss, correct, len(testloader.dataset), accuracy))</pre><p>In the code above, we first define the FederatedDataLoader for the training and test sets, as we did in the previous example. We then define the FederatedOptimizer and train the model using Federated Learning for 10 epochs.</p><p>After training the model, we send the model to bob and alice using the send() method, which returns a pointer to the remote model. We then use the average_precision() method to average the models and get the aggregated model back. Finally, we test the aggregated model on the test set and print the accuracy.</p><h4>Step 4: Conclusion</h4><p>In this article, we learned how to perform Federated Learning using PyTorch on the Fashion-MNIST dataset. We split the data into two parties and trained a CNN classifier using the FederatedDataLoader and FederatedOptimizer classes in PyTorch. Federated Learning is a powerful technique that enables collaborative machine learning without sharing data, and PyTorch provides excellent support for Federated Learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e190ad9fda4e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Train a CNN Classifier on Fashion-MNIST Dataset]]></title>
            <link>https://medium.com/@jahanxb/how-to-train-a-cnn-classifier-on-fashion-mnist-dataset-5a274bd671ad?source=rss-ffc096f79a5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a274bd671ad</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[fashion-mnist]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Jahanzeb]]></dc:creator>
            <pubDate>Sun, 02 Apr 2023 00:18:35 GMT</pubDate>
            <atom:updated>2023-04-02T00:18:35.925Z</atom:updated>
            <content:encoded><![CDATA[<p>Fashion-MNIST is a popular benchmark dataset for image classification, widely used in the computer vision community. In this article, we will walk through the steps to train a convolutional neural network (CNN) classifier on the Fashion-MNIST dataset using PyTorch.</p><p>First, let’s start with some background information about the Fashion-MNIST dataset. It is a dataset of 70,000 grayscale images of 28x28 pixels in size, representing 10 different clothing categories. Each image is labeled with one of the categories: T-shirt/top, Trouser, Pullover, Dress, Coat, Sandal, Shirt, Sneaker, Bag, and Ankle boot. The dataset is split into 60,000 training images and 10,000 test images.</p><p>To get started, make sure you have PyTorch installed. If not, you can install it by following the instructions on the official website.</p><p>Next, we need to load the dataset into our Python environment. PyTorch has a built-in function to load the Fashion-MNIST dataset, which we can use as follows:</p><pre>import torch<br>import torchvision<br><br>transform = torchvision.transforms.ToTensor()<br><br>train_dataset = torchvision.datasets.FashionMNIST(root=&#39;./data&#39;, train=True, transform=transform, download=True)<br>test_dataset = torchvision.datasets.FashionMNIST(root=&#39;./data&#39;, train=False, transform=transform, download=True)</pre><p>In the code above, we create a transform that converts the input images to PyTorch tensors. Then, we load the training and test sets into variables train_dataset and test_dataset, respectively.</p><p>Now, let’s define our CNN model. We will create a simple architecture with two convolutional layers, each followed by a max-pooling layer, and two fully connected (dense) layers. The output of the last layer will have 10 nodes, one for each clothing category.</p><pre>class CNNModel(torch.nn.Module):<br>    def __init__(self):<br>        super(CNNModel, self).__init__()<br>        self.conv1 = torch.nn.Conv2d(1, 32, kernel_size=3, padding=1)<br>        self.conv2 = torch.nn.Conv2d(32, 64, kernel_size=3, padding=1)<br>        self.pool = torch.nn.MaxPool2d(kernel_size=2, stride=2)<br>        self.fc1 = torch.nn.Linear(64*7*7, 128)<br>        self.fc2 = torch.nn.Linear(128, 10)<br><br>    def forward(self, x):<br>        x = torch.nn.functional.relu(self.conv1(x))<br>        x = self.pool(x)<br>        x = torch.nn.functional.relu(self.conv2(x))<br>        x = self.pool(x)<br>        x = x.view(-1, 64*7*7)<br>        x = torch.nn.functional.relu(self.fc1(x))<br>        x = self.fc2(x)<br>        return x</pre><p>In the code above, we define our model as a PyTorch module. In the constructor, we define the layers of our model. In the forward method, we specify the order in which the input passes through the layers.</p><p>We can now create an instance of our model and define the loss function and optimizer.</p><pre>model = CNNModel()<br>criterion = torch.nn.CrossEntropyLoss()<br>optimizer = torch.optim.Adam(model.parameters(), lr=0.001)</pre><p>In the code above, we create an instance of our model, define the cross-entropy loss function, and use the Adam optimizer with a learning rate of 0.001.</p><p>Finally, we can train our model using PyTorch’s built-in DataLoader and train functions.</p><pre>train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=64, shuffle=True)<br>test_loader = torch.utils.data.DataLoader(test_dataset, batch_size=64, shuffle=False)<br><br>num_epochs = 10<br>for epoch in range(num_epochs):<br>    for i, (images, labels) in enumerate(train_loader):<br>        optimizer.zero_grad()<br>        outputs = model(images)<br>        loss = criterion(outputs, labels)<br>        loss.backward()<br>        optimizer.step()<br>        <br>        if (i+1) % 100 == 0:<br>            print (&#39;Epoch [{}/{}], Step [{}/{}], Loss: {:.4f}&#39;.format(epoch+1, num_epochs, i+1, len(train_loader), loss.item()))</pre><p>In the code above, we use the DataLoader to load batches of images and labels. We then loop over the batches and perform forward and backward passes through the model, computing the loss and updating the model parameters using the optimizer.</p><p>After training, we can evaluate our model on the test set and print the accuracy.</p><pre>model.eval()<br>with torch.no_grad():<br>    correct = 0<br>    total = 0<br>    for images, labels in test_loader:<br>        outputs = model(images)<br>        _, predicted = torch.max(outputs.data, 1)<br>        total += labels.size(0)<br>        correct += (predicted == labels).sum().item()<br><br>    print(&#39;Accuracy of the network on the 10000 test images: {} %&#39;.format(100 * correct / total))</pre><p>In the code above, we set the model to evaluation mode and use the no_grad context to disable gradient computation. We then loop over the test set and compute the predicted labels for each image. We compare the predicted labels with the ground truth labels and count the number of correct predictions.</p><p>That’s it! We have trained a CNN classifier on the Fashion-MNIST dataset using PyTorch. You can try changing the architecture of the model, the optimizer, or the hyperparameters to see if you can improve the accuracy. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a274bd671ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>