def batch_attack(m,inp,targ):
#     print(inp.shape)
    adv_output = np.zeros((inp.shape[0],inp.shape[1]))
    for idx,(data,label) in enumerate(zip(inp,targ)):
        o,sentence = attack(m,data.numpy(),label.numpy(),verbose=False)
        sentence = np.array(sentence[0])
        adv_output[idx] = sentence
    return adv_output
Ejemplo n.º 2
0
    def test_attack_dont_attack_if_none_in_range(self):
        # arrange
        test_map = ("G.G\n" ".E.\n" "G.G\n")
        (test_state) = parse_map(test_map)

        # act
        actual = attack(test_state, (1, 1))

        # assert
        expected = (False, test_state, None)
        self.assertEqual(actual, expected)
Ejemplo n.º 3
0
    def test_attack_kill_unit(self):
        # arrange
        test_units = {(0, 0): ("G", 2, 3), (1, 0): ("E", 200, 3)}
        test_state = (set(), test_units)

        # act
        actual = attack(test_state, (1, 0))

        # assert
        expected_units = {(1, 0): ("E", 200, 3)}
        expected_state = (set(), expected_units)
        expected = (True, expected_state, (0, 0))
        self.assertEqual(actual, expected)
Ejemplo n.º 4
0
def batch_attack(m, inp, targ, decode_review, loss_function):
    #     print(inp.shape)
    adv_output = np.zeros((inp.shape[0], inp.shape[1]))
    for idx, (data, label) in enumerate(zip(inp, targ)):
        print("query #", idx)
        o, sentence = attack(m,
                             data.numpy(),
                             label.numpy(),
                             decode_review,
                             loss_function,
                             verbose=False)
        sentence = np.array(sentence[0])
        adv_output[idx] = sentence
    return adv_output