# ML using OpenFHE: Logistic regression training examples are now available

**URL:** <https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476>\
**Category:** FHE Use Cases\
**Created:** [April 19, 2023, 4:29pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476 "2023-04-19T16:29:21Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [April 19, 2023, 4:29pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/1 "2023-04-19T16:29:21Z")

</div>

Check out [GitHub - openfheorg/openfhe-logreg-training-examples: Examples of Logistic Regression Training using Nesterov Accelerated Gradient Descent](https://github.com/openfheorg/openfhe-logreg-training-examples), which shows examples of logistic regression training using the Nesterov Accelerated Gradient Descent method. The examples were developed using CKKS in OpenFHE. @iquah was the main developer.

---

<div class="post-metadata">

**Author:** ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)\
**Post date:** [April 27, 2023, 3:25pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/2 "2023-04-27T15:25:13Z")

</div>

Thank you for sharing! Definitely needed that 🙂

Edit: I exploit this post to ask: in [this](https://github.com/openfheorg/openfhe-logreg-training-examples/blob/1eb0545b09f2f5a1eceef2ef8178a21a08ba422e/lr_nag.cpp#L201) line, the depth is increased by one because of the `DCRTPolyImpl's towers are not initialized` issue. Is this something that will be fixed in the future, or bootstrapping can’t simply be performed at the last level?

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [April 28, 2023, 9:03pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/3 "2023-04-28T21:03:04Z")

</div>

Thank you for reporting this. The comment can be improved. In 64-bit CKKS bootstrapping, we need one extra level (for an extra scaling). We will fix the comment.

---

<div class="post-metadata">

**Author:** ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)\
**Post date:** [April 28, 2023, 9:36pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/4 "2023-04-28T21:36:17Z")

</div>

This happens in general in 64 bits bootstrapping or just in case of 2 iterations?

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [April 28, 2023, 10:20pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/5 "2023-04-28T22:20:36Z")

</div>

This is specific to the use of 2 iterations for the 64-bit case. This requirement is illustrated in [openfhe-development/iterative-ckks-bootstrapping.cpp at v1.0.3 · openfheorg/openfhe-development · GitHub](https://github.com/openfheorg/openfhe-development/blob/v1.0.3/src/pke/examples/iterative-ckks-bootstrapping.cpp) (search for numIterations).

---

<div class="post-metadata">

**Author:** ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)\
**Post date:** [May 11, 2023, 9:31am UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/6 "2023-05-11T09:31:56Z")

</div>

Hello there, another question here 😃

[In this line](https://github.com/openfheorg/openfhe-logreg-training-examples/blob/1eb0545b09f2f5a1eceef2ef8178a21a08ba422e/lr_nag.cpp#LL193C5-L193C11), you justify the use of a level budget equal to {2, 2}, can you please elaborate a little bit more? Thank you 🙏

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [May 11, 2023, 7:51pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/7 "2023-05-11T19:51:55Z")

</div>

`Level budget = {e,d}` controls the computational complexity of the homomorphic encoding and decoding steps in CKKS bootstrapping, both are homomorphic evaluations of linear transforms. A higher budget allows faster computation of these steps at the expense of using a deeper circuit (consuming more levels). On the other hand, lower budget would be slower but it uses a shallow circuit.

Recommended values, found experimentally, are `e` or `d = {1,2,3, or 4}` (they do not need to be equal). You can run a few experiments to find the best configuration for you.

---

<div class="post-metadata">

**Author:** ![chayma](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@chayma](https://openfhe.discourse.group/u/chayma)\
**Post date:** [May 12, 2023, 5:25pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/8 "2023-05-12T17:25:28Z")

</div>

![image](https://canada1.discourse-cdn.com/flex031/uploads/openfhe/original/1X/60a9c1f9109beb402c8765d998db678dd5e9993a.png)  
Hello,  
In the data directory, we not only have “pvalue.txt” and “result.txt” files but also 7 other files. Could you please provide more information about those files and their purpose?

---

<div class="post-metadata">

**Author:** ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)\
**Post date:** [May 12, 2023, 7:57pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/9 "2023-05-12T19:57:18Z")

</div>

That seems to be for the [genomic examples](https://github.com/openfheorg/openfhe-genomic-examples/tree/main/data) instead of using the Logistic Regression one

---

<div class="post-metadata">

**Author:** ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)\
**Post date:** [May 15, 2023, 10:03am UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/10 "2023-05-15T10:03:17Z")

</div>

Thank you for your answer. With recommended values you mean values that have a good ratio between circuit depth and complexity reduction for bootstrap?

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [May 15, 2023, 1:46pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/11 "2023-05-15T13:46:42Z")

</div>

Yes, going higher than four consumes more levels.

---

<div class="post-metadata">

**Author:** ![chayma](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@chayma](https://openfhe.discourse.group/u/chayma)\
**Post date:** [June 8, 2023, 6:38am UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/13 "2023-06-08T06:38:36Z")

</div>

Hello  
I have built the logistic regression example " **openfhe-logreg-training-examples**".In lr\_nag, when I disable bootstrapping , it works well, but when I enable it, I get a “killed” message. Do you have any recommendations about the parameters? Which ones should I modify and what values should I choose?

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [June 8, 2023, 2:54pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/14 "2023-06-08T14:54:17Z")

</div>

Can you provide more information about the error message? I suspect you may not have enough memory to hold the evaluation keys. How much RAM does your machine have?

---

<div class="post-metadata">

**Author:** ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)\
**Post date:** [June 8, 2023, 2:56pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/15 "2023-06-08T14:56:37Z")

</div>

The examples should work out of the box. In addition to what @Caesar mentioned, are you running in 64 or 128 bit mode?

---

<div class="post-metadata">

**Author:** ![chayma](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@chayma](https://openfhe.discourse.group/u/chayma)\
**Post date:** [June 8, 2023, 3:40pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/16 "2023-06-08T15:40:43Z")

</div>

I am running it in 64 bits mode

---

<div class="post-metadata">

**Author:** ![chayma](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@chayma](https://openfhe.discourse.group/u/chayma)\
**Post date:** [June 8, 2023, 4:13pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/17 "2023-06-08T16:13:04Z")

</div>

I have 12GB of RAM, I think so, but I don’t know how to configure the parameters to run the code on my machine. I’ve tried some values, but I always encounter the same problems.

---

<div class="post-metadata">

**Author:** ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)\
**Post date:** [June 8, 2023, 5:35pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/18 "2023-06-08T17:35:18Z")

</div>

I’m not currently at my desktop but one thing you can use to test if the issue is with how much RAM your machine has is to drop the ring size (and the number of data points you read). 2\<\<16 perhaps?

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [June 9, 2023, 11:13pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/19 "2023-06-09T23:13:26Z")

</div>

12GB may not be enough. 32GB should be safe. Also please compile using `NATIVE_SIZE=64`, which should be by default - most likely this is what you are already using. `NATIVE\_SIZE=128 will take twice more memory.

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [June 9, 2023, 11:14pm UTC](https://openfhe.discourse.group/t/ml-using-openfhe-logistic-regression-training-examples-are-now-available/476/20 "2023-06-09T23:14:37Z")

</div>

Trying a twice smaller ring dimension, as suggested by @iquah, will also help.
