Semi-Parallel logistic regression for GWAS on encrypted data

Background The sharing of biomedical data is crucial to enable scientific discoveries across institutions and improve health care. For example, genome-wide association studies (GWAS) based on a large number of samples can identify disease-causing genetic variants. The privacy concern, however, has become a major hurdle for data management and utilization. Homomorphic encryption is one of the most powerful cryptographic primitives which can address the privacy and security issues. It supports the computation on encrypted data, so that we can aggregate data and perform an arbitrary computation on an untrusted cloud environment without the leakage of sensitive information. Methods This paper presents a secure outsourcing solution to assess logistic regression models for quantitative traits to test their associations with genotypes. We adapt the semi-parallel training method by Sikorska et al., which builds a logistic regression model for covariates, followed by one-step parallelizable regressions on all individual single nucleotide polymorphisms (SNPs). In addition, we modify our underlying approximate homomorphic encryption scheme for performance improvement. Results We evaluated the performance of our solution through experiments on real-world dataset. It achieves the best performance of homomorphic encryption system for GWAS analysis in terms of both complexity and accuracy. For example, given a dataset consisting of 245 samples, each of which has 10643 SNPs and 3 covariates, our algorithm takes about 43 seconds to perform logistic regression based genome wide association analysis over encryption. Conclusions We demonstrate the feasibility and scalability of our solution.


Background
Since National Institutes of Health (NIH) released the Gemonic Data Sharing policy allowing the use of cloud computing services for storage and analysis of controlledaccess data [1], we are getting more challenge to ensure security and privacy of data in cloud computing systems. In the United States, the Health Insurance Portability and Accountability Act regulates medical care data sharing [2]. A community effort has been made to protect

Summary of results
In this work, we provide a solution for the second track of iDASH 2018 competition, which aims to develop a method for outsourcing computation of Genome Wide Association Studies (GWAS) on homomorphically encrypted data. We propose a practical protocol to assess logistic regression model to compute p-values of different single nucleotide polymorphisms (SNPs). We investigate the association of genotypes and phenotypes by adjusting the models on the basis of covariates. The results will be used for identifying genetic variants that are statistically correlated with phenotypes of interest.
One year ago, participants of the third task in iDASH 2017 competition were challenged to train a single logistic regression model on encrypted data. Although significant performance improvements over existing solutions have been demonstrated [7,8], it is still computationally intensive to perform logistic regression based GWAS. A straightforward implementation would require building one model for each SNP, incurring a high performance overhead of secure computation. This motivates the use of the semi-parallel algorithm, which was previously discussed in [9,10]. Following the approach, our algorithm proceeds in two steps over encrypted data: (1) construct a logistic regression model by applying the gradient descent method of [7] while taking only the covariates into account, (2) compute the regression parameters of logistic regression corresponding to SNPs with one additional update of Newton's method. The model in the first step can be computed very efficiently and can be used for all SNPs in the subsequent step. In the second step, we apply various techniques to enable computing the logistic regression updates for all SNPs in many parallel sub-steps. This approach enables us to obtain logistic regression based models for thousands of SNPs all in one.
Our solution is based on a homomorphic scheme by Cheon et al. [11] with support for approximate fixed-point arithmetic over the real numbers. Recently, a significant performance improvement was made in [8] based on the Residue Number System (RNS). The authors modified homomorphic operations so that they do not require any expensive RNS conversions. In this paper, we propose another RNS variant of approximate HE scheme which has some advantages for this task. Specifically, we adapt a different key-switching method which is a core operation in homomorphic multiplication or permutation. The earlier studies [8,11] were based on the key-switching technique of [12] which introduces a special modulus. A special modulus had approximately the same bit-size as a ciphertext modulus to reduce the noise of keyswitching procedure, but we observed that it is not the best option when the depth of an HE scheme is small. Instead, we combine the special modulus technique with RNS-friendly decomposition method [13]. As a result, we could minimize the parameter and thereby improve the performance while guaranteeing the same security level. We further leverage efficient packing techniques and parallelization approaches to reduce the storage requirement and running time.

