def test_dag_regression_uncertainty(): import tensorflow as tf np.random.seed(1234) tf.random.set_seed(1234) tasks, dataset, transformers, metric = get_dataset('regression', 'GraphConv') batch_size = 10 max_atoms = max([mol.get_num_atoms() for mol in dataset.X]) transformer = dc.trans.DAGTransformer(max_atoms=max_atoms) dataset = transformer.transform(dataset) model = DAGModel(len(tasks), max_atoms=max_atoms, mode='regression', learning_rate=0.003, batch_size=batch_size, use_queue=False, dropout=0.05, uncertainty=True) model.fit(dataset, nb_epoch=750) # Predict the output and uncertainty. pred, std = model.predict_uncertainty(dataset) mean_error = np.mean(np.abs(dataset.y - pred)) mean_value = np.mean(np.abs(dataset.y)) mean_std = np.mean(std) # The DAG models have high error with dropout # Despite a lot of effort tweaking it , there appears to be # a limit to how low the error can go with dropout. #assert mean_error < 0.5 * mean_value assert mean_error < .7 * mean_value assert mean_std > 0.5 * mean_error assert mean_std < mean_value
def test_dag_regression_uncertainty(self): tasks, dataset, transformers, metric = self.get_dataset( 'regression', 'GraphConv') max_atoms = max([mol.get_num_atoms() for mol in dataset.X]) transformer = dc.trans.DAGTransformer(max_atoms=max_atoms) dataset = transformer.transform(dataset) model = DAGModel( len(tasks), max_atoms=max_atoms, mode='regression', learning_rate=0.002, use_queue=False, dropout=0.1, uncertainty=True) model.fit(dataset, nb_epoch=100) # Predict the output and uncertainty. pred, std = model.predict_uncertainty(dataset) mean_error = np.mean(np.abs(dataset.y - pred)) mean_value = np.mean(np.abs(dataset.y)) mean_std = np.mean(std) assert mean_error < 0.5 * mean_value assert mean_std > 0.5 * mean_error assert mean_std < mean_value
def test_dag_regression_uncertainty(self): tasks, dataset, transformers, metric = self.get_dataset( 'regression', 'GraphConv') max_atoms = max([mol.get_num_atoms() for mol in dataset.X]) transformer = dc.trans.DAGTransformer(max_atoms=max_atoms) dataset = transformer.transform(dataset) model = DAGModel( len(tasks), max_atoms=max_atoms, mode='regression', learning_rate=0.002, use_queue=False, dropout=0.1, uncertainty=True) model.fit(dataset, nb_epoch=100) # Predict the output and uncertainty. pred, std = model.predict_uncertainty(dataset) mean_error = np.mean(np.abs(dataset.y - pred)) mean_value = np.mean(np.abs(dataset.y)) mean_std = np.mean(std) assert mean_error < 0.5 * mean_value assert mean_std > 0.5 * mean_error assert mean_std < mean_value
def test_dag_model(): tasks, dataset, transformers, metric = get_dataset('classification', 'GraphConv') max_atoms = max([mol.get_num_atoms() for mol in dataset.X]) transformer = dc.trans.DAGTransformer(max_atoms=max_atoms) dataset = transformer.transform(dataset) model = DAGModel(len(tasks), max_atoms=max_atoms, mode='classification', learning_rate=0.001) model.fit(dataset, nb_epoch=30) scores = model.evaluate(dataset, [metric], transformers) assert scores['mean-roc_auc_score'] >= 0.9
def test_dag_regression_model(self): tasks, dataset, transformers, metric = self.get_dataset( 'regression', 'GraphConv') max_atoms = max([mol.get_num_atoms() for mol in dataset.X]) transformer = dc.trans.DAGTransformer(max_atoms=max_atoms) dataset = transformer.transform(dataset) model = DAGModel(len(tasks), max_atoms=max_atoms, mode='regression', learning_rate=0.003, use_queue=False) model.fit(dataset, nb_epoch=100) scores = model.evaluate(dataset, [metric], transformers) assert all(s < 0.15 for s in scores['mean_absolute_error'])
def test_dag_regression_model(): import tensorflow as tf np.random.seed(1234) tf.random.set_seed(1234) tasks, dataset, transformers, metric = get_dataset('regression', 'GraphConv') max_atoms = max([mol.get_num_atoms() for mol in dataset.X]) transformer = dc.trans.DAGTransformer(max_atoms=max_atoms) dataset = transformer.transform(dataset) model = DAGModel(len(tasks), max_atoms=max_atoms, mode='regression', learning_rate=0.003) model.fit(dataset, nb_epoch=100) scores = model.evaluate(dataset, [metric], transformers) assert scores['mean_absolute_error'] < 0.15
def test_dag_model(self): tasks, dataset, transformers, metric = self.get_dataset( 'classification', 'GraphConv') batch_size = 10 max_atoms = max([mol.get_num_atoms() for mol in dataset.X]) transformer = dc.trans.DAGTransformer(max_atoms=max_atoms) dataset = transformer.transform(dataset) model = DAGModel(len(tasks), max_atoms=max_atoms, mode='classification', learning_rate=0.03, batch_size=batch_size, use_queue=False) model.fit(dataset, nb_epoch=40) scores = model.evaluate(dataset, [metric], transformers) assert scores['mean-roc_auc_score'] >= 0.9
def test_dag_model(self): tasks, dataset, transformers, metric = self.get_dataset( 'classification', 'GraphConv') max_atoms = max([mol.get_num_atoms() for mol in dataset.X]) transformer = dc.trans.DAGTransformer(max_atoms=max_atoms) dataset = transformer.transform(dataset) model = DAGModel( len(tasks), max_atoms=max_atoms, mode='classification', use_queue=False) model.fit(dataset, nb_epoch=10) scores = model.evaluate(dataset, [metric], transformers) assert scores['mean-roc_auc_score'] >= 0.9 model.save() model = TensorGraph.load_from_dir(model.model_dir) scores2 = model.evaluate(dataset, [metric], transformers) assert np.allclose(scores['mean-roc_auc_score'], scores2['mean-roc_auc_score'])
def test_dag_model(self): tasks, dataset, transformers, metric = self.get_dataset( 'classification', 'GraphConv') max_atoms = max([mol.get_num_atoms() for mol in dataset.X]) transformer = dc.trans.DAGTransformer(max_atoms=max_atoms) dataset = transformer.transform(dataset) model = DAGModel( len(tasks), max_atoms=max_atoms, mode='classification', use_queue=False) model.fit(dataset, nb_epoch=10) scores = model.evaluate(dataset, [metric], transformers) assert scores['mean-roc_auc_score'] >= 0.9 model.save() model = TensorGraph.load_from_dir(model.model_dir) scores2 = model.evaluate(dataset, [metric], transformers) assert np.allclose(scores['mean-roc_auc_score'], scores2['mean-roc_auc_score'])
def test_dag_regression_model(self): tasks, dataset, transformers, metric = self.get_dataset( 'regression', 'GraphConv') max_atoms = max([mol.get_num_atoms() for mol in dataset.X]) transformer = dc.trans.DAGTransformer(max_atoms=max_atoms) dataset = transformer.transform(dataset) model = DAGModel( len(tasks), max_atoms=max_atoms, mode='regression', learning_rate=0.003, use_queue=False) model.fit(dataset, nb_epoch=100) scores = model.evaluate(dataset, [metric], transformers) assert all(s < 0.15 for s in scores['mean_absolute_error']) model.save() model = TensorGraph.load_from_dir(model.model_dir) scores2 = model.evaluate(dataset, [metric], transformers) assert np.allclose(scores['mean_absolute_error'], scores2['mean_absolute_error'])
nb_epoch = 10 model = DAGModel( n_tasks=n_tasks, max_atoms=max_atoms, n_atom_feat=n_atom_feat, n_graph_feat=n_graph_feat, mode="regression", batch_size=batch_size, learning_rate=1e-3, use_queue=False, model_dir="/home/rod/Dropbox/Quimica/Analysis/ANalisis/Borradores/DAGModel/" ) #To prevent overfitting # Fit trained model print("Fitting model") model.fit(train_dataset, nb_epoch=nb_epoch) model.save() print("Evaluating model") train_scores = model.evaluate(train_dataset, [metric]) valid_scores = model.evaluate(valid_dataset, [metric]) print("Train scores") print(train_scores) print("Validation scores") print(valid_scores) """ #Check model predictions from rdkit import Chem smiles = ['COC(C)(C)CCCC(C)CC=CC(C)=CC(=O)OC(C)C', 'CCOC(=O)CC',