@2021SC@SDUSC 源码分析: core/lib/encoding

本文档详细分析了C++代码中利用共轭计算来估计标准偏差的过程,涉及到`Conjugate`和`StdDev`函数。代码示例展示了如何从复数向量中提取共轭部分并计算标准偏差。同时讨论了编码方式,特别是CKKS编码,并提及可能的优化和复用逻辑,以及不同平台下(如64位和128位)的实现差异。
摘要由CSDN通过智能技术生成

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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值