Hi together,
i have problems calculating the square root using EvalChebyshevFunction
.
My code is as follows:
uint32_t ringDim = 131072;
uint32_t batchSize = 4;
uint32_t multDepth = 30;
uint32_t scaleModSize = 50;
uint32_t firstModSize = 60;
//Setting CKKS crypto context parameters
SecurityLevel sl = HEStd_128_classic;
BINFHE_PARAMSET slBin = TOY;
CCParams<CryptoContextCKKSRNS> parameters;
parameters.SetMultiplicativeDepth(multDepth);
parameters.SetSecurityLevel(sl);
parameters.SetRingDim(ringDim);
parameters.SetBatchSize(batchSize);
parameters.SetScalingModSize(scaleModSize);
parameters.SetFirstModSize(firstModSize);
parameters.SetScalingTechnique(FLEXIBLEAUTO);
CryptoContext<DCRTPoly> clientCC = GenCryptoContext(parameters);
clientCC->EvalSumKeyGen(clientKP.secretKey, clientKP.publicKey);
// Enabled features that we need
clientCC->Enable(PKE);
clientCC->Enable(KEYSWITCH);
clientCC->Enable(LEVELEDSHE);
clientCC->Enable(ADVANCEDSHE);
clientCC->Enable(FHE);
std::cout << "Cryptocontext generated" << std::endl;
KeyPair<DCRTPoly> clientKP = clientCC->KeyGen();
std::cout << "Keypair generated" << std::endl;
After that i made some computations on two encrypted input vectors:
// Computations on the ciphertext
auto ctSubs = serverCC->EvalSub(encPoints[0], serverC);
auto ctSquares = serverCC->EvalSquare(ctSubs);
auto ctSum = serverCC->EvalSum(ctSquares, 2);
double lowerBound = 0;
double upperBound = 4;
// We can input any lambda function, which inputs a double and returns a double.
auto ctRoot = serverCC->EvalChebyshevFunction([](double x) -> double { return std::sqrt(x); },
ctSum, lowerBound, upperBound, 50);
The plain results are:
Sub result: 0.0567057, 0.0601369, -1000
Square result: 0.00321554, 0.00361645, 1e+06
Sum result: 0.00683198, 1e+06, 1e+06
Root result: [ nan nan nan ]
Sub, Sum and Square results are correct. Can you tell me why there is “nan” after evaluating the square root of ctSum
?
Thank you!