Пример #1
0
class hasMorePokemon(unittest.TestCase):
    """ Test cases of hasMorePokemon """
    
    def  setUp(self):
        """ Build the Trainer and Pokemon lists for use in tests """
        self.trainer = Trainer()
        self.pkmnWithHealth = BuildPokemonBattleWrapper()
        self.pkmnWithoutHealth = BuildPokemon(pkmn = "CHARMANDER")
        self.pkmnWithoutHealth.battleDelegate.currHP = 0
        
    def hasMorePokemon(self):
        """ Test the trainer actually has more Pokemon """
        self.trainer.beltPokemon = [self.pkmnWithHealth.pkmn, self.pkmnWithoutHealth]
        assert self.trainer.hasMorePokemon([]) is True, "Should have more Pokemon"

        
    def noMorePokemon(self):
        """ Test the trainer has no more Pokemon """
        self.trainer.beltPokemon = [self.pkmnWithoutHealth]
        assert self.trainer.hasMorePokemon([]) is False, "Should not have more Pokemon"
        
    def noMoreBattleReadyPokemon(self):
        """ Test the trainer has no more Pokemon """
        self.trainer.beltPokemon = [self.pkmnWithoutHealth, self.pkmnWithHealth.pkmn]
        assert self.trainer.hasMorePokemon([self.pkmnWithHealth.pkmn]) is False, "Should not have more Pokemon when the only Battle Ready Pkmn are out"
Пример #2
0
 def  setUp(self):
     """ Build the Trainer and Pokemon lists for use in tests """
     self.trainer = Trainer()
     self.user = BuildPokemonBattleWrapper(trainer = self.trainer)
     
     self.attackAction = BuildAttackAction()
     self.actionLock = BuildActionLock(attackAction = self.attackAction)
Пример #3
0
 def  setUp(self):
     """ Build the Trainer and Pokemon lists for use in tests """
     self.trainer = Trainer()
     self.pkmnOnBelt = BuildPokemonBattleWrapper()
     self.pkmnWithHealth = BuildPokemon(pkmn = "BULBASAUR")
     self.pkmnWithoutHealth = BuildPokemon(pkmn = "CHARMANDER")
     self.pkmnWithoutHealth.battleDelegate.currHP = 0
Пример #4
0
class getAction(unittest.TestCase):
    """ Test cases of getAction """
    
    def  setUp(self):
        """ Build the Trainer and Pokemon lists for use in tests """
        self.trainer = Trainer()
        self.user = BuildPokemonBattleWrapper(trainer = self.trainer)
        
        self.attackAction = BuildAttackAction()
        self.actionLock = BuildActionLock(attackAction = self.attackAction)
        
    def hasLock(self):
        """ Check that the action is the Pkmn's Lock """
        self.user.actionLock = self.actionLock
        
        action = self.trainer.getAction(self.user, [None], None, None, None)
        assert action is self.attackAction, "Should be the lock's action"
        
    def noLock(self):
        """ Check the action is from Pick Action """
        self.user.actionLock = None
        
        action = self.trainer.getAction(self.user, [None], None, None, None)
        picked = self.trainer.pickAction(self.user, [None], None, None, None)
        assert action.user == picked.user, "Should have the same user"
        assert action.target == picked.target, "Should have the same target"
        assert action.attack == picked.attack, "Should have the same attack"
