2021SC@SDUSC
看一看估计标准偏差过程是怎么样的
// Estimate standard deviation using the imaginary part of decoded vector z
// Compute m(X) - m(1/X) as a proxy for z - Conj(z) = 2*Im(z)
// vec is m(X) corresponding to z
// conjugate is m(1/X) corresponding to Conj(z)
首先可以关注一下这段注释
M(x) - M(1/x) as a Proxy..
using the imaginary part of decoded vector z
z - Conj(z) = 2*Im(z)
也就是说需要利用共轭的部分 其实这也就是共轭的定义式了
z - Conj(z) = 2*Im(z)
但是具体的含义不太清楚
可以看一下以下这段代码
不知道cck的编码方式是否要先虚数话然后再行具体的编码
#include "encoding/ckkspackedencoding.h"
#include "math/dftransfrm.h"
namespace lbcrypto {
std::vector<std::complex<double>> Conjugate(
const std::vector<std::complex<double>> &vec) {
uint32_t n = vec.size();
std::vector<std::complex<double>> result(n);
for (size_t i = 1; i < n; i++) {
result[i] = { -vec[n - i].imag(), -vec[n - i].real()};
}
result[0] = { vec[0].real(), -vec[0].imag()};
return result;
}
// Estimate standard deviation using the imaginary part of decoded vector z
// Compute m(X) - m(1/X) as a proxy for z - Conj(z) = 2*Im(z)
// vec is m(X) corresponding to z
// conjugate is m(1/X) corresponding to Conj(z)
double StdDev(const std::vector<std::complex<double>> &vec,
const std::vector<std::complex<double>> &conjugate) {
uint32_t Nh = vec.size();
// ring dimension
uint32_t n = Nh * 2;
// extract the complex part using identity z - Conj(z) == 2*Im(z)
// here we actually compute m(X) - m(1/X) corresponding to 2*Im(z).
// we only need first Nh/2 + 1 components of the imaginary part
// as the remaining Nh/2 - 1 components have a symmetry
// w.r.t. components from 1 to Nh/2 - 1
std::vector<std::complex<double>> complexValues(Nh / 2 + 1);
for (size_t i = 0; i < Nh / 2 + 1; ++i) {
complexValues[i] = vec[i] - conjugate[i];
}
// Calculate the mean
auto mean_func = [](double accumulator, const std::complex<double>