Related works
There are a number of recent research articles on HEbased machine learning applications. Kim et al. presented the first secure outsourcing method to train a logistic regression model on encrypted data [14] and the followup showed remarkably good performance with real data [7,8]. For example, the training of a logistic regression model took about 3.6 minutes on encrypted data consisting of 1579 samples and 18 features. A slightly different approach is taken in [15], where the authors use Gentry's bootstrapping technique in fully homomorphic encryption, so that their solution can run for an arbitrary number of iterations of gradient descent algorithm.

Methods
The binary logarithm will be simply denoted by log(·). We denote vectors in bold, e.g. a, and matrices in uppercase bold, e.g. A. For an n × m matrix A, we use A i to denote the i-th row of A, and a j the j-th column of A. For a d 1 × d matrix A 1 and a d 2 × d matrix A 2 , (A 1 ; A 2 ) denotes the (d 1 + d 2 ) × d matrix obtained by concatenating two matrices in a vertical direction. If two matrices A 1 and A 2 have the same number of rows, (A 1 |A 2 ) denotes a matrix formed by horizontal concatenation. We let λ denote the security parameter throughout the paper: all known valid attacks against the cryptographic scheme under scope should take (2 λ ) bit operations.

Logistic regression
Logistic regression is a widely used in statistical model when the response variable is categorical with two possible outcomes [16]. In particular, it is very popular in biomedical informatics research and serve as the foundation of many risk calculators [17][18][19].
Let the observed phenotype be given as a vector y ∈ {±1} n of length n, the states of p many SNPs as the n × p matrix S, and the states of k many covariates as the n × k matrix X. Suppose that an intercept is included in the matrix of covariates, that is, X contains a column of ones. For convenience, let u i = (X i , s ij ) ∈ R k+1 for i = 1, . . . , n. For each j ∈[ p], logistic regression aims to find an optimal vector β ∈ R k+1 which maximizes the ) is the sigmoid function, or equivalently minimizes the loss function, defined as the negative log-likelihood: Note that β = (β X |β j ) depends on the index j, and we are particularly interested in the last component β j that corresponds to the j-th SNP.
There is no closed form formula for the regression coefficients that minimizes the loss function. Instead, we employ an iterative process: we begin with some initial guess for the parameters and then repeatedly update them to make the loss smaller until the process converges. Specifically, the gradient descent (GD) takes a step in the direction of the steepest decrease of L. The method of GD can face a problem of zig-zagging along a local optima and this behavior of the method becomes typical if it increases the number of variables of an objective function. We can employ Nesterov's accelerated gradient [20] to address this phenomenon, which uses moving average on the update vector and evaluates the gradient at this looked-ahead position.

Newton's method
We can alternatively use Newton algorithm to estimate parameters [21]. It can be achieved by calculating the first and the second derivatives of the loss function, followed by the update: ; then p i represents the probability of success for each sample. We see that ∇ β L(β) = U T (y − p) and ∇ 2 β L(β) = −U T WU, where U is an n × (k + 1) regressor matrix whose i-th row contains the variables u i , p = (p i ) n i=1 is a column vector of the estimated probabilities p i , and W is a diagonal weighting matrix with elements w i = p i (1 − p i ). Then the above update formula can be rewritten as Here, the vector z is known as the working response. This method is also called Iteratively Reweighted Least Squares. More details can be found in [21]. On the other hand, the Fisher information U T WU can be partitioned into a block form: where A = X T WX, s j = (s ij ) n i=1 is a column vector of all samples of the j-th SNP, b = X T Ws j , and c = s T j Ws j . Then the inverse of U T WU is where t = c − b T A −1 b. Therefore, the estimated SNP effect β j and the variance for the estimation are computed by where adj(A) denotes the adjugate matrix and |A| the determinant of A.

