def test_FullMTL(self): metrics = ['rmse'] ddataset = SD.SyntheticDataCreator(num_tasks=3, cellsPerTask=500, drugsPerTask=10, function="gauss", normalize=False, noise=1, graph=False, test_split=0.3) dataset.prepare_data() exp_folder = "fullMtlGP_test" exp = ModelTraining(exp_folder) methods = [ MtlGP.GPyFullMTL(num_iters=50, length_scale=20, noise_covar=.9, n_inducing_points=500, num_tasks=3) ] exp.execute(dataset, methods, metrics, nruns=1) df = exp.getResultsWrapper() rmses = df['Value'].values for rmse in rmses: assert rmse < 1.5 # arbitrary threshold for reasonable prediction
def synthetic(n_examples, **kwargs): ''' Run a synthetic experiment using n_examples examples ''' np.random.seed(42) config = synthetic_config.copy() config.update(kwargs) assert config.get( 'vocab_size') is not None, "Must specify synthetic data vocab_size" sampler = SyntheticData(**config) c, a, y = sampler.sample_truth(n_examples) t = sampler.sample_text((c, a, y)) mask = sampler.mar(a, (c, y, t)) debug = kwargs.get('debug', False) return experiment(c, a, y, t, mask, debug=debug)
def synthetic(n_examples, n_train, **kwargs): ''' Run a synthetic experiment using n_examples examples in target dataset p(A*, C, Y) and n_train examples of external data to estimate p(A*, A) ''' np.random.seed(42) proxy_i = 1 confound_i = ( 0, 2, ) config = synthetic_config.copy() config.update(kwargs) assert config.get( 'vocab_size') is not None, "Must specify synthetic data vocab_size" sampler = SyntheticData(**config) truth = sampler.sample_truth(n_examples) truth_t = sampler.sample_text(truth[proxy_i]) external = sampler.sample_truth(n_train) external_t = sampler.sample_text(external[proxy_i]) debug = kwargs.get('debug', False) return train_adjust(np.concatenate( (np.array(external), np.transpose(external_t)), axis=0), np.concatenate( (np.array(truth), np.transpose(truth_t)), axis=0), proxy_i, confound_i, debug=debug)
def test_NN(self): ddataset = SD.SyntheticDataCreator(num_tasks=3, cellsPerTask=400, drugsPerTask=10, function="cosine", normalize=True, noise=1, graph=False, test_split=0.3) dataset.prepare_data() exp_folder = "NN_test" exp = ModelTraining(exp_folder) methods = [FeedForwardNN([25, 25], 'relu', epochs=60, lr=1e-3)] exp.execute(dataset, methods, metrics, nruns=1) df = exp.getResultsWrapper() rmses = df['Value'].values for rmse in rmses: assert rmse < 1.5 # arbitrary threshold for reasonable prediction
import sys sys.path.append('../') from design import ModelTraining from methods.regressor.FFNN import FeedForwardNN import methods.mtl.MTL_GP as MtlGP from methods.knn.KNN import KNN_Normalized from datasets import SyntheticData as SD import methods.mtl.NCF_MTL as NCF_MTL from methods.matrix_factorization.MF import SVD_MF, NonNegative_MF if __name__ == '__main__': dataset = SD.SyntheticDataCreator(num_tasks=3,cellsPerTask=400, drugsPerTask=10, function="cosine", normalize=False, noise=.5, graph=False, test_split=0.3) dataset.prepare_data() hyperparams_mtlmlp = {'batch_size': 64, 'epochs': 150, 'layers': '[64,32,16,8]', \ 'learner': 'adam', 'lr': .001,'mlp_lr': .001, 'num_factors': 10, \ 'reg_layers': '[0,0,0,.01]', 'reg_mf': 0.01, 'verbose': 1} hyperparams_mtlmf = {'batch_size': 64, 'epochs': 150, 'layers': '[64,32,16,8]', \ 'learner': 'adam', 'lr': .001,'mf_lr': .001, 'num_factors': 10, \ 'reg_layers': '[0,0,0,.01]', 'reg_mf': 0.01, 'verbose': 1} methods = [MtlGP.HadamardMTL(num_iters=150, length_scale=57, noise_covar=.24, n_inducing_points=1000, \ composite=False, learning_rate=.07, validate=False,bias=False,stabilize=True), MtlGP.GPyFullMTL(num_iters=72, length_scale=58.828, noise_covar=0.31587, n_inducing_points=500, num_tasks=3, learning_rate=0.02729), NCF_MTL.Neural_Collaborative_Filtering_FeaturesMTLMLP(hyperparams_mtlmlp,'MTL NCF MLP', 'feature_based'), NCF_MTL.Neural_Collaborative_Filtering_FeaturesMTLMF(hyperparams_mtlmf,'NCF_MTL_MF', 'feature_based'), SVD_MF(n_factors=10),