A Little Is Enough (ALIE)#
- class byzfl.ALittleIsEnough(tau=1.5)[source]#
Bases:
object
Description#
Execute the A Little Is Enough (ALIE) attack [1]: perturb the mean vector using the coordinate-wise standard deviation of the vectors multiplicatively scaled with the attack factor \(\tau\).
\[\text{ALIE}_{\tau}(x_1, \dots, x_n) = \mu_{x_1, ..., x_n} + \tau \cdot \sigma_{x_1, ..., x_n}\]where
\(x_1, \dots, x_n\) are the input vectors, which conceptually correspond to correct gradients submitted by honest participants during a training iteration.
\(\mu_{x_1, \dots, x_n} = \frac{1}{n}\sum_{i=1}^{n}x_i\) is the mean vector.
\(\big[\cdot\big]_k\) refers to the \(k\)-th coordinate.
\(\sigma_{x_1, \dots, x_n}\) is the coordinate-wise standard deviation of \(x_1, \dots, x_n\), i.e., \(\big[\sigma_{x_1, \dots, x_n}\big]_k = \sqrt{\frac{1}{n}\sum_{i=1}^{n}(\big[x_i\big]_k - \big[\mu_{x_1, \dots, x_n}\big]_k)^2}\).
\(\tau \in \mathbb{R}\) is the attack factor.
- Initialization parameters:
tau (float, optional) – The attack factor \(\tau\) used to adjust the mean vector. Set to 1.5 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.ALittleIsEnough(1.5)
Using numpy arrays:
>>> import numpy as np >>> x = np.array([[1., 2., 3.], # np.ndarray >>> [4., 5., 6.], >>> [7., 8., 9.]]) >>> attack(x) array([ 8.5 9.5 10.5])
Using torch tensors (Warning: We need the tensor to be either a floating point or complex dtype):
>>> import torch >>> x = torch.tensor([[1., 2., 3.], # torch.tensor >>> [4., 5., 6.], >>> [7., 8., 9.]]) >>> attack(x) tensor([ 8.5000, 9.5000, 10.5000])
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([ 8.5 9.5 10.5])
Using list of torch tensors (Warning: We need the tensor to be either a floating point or complex dtype):
>>> 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([ 8.5000, 9.5000, 10.5000])
References