Full RNS variant of HEAAN, revisited
We apply the full RNS variant of the HEAAN scheme [11], called RNS-HEAAN [8], for efficient arithmetic over the real numbers. In addition, we modify some algorithms to meet our goals. The previous RNS-HEAAN scheme uses some approximate modulus switching algorithms for the key-switching procedure. The evaluation key should have a much larger modulus compared to encrypted data due to multiplicative noise. In this work, we developed and implemented a new key-switching algorithm which provides a trade-off between complexity and parameter. Our new key-switching process requires more Number Theoretic Transformation (NTT) conversions, but the HE parameters such as the ring dimension N can be reduced while keeping the same security level. In particular, our method is more efficient than the previous one when the depth of a circuit to be evaluated is small.
The following is a simple description of RNS-HEAAN based on the ring learning with errors (RLWE) problem. Let R = Z[ X] /(X N + 1) be a cyclotomic ring for a powerof-two integer N. An ordinary ciphertext of RNS-HEAAN can be represented as a linear polynomial c(Y ) = c 0 +c 1 ·Y over the ring R Q where Q denotes the ciphertext modulus and R Q = R (mod Q) is the residue ring modulo Q.
• Setup(q, L, η; 1 λ ). Given a base integer module q, a maximum level L of computation, a bit precision η, and a security parameter λ, the Setup algorithm generates the following parameters: -Choose a basis D = {p 0 , q 0 , q 1 , . . . , q L } such that -Choose a power-of-two integer N.
-Choose a secret key distribution χ key , an encryption key distribution χ enc , and an error distribution χ err over R.
We always use the RNS form with respect to the basis {p 0 , q 0 , . . . , q } (or its sub-basis) to represent polynomials in our scheme. For example, an element a(X) of R Q is identified with the tuple (a 0 , a 1 , . . . , a ) ∈ i=0 R q i where a i = a (mod q i ). We point out that all algorithms in our scheme are RNS-friendly, so that we do not have to perform any RNS conversions.
The main difference of our scheme from previous work [8] is that the key-switching procedure is based on both the decomposition and modulus raising techniques. The use of decomposition allows us to use a smaller parameter, but its complexity may be increased when the level of HE scheme is large. However, we realize that the GWAS analysis does not require a huge depth, so this new keyswitching technique is beneficial to obtain a better performance in this specific application. The generation of switching key and key-switching algorithms are described as follows.
• KSGen(s 1 , s 2 ). Given two secret polynomials s 1 , , and then return the ciphertext ct = (c 0 , 0) + p −1 0 ·ct (mod Q ). The idea of key-switching procedure is used to relinearize a ciphertext in homomorphic multiplication algorithm below. All other algorithms including key generation, encryption and decryption are exactly same as the previous RNS-based scheme.
-Sample s ← χ key and set the secret key as sk = (1, s).
-Sample a ← U(R Q L ) and e ← χ err . Set the public key pk as pk -Set the evaluation key as evk ← KSGen(s 2 , s).
• Mult evk (ct, ct ). For two ciphertexts ct = (c 0 , c 1 ) and . Finally, RNS-HEAAN provides the rescaling operation to round messages over encryption, thereby enabling to control the magnitude of messages during computation.
• ReScale(ct). For given ct ∈ R 2 Q , return the cipher- It is a common practice to rescale the encrypted message after each multiplication as we round-off the significant digits after multiplication in plain fixed/floating point computation. In the next section, we assume that the rescaling procedure is included in homomorphic multiplications for simpler description, but a rigorous analysis about level consumption will be provided later in the parameter setting section.
As in the original HEAAN scheme, the native plaintext space can be understood as an N/2-dimensional complex vector space (each vector component is called a plaintext slot). Addition and multiplication in R correspond to component-wise addition and multiplication on plaintext slots. Furthermore, it provides an operation that shifts the plaintext vector over encryption. For a ciphertext ct encrypting a plaintext vector (m 1 , . . . , m ) ∈ R , we could obtain an encryption of a shifted vector (m r+1 , . . . , m , m 1 , . . . , m r ). Let us denote such operation by Rot(ct; r). For more detail, we refer the reader to [8]. In the rest of this paper, we let N 2 = N/2 and denote by E(·) the encryption function for convenience.

