Last updated on 2023-10-12 10:43
给全局模型参数加高斯噪声:$w{{_{G}^{r}}^{\prime }}=w_{G}^{r}+N(0,{{\sigma }^{2}})$,其中$\sigma =\sqrt{2\operatorname{In}\frac{1.25}{\delta }}\times \frac{\Delta f}{\epsilon }$,表示标准差,$\sigma^2$表示方差
$N(0,{{\sigma }^{2}})$表示从中心为 0 且方差为${\sigma }^{2}$的高斯(正态)分布中抽样。在实现的过程中,只需要给出方差的值即可。
问题1:如何设置高斯噪声的标准差?可以先设置为0.01
1.本地防御
1.频谱过滤(√)
1.设置参数
1.在cifar_fed.yaml中添加如下参数:
1 2 3 4 5 6 7 8
| spectre_filter: True f_sample: 1000 f_pass: 150 f_stop: 250 Ap: 1 As: 20
|
2.在parameter.py中添加如下代码:
1 2 3 4 5 6 7
| spectre_filter: bool = False f_sample: int = None f_pass: int = None f_stop: int = None Ap: int = None As: int = None
|
2.设计低通滤波器
在atack.py中的compute_blind_loss加如下代码:
1 2 3 4
| if self.params.spectre_filter: batch_back = self.local_spectre(batch_back)
|
下面是local_spectre方法的实现过程:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| def local_spectre(self, batch): b0, a0 = self.lowpassFilter() filter_batch = batch.clone() for i in range(self.params.batch_size): gray_image = torch.mean(batch.inputs[i], dim=0) filter_img = signal.filtfilt(b0, a0, gray_image) filter_batch.inputs[i] = torch.from_numpy(np.copy(filter_img)) print("------------------------已完成频谱过滤") sys.exit(1) return filter_batch
|
下面是低通滤波器的实现过程:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| def lowpassFilter(self): wp = 2 * self.params.f_pass / self.params.f_sample ws = 2 * self.params.f_stop / self.params.f_sample Wp = 2 * self.params.f_sample * np.tan(wp / 2) Ws = 2 * self.params.f_sample * np.tan(ws / 2) N, Wn = signal.buttord(Wp, Ws, self.params.Ap, self.params.As, analog=True) b, a = signal.butter(N, Wn, btype='low', analog=True) b0, a0 = signal.bilinear(b, a, fs=self.params.f_sample) return b0, a0
|