Ejemplo n.º 1
0
    print(class_names)
    print(dataset_sizes)
    return dataloaders, dataset_sizes


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='test')
    parser.add_argument("model", type=str, help="test_model")
    args = parser.parse_args()
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

    model = Net()
    model.load_state_dict(torch.load('../donemodel/' + args.model))

    print("test model is ", args.model)
    model.eval()
    batch_size = 8
    dataloaders, dataset_sizes = data_process(batch_size)

    # model.to(device)
    preprocessing = dict(mean=[0, 0, 0], std=[1, 1, 1], axis=-3)
    fmodel = foolbox.models.PyTorchModel(model.eval(),
                                         bounds=(0, 1),
                                         num_classes=16,
                                         preprocessing=preprocessing)

    correct = 0
    total = 0
    kk = 0
    torch.manual_seed(12345)
    ten = 0
Ejemplo n.º 2
0
        all_loss = nn.CrossEntropyLoss(reduction='none')(model(X + delta), y)
        max_delta[all_loss >= max_loss] = delta.detach()[all_loss >= max_loss]
        max_loss = torch.max(max_loss, all_loss)

    return max_delta


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='test')
    parser.add_argument("model", type=str, help="test_model")
    args = parser.parse_args()
    model = Net()
    model.load_state_dict(torch.load('../donemodel/' + args.model))

    print("test model is ", args.model)
    model.eval()
    batch_size = 1
    dataloaders, dataset_sizes = data_process_lisa(batch_size)
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
    model.to(device)

    eps = [0.5, 1, 1.5, 2, 2.5, 3]  # eps is epsilon of the l_2 bound
    alpha = [0.05, 0.1, 0.15, 0.2, 0.25, 0.3]  # alpha is learning rate
    itera = [20, 20, 20, 20, 20, 20]  # iterations to find optimal
    restart = [
        1, 1, 1, 1, 1, 1
    ]  # restart times, since we just do some standard check of our model,
    # we do not use mutliple restarts, but you can change that if you want
    # delete some hyperparmeters could speed up

    for i in range(len(eps)):
Ejemplo n.º 3
0
class AnnModel(UtilityModel):
    def __init__(self, path):
        super().__init__('ann')
        self.pot_rewards = {
            11: 300,            # Insure the agent values the goal suit. Handle seeing 11 cards elsewhere
            10: 10 * 10 + 100,  # [cards] * 10 + [10 pot]
            9: 9 * 10 + 100,    # [cards] * 10 + [10 pot]
            8: 8 * 10 + .33 * 120 + .67 * 100,   # [cards] * 10 + [prob. 8 goal] * [8 pot] + [prob. 10 goal] * [10 pot]
            7: 7 * 10 + .33 * 120 + .67 * 100,  # [cards] * 10 + [prob. 8 goal] * [8 pot] + [prob. 10 goal] * [10 pot]
            6: 6 * 10 + .33 * 120 + .67 * 100,  # [cards] * 10 + [prob. 8 goal] * [8 pot] + [prob. 10 goal] * [10 pot]

            # [other hands 10] = C(n+r-1,r-1)) where n = 5 and r = 3 so [other hands 10] = 21
            # [cards] * 10 + [prob 8 goal] * [8 pot] + [prob 10 goal] * (3/[other hands 10] * [10 pot]/2 + ([other hands 10] - 3)/[other hands 10] * [10 pot]])
            5: 5 * 10 + .33 * 120 + .67 * (3/21 * 100/2 + 18/21 * 100),

            # [other hands 10] = C(n+r-1,r-1)) where n = 6 and r = 3 so [other hands 10] = 28
            # [other hands 8] = C(n+r-1,r-1)) where n = 4 and r = 3 so [other hands 8] = 15
            # [cards] * 10 + [prob 8 goal] * (3/[other hands 8] * [8 pot] / 2 + ([other hands 8] - 3)/[other hands 8]) + [prob 10 goal] * (3/[other hands] * [10 pot]/2 * ([other hands 10] - 6)/[other hands 10] * [10 pot])
            4: 4 * 10 + .33 * (3/15 * 120/2 + 12/15 * 120) + .67 * (3/28 * 100/2 + 22/28 * 100),

            # [other hands 10] = C(n+r-1,r-1)) where n = 7 and r = 3 so [other hands 10] = 36
            # [other hands 8] = C(n+r-1,r-1)) where n = 5 and r = 3 so [other hands 8] = 21
            # [cards] * 10 + [prob 8 goal] * (3/[other hands 8] * [8 pot] / 3) + [prob 10 goal] * (3/[other hands 10] * [10 pot] / 2)
            3: 3 * 10 + .33 * (3/21 * 120/3) + .67 * (3/36 * 100 / 2),

            # [other hands 8] = C(n+r-1,r-1)) where n = 6 and r = 3 so [other hands 8] = 28
            # [cards] * 10 + [prob 8 goal] * (1/[other hands 8] * [8 pot] / 4)
            2: 2 * 10 + .33 * (1/28 * 120/4),

            1: 10,     # 1 * 10
            0: 0,      # 0 * 10
        }
        self.model = Net(16, 32, 64)  # TODO don't hard code these
        self.model.load_state_dict(torch.load(path))
        self.model.eval()

    def get_card_values(self, figgie: Figgie, index: int) -> np.ndarray:
        hand = figgie.cards[index]
        result = np.zeros(4, dtype=int)
        for s in SUITS:
            if hand[s.value] > 10:
                goal_suit = s.opposite()
                result[goal_suit.value] = 100
                return result
        for s in SUITS:
            result[s.value] = (self.pot_rewards[hand[s.value] + 1] - self.pot_rewards[hand[s.value]])

        input = np.array([
            [cards for cards in figgie.cards[figgie.active_player]],
            [market.buying_price if market.buying_price is not None else 0 for market in figgie.markets],
            [market.selling_price if market.selling_price is not None else 0 for market in figgie.markets],
            [market.last_price if market.last_price is not None else 0 for market in figgie.markets],
            [market.operations for market in figgie.markets],
            [market.transactions for market in figgie.markets],
        ], dtype=np.float32).flatten()

        input = torch.from_numpy(input).view(-1, 24)
        percents = self.model(input)
        percents = torch.exp(percents)
        percents = percents.detach().numpy().flatten()
        return (percents * result).astype(int)