Database encoding
As noted before, the learning data are recorded into an n × k matrix X of covariates, an n × p binary matrix S = (s ij ) of all the SNP data, and an n-dimensional binary column vector y of the dependent variable. In large-scale GWAS, the number of parameters of SNPs, p can be in the thousands, so we split the SNP data into several N 2dimensional vectors, encrypt them, and send the resulting ciphertexts to the server. For simplicity, we assume in the following discussion that each row of S is encrypted into a single ciphertext. More specifically, for 1 ≤ i ≤ n and As mentioned before, we add a column of ones to X to allow for an intercept in the regression; that is, we assume x i1 = 1 for all 1 ≤ i ≤ n. So, when = 1, the ciphertext E(x i1 S i ) encrypts exactly the i-th SNP sample.
Next, consider the matrix y T X ∈ R n×k defined as y n x n1 y n x n2 · · · y n x nk For simplicity, we assume that n and k are power-of-two integers satisfying log n + log k ≤ log(N 2 ). Kim et al. [7] suggested an efficient encoding map to encode the whole matrix y T X in a single ciphertext in a row-by-row manner. Specifically, we will identify this matrix with a vector in R n·k , that is, Similarly, we identify the matrix X with a vector in R n·k as follows: For an efficient implementation, we can make N 2 /(k · n) copies of each component of y T X and X to encode them into fully packed plaintext slots. For example, we can generate the encryption of y T X as where y i X (N 2 /(k·n)) i denotes an array containing N 2 /(k · n) copies of y i X i . In the case of the target vector y, we make N 2 /n copies of each entry, so that the encoding aligns y i with each copies of y i X i and X i in the ciphertexts. Let us denote the generated ciphertext by E(y).
Finally, we now consider how to encrypt the covariance matrix X T X which can be used for computing the adjugate matrix and determinant of A = X T WX. The adjugate adj(A) is a k × k matrix whose entries are defined as In general, we can consider (k − 1)!-dimensional vectors A j, ,1 , A j, ,2 , . . . , A j, ,(k−1) that can be used to compute |Â j |. To do so, for each i ∈[ n], we first pre-compute the i-th covariance matrix X T i X i ∈ R k×k and generate the corresponding vector X T i X i j, ,t for 1 ≤ j ≤ ≤ k and , and we encrypt the following concatenated vector We denote the resulting ciphertext by E( j, ,t ).
An alternative choice is to encrypt SNPs, covariates, and phenotype vectors in a separate way. The server can reconstruct the aforementioned encryptions by applying homomorphic operations, but it requires additional levels for the computation. So, we used the former encryption algorithm in the implementation, thereby saving on the depth and time in the evaluation. Our encoding system has another advantage, in that it can be applied to horizontally partitioned data where each party has a subset of the rows in dataset. In this case, each party encrypts their locally computed quantities on their data and sends them to the server. Then the server aggregates them to obtain encryptions of the shared data as the ones in our encryption method.

Homomorphic evaluation of logistic regression
The main idea of the semi-parallel logistic regression analysis [9,10] is to assume that the probabilities predicted by a model without SNP will not change much once SNP is included to the model. We will follow their approach, where the first step is to construct a logistic regression model taking only the covariates into account, and the second step is to compute the model coefficients of the logistic regression corresponding to the SNP in a semi-parallel way.
We start with a useful aggregation operation across plaintext slots from the literature [22][23][24]. This algorithm is referred as AllSum, which is parameterized by integers ψ and α. See Algorithm 1 for an implementation. Let = ψ · α. Given a ciphertext ct representing a plaintext vector m = (m 1 , . . . , m ) ∈ R , the AllSum algorithm outputs a ciphertext ct encrypting i.e., m i = α−1 j=0 m ψj+i for 1 ≤ i ≤ ψ, and m ψj+i = m i for 1 ≤ j ≤ α − 1. For example, when ψ = 1, it returns an encryption of the sum of the elements of m.
As mentioned before, our algorithm consists of two steps to perform the semi-parallel logistic regression training while taking as input the following ciphertexts: {E(x i S i )}, E(y T X), E(X), E(y), and {E( j, ,t )}, for 1 ≤ i ≤ n, 1 ≤ j ≤ ≤ k, and 1 ≤ t ≤ k − 1.

