def test_ae_with_embedding_at_start(self):
    cols = ['feat1', 'feat2']
    ds = ds_from_df(self.df, y_columns=cols, x_columns=cols, cat_columns=['cat_1', 'cat_2'])
    (ds_tr, ds_val, _) = data.train_test_split_dataset(ds)
    db = create_databunch(ds_tr, ds_val, None, batch_size=40, device='cpu')
    df_tr = ds_tr.to_df()
    input_size = ds_tr.x.shape[1]
    print(input_size, ds_tr.y.shape[1])
    ann_structure = [10, 4, 1]
    embedding_module = Embedding([11, 11], embedding_dropout=0.1)
    ann_model = Autoencoder(input_size=input_size, ann_structure=ann_structure, embedding_module=embedding_module, embeding_position='start')
    ann_model.apply(xavier_init_uniform)
    learn = Learner(db, ann_model, loss_func=torch.nn.MSELoss())
    (y_hat, _) = dev_to_np(learn.get_preds(DatasetType.Train))
    target_cols = ['feat1_target', 'feat2_target']
    e_init = mse(df_tr[target_cols].values, y_hat)
    learn.fit(1)
    (y_hat, _) = dev_to_np(learn.get_preds(DatasetType.Train))
    e_end = mse(df_tr[target_cols].values, y_hat)
    self.assertLess(e_end, e_init)
def test_ae_with_embedding_at_start(self):
    cols = ['feat1', 'feat2']
    ds = ds_from_df(self.df, y_columns=cols, x_columns=cols, cat_columns=['cat_1', 'cat_2'])
    (ds_tr, ds_val, _) = data.train_test_split_dataset(ds)
    db = create_databunch(ds_tr, ds_val, None, batch_size=40, device='cpu')
    df_tr = ds_tr.to_df()
    input_size = ds_tr.x.shape[1]
    print(input_size, ds_tr.y.shape[1])
    ann_structure = [10, 4, 1]
    embedding_module = Embedding([11, 11], embedding_dropout=0.1)
    ann_model = Autoencoder(input_size=input_size, ann_structure=ann_structure, embedding_module=embedding_module, embeding_position='start')
    ann_model.apply(xavier_init_uniform)
    learn = Learner(db, ann_model, loss_func=torch.nn.MSELoss())
    (y_hat, _) = dev_to_np(learn.get_preds(DatasetType.Train))
    target_cols = ['feat1_target', 'feat2_target']
    e_init = mse(df_tr[target_cols].values, y_hat)
    learn.fit(1)
    (y_hat, _) = dev_to_np(learn.get_preds(DatasetType.Train))
    e_end = mse(df_tr[target_cols].values, y_hat)
    self.assertLess(e_end, e_init)