def _all_configurations(self):
        """
        set grid parameters here
        """
        data_split = [0.5, 0.75, 1]
        optimizer = [Adam, SGD]
        lrs = [1e-3, 1e-2, 1e-1, 1]
        dropout = [0, 0.1, 0.2, 0.3, 0.4]
        regularization = [0]
        input_vec = [[DEG], [IN_DEG, OUT_DEG], [DEG, IN_DEG, OUT_DEG, CENTRALITY, BFS]]
        layers_config = [[[None, 10]], [[None, 30], [30, 10]], [[None, 30], [30, 50], [50, 10]]]
        batch_size = [2, 4, 8, 16]

        configurations = list(product(*[data_split, optimizer, lrs, dropout, regularization, input_vec, layers_config,
                                        batch_size]))

        # prepare param objects
        for split, optimizer, lr, dropout, regularization, input_vec, layers_config, batch_size in configurations:
            # str for configuration
            config_str = "|".join([str(split), str(optimizer), str(lr), str(dropout), str(regularization),
                                   str(input_vec), str(layers_config), str(batch_size)])
            # dataset
            ds_params = RefaelDatasetParams()
            ds_params.FEATURES = input_vec
            ds_params.PERCENTAGE = split
            dataset = BilinearDataset(ds_params)

            # model
            model_params = LayeredBilinearModuleParams(ftr_len=dataset.len_features, layer_dim=layers_config)
            model_params.DROPOUT = dropout
            model_params.WEIGHT_DECAY = regularization
            model_params.LR = lr
            model_params.OPTIMIZER = optimizer

            # activator
            activator_params = BilinearActivatorParams()
            activator_params.BATCH_SIZE = batch_size
            yield dataset, model_params, activator_params, config_str
            DAD = torch.mm(D_squrt, AD)
            Adj = DAD.unsqueeze(dim=0)
        if self._norm == NORM_REDUCED_SYMMETRIC:
            # D^-0.5 [A + A.T + I] D^-0.5
            pass
        else:       # no normalization
            Adj = A

        x1 = x0.clone()
        for i in range(self._num_layers):
            x1 = self._linear_layers[i](Adj, x1)
        x2 = self._bilinear_layer(Adj, x0, x1)
        return x2


if __name__ == "__main__":
    from dataset.dataset import RefaelDataset
    from torch.utils.data import DataLoader
    from params.parameters import RefaelDatasetParams
    ds = RefaelDataset(RefaelDatasetParams())
    dl = DataLoader(
        dataset=ds,
        batch_size=1,
    )

    module = LayeredBilinearModule(LayeredBilinearModuleParams(ftr_len=ds.len_features))
    # module = BilinearModule(BilinearModuleParams())
    for i, (_A, _D, _x0, _l) in enumerate(dl):
        _x2 = module(_A, _D, _x0)
        e = 0
Beispiel #3
0
            x0 = torch.cat([x0] + list_embed, dim=2)

        x1 = x0
        self._sync()
        for i in range(self._num_layers):
            x1 = self._linear_layers[i](A, x1)
        x2 = self._bilinear_layer(A, x0, x1)
        return x2


if __name__ == "__main__":
    from dataset.datset_sampler import ImbalancedDatasetSampler
    from params.aids_params import AidsAllExternalDataParams, AidsDatasetAllParams
    from dataset.dataset_external_data import ExternalData
    from dataset.dataset_model import BilinearDataset

    ext_train = ExternalData(AidsAllExternalDataParams())
    ds = BilinearDataset(AidsDatasetAllParams(), external_data=ext_train)
    dl = DataLoader(dataset=ds,
                    collate_fn=ds.collate_fn,
                    batch_size=64,
                    sampler=ImbalancedDatasetSampler(ds))
    m_params = LayeredBilinearModuleParams(
        ftr_len=ds.len_features, embed_vocab_dim=ext_train.len_embed())
    m_params.EMBED_DIMS = [20, 20]
    module = LayeredBilinearModule(m_params)
    # module = BilinearModule(BilinearModuleParams())
    for i, (_A, _D, _x0, _l) in enumerate(dl):
        _x2 = module(_A, _D, _x0)
        e = 0
Beispiel #4
0
            if self._gpu:
                A, x0, embed, l = A.cuda(), x0.cuda(), embed.cuda(), l.cuda()
            # print progress
            if not self._nni:
                self._print_progress(batch_index, len_data, job=VALIDATE_JOB)
            output = self._model(A, x0, embed)
            # calculate total loss
            loss_count += self._loss_func(output.squeeze(dim=1).squeeze(dim=1), l.float())
            true_labels += l.tolist()
            pred += output.squeeze(dim=1).squeeze(dim=1).tolist()

        # update loss accuracy
        loss = float(loss_count / len(data_loader))
        # pred_labels = [0 if np.isnan(i) else i for i in pred_labels]
        self._update_loss(loss, job=job)
        self._update_accuracy(pred, true_labels, job=job)
        self._update_auc(pred, true_labels, job=job)
        return loss


if __name__ == '__main__':
    from params.aids_params import AidsDatasetTrainParams, AidsDatasetDevParams, AidsDatasetTestParams

    aids_train_ds = BilinearDataset(AidsDatasetTrainParams())
    aids_dev_ds = BilinearDataset(AidsDatasetDevParams())
    aids_test_ds = BilinearDataset(AidsDatasetTestParams())
    activator = BilinearActivator(
        LayeredBilinearModule(LayeredBilinearModuleParams(ftr_len=aids_train_ds.len_features)),
        BilinearActivatorParams(), aids_train_ds, dev_data=aids_dev_ds, test_data=aids_test_ds)
    activator.train()