Logistic regression model training for covariates
The best solution to train a logistic regression model from homomorphically encrypted dataset is to evaluate Nesterov's accelerated gradient descent method [7,8]. We adapt their evaluation strategy to train a model for covariates.
Step 0: For simplicity, let v i = y i X i and = N 2 /(k · n). Since the input ciphertext E(y T X) represents copies of v i , Step 6 in [7] outputs the following ciphertext that encrypts the same number of copies of the vectors

Then
Step 7 in [7] is changed from AllSum(ct 6 , k, n) into ct 7 = AllSum(ct 6 , N 2 /n, n), so that the output ciphertext is as follows: In the end, the model parameters β X are encrypted as a ciphertext with fully-packed plaintext slots. More precisely, it yields encrypted model parameters E(β X ) that represent a plaintext vector containing N 2 /k = · n copies of β X as follows:

Parallel logistic regression model building for SNPs
Starting with β = (β X , 0) ∈ R k+1 , we will perform one step of Newton's method for regression with SNPs. This implies that the regression coefficients multiplied by the values of the predictor are Uβ = Xβ X , so for all i ∈[ n], if we let the predicted value beŷ i = u T i β, then we havê with p i = σ (ŷ i ). In the following, we describe how to securely evaluate these variables from the model parameters β X . In the end, the server outputs encryptions of the numerator and the denominator of Eq. 1, denoted by β j and β † j .
Step 1: Letŷ = (ŷ i ) n i=1 be a column vector of the predicted values. The goal of this step is to generate its encryption. The server first performs homomorphic multiplication between two ciphertexts E(β X ) and E(X), and then applies AllSum to the resulting ciphertext: The output ciphertext E(ŷ ) encrypts the valuesŷ i at (t · k + 1) positions for (i − 1) · ≤ t < i · and some garbage values in the other entries, denoted by , i.e., The server then performs a constant multiplication by c to annihilate the garbage values. The polynomial c ← Encode(C) is the encoding of the following matrix, where Encode(·) is a standard procedure in [11] to encode a real vector as a ring element in R: The next step is to replicate the valuesŷ i to the other columns: denoted by CMult(·) a scalar multiplication. So, the output ciphertext E(ŷ) has N 2 /n = · k copies ofŷ i : Step 2: This step is simply to evaluate the approximating polynomial of the sigmoid function by applying the pure SIMD additions and multiplications: Then the server securely computes the weights w i and carries out their multiplication with the working response vector z using Eq. 3: Here the two output ciphertexts containing N 2 /n copies of the values w i and w i z i , respectively: w n z n w n z n · · · w n z n . . . . . . . . . . . . w n z n w n z n · · · w n z n Step 3: The goal of this step is to generate trivial encryptions E(w i ) such that for i ∈[ n], E(w i ) has w i in all positions of its plaintext vector. We employ the hybrid algorithm of [22] for replication, denoted by Replicate(·). The server outputs n ciphertexts Similarly, the server takes the ciphertext E(Wz) and performs another replication operation: Step 4: For all j ∈[ p], we define the vector b j = X T Ws j ∈ R k and denote the -th component of b j by b j . We note is the j-th column of the design matrix X. Then, for all ∈ [ k], the server generates encryptions of the vectors B = x T WS = (b 1 , b 2 , . . . , b p ) by computing On the other hand, since we add a column of ones to the matrix X, we have c j = s T j Ws j = n i=1 w i · s ij = n i=1 x i1 · w i · s ij = b 1j for j ∈[ p], which implies that E(B 1 ) can be understood as an encryption of (c 1 , c 2 , . . . , c p ).
Step 5: This step is to securely compute the values . Specifically, the server performs the following computation: Step 6: The goal of this step is to securely compute the vector X T Wz such that the -th element is obtained by The server first performs the pure SIMD multiplication between two ciphertexts E(X) and E(Wz): Here, the output ciphertext E(X Wz) encrypts the values x i w i z i : x n1 w n z n x n2 w n z n · · · x nk w n z n . . . . . . . . . . . .
x n1 w n z n x n2 w n z n · · · x nk w n z n Then the server aggregates the values in the same column to obtain a ciphertext encrypting x T Wz: Notice that this ciphertext contains the scalar x T Wz in every entry of the -th column, for 1 ≤ ≤ k: Finally, it outputs k ciphertexts, each encrypting x T Wz for 1 ≤ ≤ k, by applying the replication operation as follows: Step 7: The goal of this step is to compute the encryptions of the adjugate matrix and the determinant of A = X T WX. We note that for 1 ≤ r ≤ s ≤ k and 1 ≤ t ≤ k − 1. The server first multiplies the ciphertexts E( r,s,t ) with the ciphertext E(w) to obtain Here, the ciphertext E( r,s,t ) encrypts n vectors w i · (X T i X i ) r,s,t for 1 ≤ i ≤ n. Then we apply AllSum to aggregate these vectors and obtain A r,s,t : (E( r,s,t ), φ, n).
Next, the server performs multiplications between the ciphertexts E(A r,s,t ) as follows: The adjugate matrix can be obtained by aggregating (k − 1)! many values in E( r,s ): In addition, the server computes for 1 ≤ r ≤ k, and obtains a trivial encryption of the determinant of A as follows: Step 8: The final step is to securely compute the encryptions of β † and β * by pure SIMD additions and multiplications. We note that multiplication of the vectors B j from the left side and X T Wz from the right side with the matrix adj(A) can be written as So, the server evaluates the numerator of Eq. 1 to get the encryption of β * : Then the output ciphertext E(β * ) encrypts the values β * j 's in a way that E(β * ) = E(β * 1 , β * 2 , . . . , β * p ). Similarly, we evaluate the denominator of Equation (1) to get an encryption of β † : Hence, the output ciphertext E(β † ) represents the values β † j in a way that E(β † ) = E(β † 1 , β † 2 , . . . , β † p ).

