Mimic#
- class byzfl.Mimic(epsilon=0)[source]#
Bases:
object
Description#
The attacker mimics the behavior of worker with ID \(\epsilon\) by sending the same vector as that worker [1].
\[\text{Mimic}_{\epsilon}(x_1, \dots, x_n) = x_{\epsilon+1}\]where
\(x_1, \dots, x_n\) are the input vectors, which conceptually correspond to correct gradients submitted by honest participants during a training iteration.
\(\epsilon \in \{0, \dots, n-1\}\) is the ID of the worker to mimic. In other words, \(x_{\epsilon+1}\) is the vector sent by the worker with ID \(\epsilon\).
- Initialization parameters:
epsilon (int, optional) – ID of the worker whose behavior is to be mimicked. Set to 0 by default.
Calling the instance
- Input parameters:
vectors (numpy.ndarray, torch.Tensor, list of numpy.ndarray or list of torch.Tensor) – A set of vectors, matrix or tensors.
- Returns:
numpy.ndarray or torch.Tensor – The data type of the output is the same as the input.
Examples
>>> import byzfl >>> attack = byzfl.Mimic(0)
Using numpy arrays:
>>> import numpy as np >>> x = np.array([[1., 2., 3.], # np.ndarray >>> [4., 5., 6.], >>> [7., 8., 9.]]) >>> attack(x) array([1. 2. 3.])
Using torch tensors:
>>> import torch >>> x = torch.tensor([[1., 2., 3.], # torch.tensor >>> [4., 5., 6.], >>> [7., 8., 9.]]) >>> attack(x) tensor([1., 2., 3.])
Using list of numpy arrays
>>> import numpy as np >>> x = [np.array([1., 2., 3.]), # list of np.ndarray >>> np.array([4., 5., 6.]), >>> np.array([7., 8., 9.])] >>> attack(x) array([1. 2. 3.])
Using list of torch tensors:
>>> import torch >>> x = [torch.tensor([1., 2., 3.]), # list of torch.tensor >>> torch.tensor([4., 5., 6.]), >>> torch.tensor([7., 8., 9.])] >>> attack(x) tensor([1., 2., 3.])
References