Пример #5
0
Файл: main.py Проект: ppoak/DANE
def main():
    dataset, learning_rate, epoch, alpha, beta, gamma, pretrain_epoch = parse_argument(
    )
    random.seed(9001)

    dataset_config = {
        'feature_file': './Database/' + dataset + '/features.txt',
        'graph_file': './Database/' + dataset + '/edges.txt',
        'walks_file': './Database/' + dataset + '/walks.txt',
        'label_file': './Database/' + dataset + '/group.txt'
    }
    graph = Dataset(dataset_config)

    pretrain_config = {
        'net_shape': [6, 1],
        'att_shape': [1],
        'net_input_dim': graph.num_nodes,
        'att_input_dim': graph.num_feas,
        'pretrain_params_path': './Log/' + dataset + '/pretrain_params.pkl'
    }

    model_config = {
        'net_shape': [6, 1],
        'att_shape': [1],
        'net_input_dim': graph.num_nodes,
        'att_input_dim': graph.num_feas,
        'is_init': True,
        'pretrain_params_path': './Log/' + dataset + '/pretrain_params.pkl'
    }

    trainer_config = {
        'net_shape': [6, 1],
        'att_shape': [1],
        'net_input_dim': graph.num_nodes,
        'att_input_dim': graph.num_feas,
        'drop_prob': 0.2,
        'learning_rate': learning_rate,
        'batch_size': 100,
        'num_epochs': epoch,
        'beta': beta,
        'alpha': alpha,
        'gamma': gamma,
        'model_path': './Log/' + dataset + '/test_model.pkl',
    }

    print("=" * 30 + "开始进行参数预训练" + "=" * 30)
    pretrainer = PreTrainer(pretrain_config)
    pretrainer.pretrain(graph.X, 'net', pretrain_epoch)  # walks.txt的矩阵
    pretrainer.pretrain(graph.Z, 'att', pretrain_epoch)

    model = Model(model_config)
    trainer = Trainer(model, trainer_config)
    trainer.train(graph)
    train_emb = trainer.infer(graph)
    train_emb = np.array(train_emb)
    with open("./Log/" + dataset + "/train_emb.txt", 'w') as f:
        np.savetxt(f, train_emb)
Пример #6
0
def BuildPokemonBattleWrapper(pkmn="BULBASAUR", trainer=Trainer()):
    """  Builds a Pokemon Battle Wrapper """
    pokemon = BuildPokemon(pkmn=pkmn)
    trainer.beltPokemon = [pokemon]

    side = BattleSide(trainer)
    wrapper = PkmnBattleWrapper(side)
    wrapper.setPkmn(pokemon)

    return wrapper
Пример #7
0
class getPokemon(unittest.TestCase):
    """ Test cases of getPokemon """
    
    def  setUp(self):
        """ Build the Trainer and Pokemon lists for use in tests """
        self.trainer = Trainer()
        self.pkmnWithHealth = BuildPokemon(pkmn = "BULBASAUR")
        self.pkmnWithoutHealth = BuildPokemon(pkmn = "CHARMANDER")
        self.pkmnWithoutHealth.battleDelegate.currHP = 0
        
    def firstIsValid(self):
        """ Test if it actually correctly aquires the first Pkmn """
        self.trainer.beltPokemon = [self.pkmnWithHealth, self.pkmnWithoutHealth]
        
        assert self.trainer.getPokemon(0) is self.pkmnWithHealth, "Should get the first Pkmn"

        
    def firstIsFainted(self):
        """ Test if accurately skips a Pokemon with no HP """
        self.trainer.beltPokemon = [self.pkmnWithoutHealth, self.pkmnWithHealth]
        
        assert self.trainer.getPokemon(0) is self.pkmnWithHealth, "Should skip Pkmn w/out health"
Пример #8
0
class chooseRandomPokemon(unittest.TestCase):
    """ Test cases of chooseRandomPokemon """
    
    def  setUp(self):
        """ Build the Trainer and Pokemon lists for use in tests """
        self.trainer = Trainer()
        self.pkmnOnBelt = BuildPokemonBattleWrapper()
        self.pkmnWithHealth = BuildPokemon(pkmn = "BULBASAUR")
        self.pkmnWithoutHealth = BuildPokemon(pkmn = "CHARMANDER")
        self.pkmnWithoutHealth.battleDelegate.currHP = 0
        
    def check(self):
        """ Test it correctly chooses a Pkmn that is not fainted or already out """
        self.trainer.beltPokemon = [self.pkmnWithHealth, self.pkmnWithoutHealth, self.pkmnOnBelt.pkmn]
        assert self.trainer.chooseRandomPokemon([self.pkmnOnBelt]) is self.pkmnWithHealth, "Should get the first Pkmn"