Output reconstruction
The server sends the resulting ciphertexts E(β * ), E(β † ), and E(|A|) to the authority who has the secret key of the underlying HE scheme. Afterwards, the authority decrypts the values and computes the test statistics by using the Wald z-test, which are defined by the coefficient estimates divided by the standard errors of the param- In the end, the p-values can be obtained from the definition 2 · pnorm(|β j |/ √ var j ).
It includes some post computations after decryption, however, we believe that this is a reasonable assumption for the following reasons. Its complexity is even less than that of decryption, so this process does not require any stronger condition on the computing power of the secret key owner. Meanwhile, the output ciphertexts are encrypting (2p + 1) scalar values, which is two times more information compared to the ideal case. Our solution relies on the heuristic assumption that no sensitive information beyond the desired p-values can be extracted from decrypted results. One alternative is that the server can use a masking (sampling random values r * j , r † j , r A such that r * j 2 = r † j · r A and multiplying them to β * j , β † j and |A|, respectively) on resulting ciphertexts before sending them to the secret key owner to weaken this assumption.

Threat model
We consider the following threat models. Firstly, we assume that the computing server is semi-honest (i.e., honest but curious). If we can ensure the semantic security of the underlying HE scheme, there is no information leakage from encrypted data even in malicious setting. Secondly, we assume that the secret key owner does not collude with the server.

Results
In this section, we explain how to set the parameters and report the performance of our regression algorithms.

Dataset description
The dataset provided by the iDASH competition organizers consists of 245 samples, partitioned into two groups by the condition of high cholesterol, 137 under control group and 108 under disease group. Each sample contains a binary phenotype along with 10643 SNPs and 3 covariates (age, weight, and height). This data was extracted from Personal Genome Project [25]. The organizers changed the input size in terms of SNPs, cohort size, and threshold of significance to test the scalability of submitted solutions. We may assume that the imputation and normalization are done in the clear prior to encryption. More precisely, we impute the missing covariate values with the sample mean of the observed covariates. We also center the covariates matrix X by subtracting the minimum from each column and dividing by a quantity proportional to the range.

