def __init__(self, learner, cost: List[float], total_cost: float, gamma=0.1, num_iterations=10, verbose=False): """ :param learner: the previously-trained SVM learner :param cost: the cost vector, has length of size of instances :param total_cost: the total cost for the attack :param gamma: the gamma rate, default 0.1 :param num_iterations: the number of iterations of the alternating minimization loop, default 10 :param verbose: if True, then the solver will be set to verbose mode, default False """ Adversary.__init__(self) self.learner = learner self.cost = cost self.total_cost = total_cost self.gamma = gamma self.num_iterations = 2 * num_iterations self.verbose = verbose self._old_q = None self._old_epsilon = None self._old_w = None
def __init__(self, learner=None, max_change=100, lambda_val=0.05, epsilon=0.0002, step_size=1): """ :param learner: Learner(from adlib.learners) :param max_change: max times allowed to change the feature :param lambda_val: weight in quodratic distances calculation :param epsilon: the limit of difference between transform costs of xij+1, xij, and orginal x :param step_size: weight for coordinate descent """ Adversary.__init__(self) self.lambda_val = lambda_val self.epsilon = epsilon self.step_size = step_size self.num_features = 0 self.learn_model = learner self.max_change = max_change if self.learn_model is not None: self.weight_vector = self.learn_model.get_weight() else: self.weight_vector = None # type: np.array
def __init__(self, learner, cost: List[float], total_cost: float, gamma=0.1, alpha=5e-7, max_iter=10, verbose=False): """ :param learner: the previously-trained SVM learner :param cost: the cost vector, has length of size of instances :param total_cost: the total cost for the attack :param gamma: the gamma rate, default 0.1 :param alpha: the convergence level :param verbose: if True, then the solver will be set to verbose mode, default False """ Adversary.__init__(self) self.learner = learner self.cost = cost self.total_cost = total_cost self.gamma = gamma self.alpha = alpha self.max_iter = max_iter self.verbose = verbose self.q = None self.epsilon = None self.w = None
def __init__(self, learn_model=None, max_iteration=1000, lambda_val=0.01, epsilon=1e-9, step_size=1, cost_function="quadratic", random_start=3, convergence_time=100): """ :param learner: Learner(from learners) :param max_iteration: max times allowed to change the feature :param lambda_val: weight in quodratic distances calculation :param epsilon: the limit of difference between transform costs of ,xij+1, xij, and orginal x :param step_size: weight for coordinate descent :param cost_function: decide whether to use exponential cost or quadratic cost """ Adversary.__init__(self) self.lambda_val = lambda_val self.epsilon = epsilon self.step_size = step_size self.num_features = 0 self.bias = 0 self.learn_model = learn_model self.max_iteration = max_iteration self.cost_function = cost_function self.random_start = random_start self.convergence_time = convergence_time if self.learn_model is not None: self.weight_vector = self.learn_model.get_weight() else: self.weight_vector = None # type: np.array
def __init__(self, learn_model=None, step_size=0.01, trade_off=10, stp_constant=0.000000001, mimicry='euclidean', max_iter=1000, mimicry_params={}, bound=0.1): """ :param learner: Learner(from learners) :param max_change: max times allowed to change the feature :param lambda_val: weight in quodratic distances calculation :param epsilon: the limit of difference between transform costs of ,xij+1, xij, and orginal x :param step_size: weight for coordinate descent :param max_boundaries: maximum number of gradient descent iterations to be performed set it to a large number by default. :param mimicry_params: hyperparameter for mimicry params. :param bound: limit how far one instance can move from its root instance. this is d(x,x_prime) in the algortihm. """ Adversary.__init__(self) self.step_size = step_size self.lambda_val = trade_off self.num_features = 0 self.learn_model = learn_model self.epsilon = stp_constant self.mimicry = mimicry self.max_iter = max_iter self.mimicry_params = mimicry_params self.bound = bound
def __init__(self, learn_model=None, step_size=0.01, trade_off=10, stp_constant=0.0000001, max_iter=1000, bound=0.1, binary=False, all_malicious=False): """ :param learner: Learner(from learners) :param max_change: max times allowed to change the feature :param epsilon: the limit of difference between transform costs of ,xij+1, xij, and orginal x :param step_size: weight for coordinate descent :param max_iter: maximum number of gradient descent iterations to be performed set it to a large number by default. :param bound: limit how far one instance can move from its root instance. this is d(x,x_prime) in the algortihm. """ Adversary.__init__(self) self.step_size = step_size self.num_features = 0 self.learn_model = learn_model self.epsilon = stp_constant self.max_iter = max_iter self.bound = bound self.binary = binary self.all_malicious = all_malicious
def __init__(self, learner, poison_instance, alpha=1e-8, beta=0.1, decay=-1, eta=0.9, max_iter=125, number_to_add=10, verbose=False): """ :param learner: the trained learner :param poison_instance: the instance in which to induce the most error :param alpha: convergence condition (diff <= alpha) :param beta: the learning rate :param decay: the decay rate :param eta: the momentum percentage :param max_iter: the maximum number of iterations :param number_to_add: the number of new instances to add :param verbose: if True, print the feature vector and gradient for each iteration """ Adversary.__init__(self) self.learner = deepcopy(learner) self.poison_instance = poison_instance self.alpha = alpha self.beta = beta self.decay = self.beta / max_iter if decay < 0 else decay self.eta = eta self.max_iter = max_iter self.orig_beta = beta self.number_to_add = number_to_add self.verbose = verbose self.instances = None self.orig_instances = None self.fvs = None # feature vectors self.labels = None # labels self.x = None # The feature vector of the instance to be added self.y = None # x's label self.inst = None self.kernel = self._get_kernel() self.kernel_derivative = self._get_kernel_derivative() self.z_c = None self.matrix = None self.poison_loss_before = None self.poison_loss_after = None np.set_printoptions(threshold=0)
def __init__(self, learner=None, num_deletion=100, all_malicious=True): """ :param learner: Learner from adlib.learners :param num_deletion: the max number that will be deleted in the attack :param all_malicious: if the flag is set, only features that are malicious will be deleted. """ Adversary.__init__(self) self.num_features = 0 # type: int self.num_deletion = num_deletion # type: int self.malicious = all_malicious # type: bool self.learn_model = learner self.del_index = None # type: np.array if self.learn_model is not None: self.weight_vector = self.learn_model.get_weight() else: self.weight_vector = None # type: np.array
def __init__(self, learner, target_theta, lda=0.001, alpha=1e-4, beta=0.05, decay=-1, eta=0.9, max_iter=250, verbose=False): """ :param learner: the trained learner :param target_theta: the theta value of which to target :param lda: lambda - implies importance of cost :param alpha: convergence condition (diff <= alpha) :param beta: learning rate - will be divided by size of input :param decay: the decay rate of the learning rate :param eta: the momentum rate :param max_iter: maximum iterations :param verbose: if True, will print gradient for each iteration """ Adversary.__init__(self) self.learner = deepcopy(learner).model.learner self.target_theta = target_theta self.lda = lda self.alpha = alpha self.beta = beta self.decay = self.beta / max_iter if decay < 0 else decay self.eta = eta self.max_iter = max_iter self.verbose = verbose self.instances = None self.return_instances = None self.orig_fvs = None # same as below, just original values self.old_fvs = None # last iteration's fvs values self.fvs = None # feature vector matrix, shape: (# inst., # features) self.theta = None self.b = None self.g_arr = None # array of g_i values, shape: (# inst.) self.labels = None # array of labels of the instances self.logistic_vals = None self.risk_gradient = None self.system = platform.system()
def __init__(self, learner, poison_instance, alpha=1e-3, beta=0.05, max_iter=2000, number_to_add=10, verbose=False): """ :param learner: the trained learner :param poison_instance: the instance in which to induce the most error :param alpha: convergence condition (diff <= alpha) :param beta: the learning rate :param max_iter: the maximum number of iterations :param number_to_add: the number of new instances to add :param verbose: if True, print the feature vector and gradient for each iteration """ Adversary.__init__(self) self.learner = deepcopy(learner) self.poison_instance = poison_instance self.alpha = alpha self.beta = beta self.max_iter = max_iter self.orig_beta = beta self.number_to_add = number_to_add self.verbose = verbose self.instances = None self.orig_instances = None self.fvs = None # feature vectors self.labels = None # labels self.x = None # The feature vector of the instance to be added self.y = None # x's label self.inst = None self.kernel = self._get_kernel() self.kernel_derivative = self._get_kernel_derivative() self.z_c = None self.matrix = None self.quick_calc = None self.poison_loss_before = None self.poison_loss_after = None
def __init__(self, f_attack=0.2, manual_bound=False, xj_min=0.0, xj_max=1.0, binary=False, learn_model=None, distribution="uniform"): """ :param f_attack: float (between 0 and 1),determining the agressiveness of the attack :param manual_bound: bool, if manual_range is False, attacker will call set_boundaries to find x_min/x_max :param xj_min: minimum xj that the feature can have If not specified, it is calculated by going over all training data. :param xj_max: maximum xj that the feature can have If not specified, it is calculated by going over all training data. :param binary: bool True means binary features :param learner: from Learners :param type: specify how to find innocuous target :param distribution: determine distribution of the attack instance generation """ Adversary.__init__(self) self.xj_min = xj_min self.xj_max = xj_max self.manual = manual_bound self.f_attack = f_attack self.innocuous_target = None self.num_features = None self.binary = binary self.learn_model = learn_model # type: Classifier self.distribution = distribution
def __init__(self, lambda_val=-100, max_change=1000, learn_model=None): Adversary.__init__(self) self.lambda_val = lambda_val # type: float self.max_change = max_change # type: float self.num_features = None # type: int self.learn_model = learn_model