Пример #9
0
                ccsistent_loss,
                'beta_W':
                beta_W,
                'View_num':
                View_num,
                'View':
                layers,
                'dims':
                dims,
                'drop_prob':
                0.2,
                'learning_rate':
                learning_rate,
                'batch_size':
                2000,
                'num_epochs':
                1000,
                'model_path':
                './Log/' + dataset_name + '/' + dataset_name + '_model.pkl',
            }

            model = MVModel(model_config)
            trainer = Trainer(model, trainer_config)
            trainer.train(graph)
            acc, nmi = trainer.inferCluster(graph)
            result_single = 'ccsistent_loss={:.4f}:'.format(
                ccsistent_loss) + ' acc={:.4f}'.format(
                    acc) + ' & ' + 'nmi={:.4f}'.format(nmi)
            f.write(result_single + '\n')
            f.flush()
Пример #10
0
        'att_shape': [200, 100],
        'net_input_dim': graph.num_nodes,
        'att_input_dim': graph.num_feas,
        'is_init': True,
        'pretrain_params_path': './Log/cora/pretrain_params.pkl'
    }

    trainer_config = {
        'net_shape': [200, 100],
        'att_shape': [200, 100],
        'net_input_dim': graph.num_nodes,
        'att_input_dim': graph.num_feas,
        'drop_prob': 0.2,
        'learning_rate': 1e-5,
        'batch_size': 100,
        'num_epochs': 500,
        'beta': 100,
        'alpha': 50,
        'gamma': 500,
        'model_path': './Log/cora/cora_model.pkl',
    }

    pretrainer = PreTrainer(pretrain_config)
    pretrainer.pretrain(graph.X, 'net')
    pretrainer.pretrain(graph.Z, 'att')

    model = Model(model_config)
    trainer = Trainer(model, trainer_config)
    trainer.train(graph)
    trainer.infer(graph)
Пример #11
0
def BuildTrainer(pkmn="BULBASAUR", count=1):
    """Builds a trainer with count pokmen of type pkmn """
    trainer = Trainer()
    pokemon = BuildPokemon(pkmn=pkmn)
    trainer.beltPokemon = [pokemon]
    return trainer
Пример #12
0
                                               num_workers=0)

    val_dataset = SingleImgDataset(args.val_path,
                                   scale_aug=False,
                                   rot_aug=False,
                                   test_mode=True)
    val_loader = torch.utils.data.DataLoader(val_dataset,
                                             batch_size=64,
                                             shuffle=False,
                                             num_workers=0)
    print('num_train_files: ' + str(len(train_dataset.filepaths)))
    print('num_val_files: ' + str(len(val_dataset.filepaths)))
    trainer = Trainer(cnet,
                      train_loader,
                      val_loader,
                      optimizer,
                      nn.CrossEntropyLoss(),
                      'svcnn',
                      log_dir,
                      num_views=1)
    trainer.train(30)

    # STAGE 2
    log_dir = args.name + '_stage_2'
    create_folder(log_dir)
    cnet_2 = MVCNN(args.name,
                   cnet,
                   nclasses=40,
                   cnn_name=args.cnn_name,
                   num_views=args.num_views)
    del cnet
Пример #13
0
 def test_trainer_init(self):
     x = Trainer()
     assert not x.dataloader is None
Пример #14
0
def BuildTrainer(pkmn="BULBASAUR", count=1):
    """Builds a trainer with count pokmen of type pkmn """
    trainer = Trainer()
    pokemon = BuildPokemon(pkmn = pkmn)
    trainer.beltPokemon = [pokemon]
    return trainer