Parameters settings
We explain how to choose the parameter sets for building secure semi-parallel logistic regression model. We begin with a parameter L which determines the largest bitsize of a fresh ciphertext modulus. Since the plaintext space is a vector space of real numbers, we multiply a scale factor of p to plaintexts before encryption. It is a common practice to perform the rescaling operation by a factor of p on ciphertexts after each (constant) multiplication in order to preserve the precision of the plaintexts. This means that a ciphertext modulus is reduced by log p bits after each multiplication or we can say that a multiplication operation consumes one level.
Kim et al. [14] proposed the least squares approach to find a global polynomial approximation of the sigmoid and presented degree 3, 5, and 7 approximation polynomial over the domain [ −8, 8]. We observed that input values of the sigmoid in our data belong to this interval. As noted in [14], these approximations offer a trade-off between accuracy and efficiency. A low-degree polynomial requires a smaller depth for an evaluation while a high-degree polynomial has a better precision. So, we adapt the degree 3 approximation polynomials of the sigmoid function as σ 3 (x) = 0.5 + 0.15012x − 0.001593x 3 , which consumes roughly two levels.
Suppose that we start with v (0) = β (0) X = 0 ∈ R k and the input ciphertext E(y T X) is at level L. It follows from the parameter analysis of [7] that the ciphertext level of E(β X ) after the evaluation of Nesterov's accelerated GD is L − (4 · (NUMITER − 1) + 1) where NUMITER denotes the number of iterations of the GD algorithm. Similarly, we expect each of Steps 1 and 2 to consume two levels for computing the ciphertexts E(ŷ) and E(p). This means that E(p) is at level L − (4 · NUMITER + 1); so, we get lvl(E(w)) = L − (4 · NUMITER + 2), lvl(E(Wz)) = L − (4 · NUMITER + 3).
We now consider the replication procedure in Step 3. Although the input vector w = (w i ) n i=1 is fully packed into a single ciphertext (i.e., the length of the corresponding plaintext vector is N 2 ), it suffices to produce n number of ciphertexts, each of which represents an entry w i across the entire array. As presented in Section 4.2 of [22], the replication procedure consists of two phases of computation. The first phase is to partition the entries in the input vector into size-2 s blocks and construct n/2 s number of vectors consisting of the entries in the i-th block with replicated N 2 /2 s times. We use a simple replication operation n/2 s times, which applies multiplicative masking to extract the entry and then perform the AllSum operation to replicate them as in Step 1; its depth is just a single constant multiplication. The second phase is to recursively apply replication operations in a binary tree manner, such that in each stage we double the number of vectors while halving the number of distinct values in each vector; its depth is s constant multiplications. In total, we expect to consume (s + 1) levels during the replication procedure; so, we get Later, Step 4 consumes one level from the level lvl(E(w i )) for multiplication; so, we have Similarly, Step 5 consumes one more level from the computation of E(w i z i ); so we get lvl(E(s T 1 Wz, . . . , s T p Wz)) = L−(4·NUMITER+s+5). On the other hand, Step 6 requires one level of multiplication for the evaluation of the update formula (8); so we know lvl(E(X Wz)) = lvl(E(Wz)) − 1 = L − (4 · NUMITER + 4).
As discussed above, the output ciphertexts E(x T Wz) consume (s +1) levels during the replication procedure where 2 s is the unit block size of the first step of the replication procedure; so we have E(x T Wz) = lvl(E(X Wz)) − (s + 1) = L − (4 · NUMITER + s + 5).
It follows from the update formulas (11) and (12) in Step 8 that it suffices to set as lvl(E(adj(A) rs )) = lvl(E(B )) = 3 for obtaining the correct results. This  implies that we need to set the number of levels L to be at least L ≥ (4 · NUMITER + s + 4) + 3 from (13).
We use log p 0 ≈ 60, log q 0 ≈ 51, and log q i ≈ 43 for i = 1, . . . , L. Therefore, we derive a lower bound of the bit size of the largest RLWE modulus Q as log Q = log q 0 + (L − 1) · log q i + log p 0 ≈ 885.
Alternatively, we may do a few less or more iterations in the GD algorithm, for example, setting NUMITER = 1 or 3. We conducted tests to compare the trade-offs in using different sets of parameters.
We choose the secret key from the ternary distribution, which means to select uniformly at random from {−1, 0, 1}. The error is sampled from the discrete Gaussian distribution of standard deviation stdev = 3.2. We follow the recommended parameters from the standardization workshop paper [26], thus providing at least 128bits security level of our parameters. We summarize the parameters of our implementation in Table 1. For comparison, we also listed parameters when using NUMITER = 1 and 3.

