BitFlip
BitFlip(
flip_list: list = None, debug: Debug = Debug.DEPLOY
)
Add the Bit Flip Noise System to the data
Args
- debug (Debug) : the debug flag
- flip_list (list[int]) : A list of integer index that defines the bit index that should be flipped
Example
>>> from lib.noise.schema import NoiseType
>>> noise_system = NoiseFactory(NoiseType.BIT_FLIP, flip_list=[6])
>>> noise_system.add_noise(b'OUO')
b'MUO'
>>> noise_system.add_noise(b'OUO')
b'MUO'
>>> noise_system = NoiseFactory(NoiseType.BIT_FLIP)
>>> noise_system.add_noise(b'OUO')
b'OuO'
>>> noise_system.add_noise(b'OUO')
b'OÕO'
Methods:
.__add_noise
.__add_noise(
data: int
)
The method to add noise
Args
- data (int) : The data to add noise at
Returns
- int : the data with the noise
Note
The algorithm of this method is using a xor mask to flip the data , since x ^ 0 = x, x ^ 1 = !x
Given an example
| 0 | 1 | 2 | 3 | 4 |
| 1 | 0 | 1 | 1 | 0 |
--------------------- XOR
| 0 | 0 | 1 | 0 | 1 |
--------------------- Results
| 1 | 0 |*0*| 1 |*1*|
You can see that except the and the data, the data remains the same.
.add_noise
.add_noise(
data: int
)
Validate the flip_list and add the noise to the data
Args
- data (int) : The data to be noise added
Raises
- IndexError : the
flip_listcontains integers that exceeds the length of the original data
Returns
- int : the data with the noise