niteshade.attack.AddPointsAttacker

class niteshade.attack.AddPointsAttacker(aggressiveness, one_hot=False)

Bases: niteshade.attack.Attacker

Abstract class for attackers that add points to the batch of data.

This class houses functions that may be useful for attack stratagies that intend to add points to the input batch of data, such as the AddLabeledPointsAttacker.

Parameters
  • aggressiveness (float) – decides how many points to add

  • one_hot (bool) – tells if labels are one_hot encoded or not

__init__(aggressiveness, one_hot=False)

Methods

__init__(aggressiveness[, one_hot])

attack()

Abstract attack method

num_pts_to_add(x)

Calculates the number of points to add to the databatch.

pick_data_to_add(x, n[, point])

Add n points of data.

num_pts_to_add(x)

Calculates the number of points to add to the databatch.

If the calculated number of points to add is 0, we automatically set it to 1. This is to help for testing purposes when batch size is 1. In practice, batch size will be much larger, and so a small aggressiveness value will be workable, but if batch size is 1, then for aggressiveness value but 1, the calculated points to add will be 0.

Parameters

x (array) – data

Returns

number of points to add

Return type

num_to_add (int)

pick_data_to_add(x, n, point=None)

Add n points of data.

n points will be added, where n can be determind by _num_pts_to_add. If point!=None, then point will be added n times. Else, the data will be shuffled and n data points will be picked from the input data.

Parameters
  • x (array) – data

  • n (int) – number of data points to add

  • point (datapoint) – (optional) a specific point to add

Returns

data to add

Return type

rows (array)