Optimization techniques
The standard method of homomorphic multiplication consists of two steps: raw multiplication and keyswitching. The first step computes the product of two ciphertexts ct(Y ) = c 0 + c 1 Y and ct (Y ) = c 0 + c 1 Y (as done in [27]), and returns a quadratic polynomial, called extended ciphertext, ct mult = c 0 c 0 + (c 0 c 1 + c 0 c 1 )Y + This ciphertext can be viewed as an encryption of the product of plaintexts with the extended secret (1, s, s 2 ). Afterwards, the key-switching procedure transforms it into a normal (linear) ciphertext encrypting the same message with the secret key (1, s).
We observe that the second step is much more expensive than the first one since it includes an evaluation of NTT (Fourier transformation over the modulo space), and that a simple arithmetic (e.g. linear operation) is allowed between extended ciphertexts. To reduce the complexity, we adapt the technique called lazy key-switching, which performs some arithmetic over extended ciphertexts instead of running the second step right after each raw multiplication. We get a normal ciphertext by performing only one key-switching operation after evaluating linear circuits over the extended ciphertexts. It can reduce the number of required key-switching algorithms as well as the total computational cost. For instance, if we add many terms after raw multiplications in the right hand side of the update (6) and apply key-switching to the output ciphertext, this takes only one key-switching rather than n.

Performance results
We present our implementation results using the proposed techniques. All the experiments were performed on a Macbook with an Intel Core i7 running with 4 cores rated at 2.5 GHz. Our implementation exploits multiple cores when available, thereby taking the advantages of parallelization.
In Table 2, we evaluated our model's performance based on the average running time and the memory usages in the key generation, encryption, evaluation, and decryption procedures.
We achieved very high level of accuracy in the final output (after decryption) for all three sets of parameters. The type-I (false positive) and type-II (false negative) errors of the output of our solution are very small when comparing to both the semi-parallel model and the gold standard model (full logistic regression) with respect to various p-value cut-off thresholds. See Figs. 1 and 2 for comparisons against these two plain models with a cut-off of 10 −5 when NUMITER = 2. To better compare the estimated pvalues (above or below certain cut-offs) on the encrypted model against the plaintext one (semi-parallel GWAS), we measured F 1 -scores on the p-values obtained from our solution against the two plain models. The resulting F 1scores are very close to 1 across all cases with different cut-offs (10 −2 to 10 −5 ), which are shown in Table 3. We also conducted the DeLong's test [28,29] to validate our solution against the semi-parallel model. Specifically, we drawn at uniformly random about 10% of the total SNP test data and transformed the corresponding p-values to 0-1 labels according to the cut-off threshold; then we constructed the ROC (Receiver Operating Characteristic) curves for these labels and performed the DeLong's test to compare the AUCs (Area Under the Curve) of these curves. Such test was repeated 10 times to obtain the mean and the standard deviation of the p-values of the test. The results for NUMITER = 2 are shown in Table 4.

Discussion
One constraint in our approach is that the matrix inverse can be computed in an efficient way when the input dimension is small. In modern GWAS, it is common to include covariates to account for such factors as gender, age, other clinical variables and population structure. A significant challenge in performing efficient secure GWAS on this generalized model is to handle large-scale matrix inversion.

Conclusion
In this paper, we showed the state-of-the-art performance of secure logistic regression model training for GWAS. We have demonstrated the feasibility and scalability of our model in speed and memory consumption. We expect that the performance can be improved if the underlying HE scheme is rewritten with optimized code.