示例#1
1
  def test_graph_conv_regression_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'regression', 'GraphConv')

    batch_size = 50
    model = GraphConvModel(len(tasks), batch_size=batch_size, mode='regression')

    model.fit(dataset, nb_epoch=100)
    scores = model.evaluate(dataset, [metric], transformers)
    assert all(s < 0.1 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'],
        rtol=1e-4)
示例#2
0
  def test_graph_conv_atom_features(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'regression', 'Raw', num_tasks=1)

    atom_feature_name = 'feature'
    y = []
    for mol in dataset.X:
      atom_features = []
      for atom in mol.GetAtoms():
        val = np.random.normal()
        mol.SetProp("atom %08d %s" % (atom.GetIdx(), atom_feature_name),
                    str(val))
        atom_features.append(np.random.normal())
      y.append([np.sum(atom_features)])

    featurizer = ConvMolFeaturizer(atom_properties=[atom_feature_name])
    X = featurizer.featurize(dataset.X)
    dataset = dc.data.NumpyDataset(X, np.array(y))
    batch_size = 50
    model = GraphConvModel(
        len(tasks),
        number_atom_features=featurizer.feature_length(),
        batch_size=batch_size,
        mode='regression')

    model.fit(dataset, nb_epoch=1)
    y_pred1 = model.predict(dataset)
    model.save()

    model2 = TensorGraph.load_from_dir(model.model_dir)
    y_pred2 = model2.predict(dataset)
    self.assertTrue(np.allclose(y_pred1, y_pred2))
示例#3
0
  def test_weave_regression_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'regression', 'Weave')

    model = WeaveModel(len(tasks), mode='regression')

    model.fit(dataset, nb_epoch=80)
    scores = model.evaluate(dataset, [metric], transformers)
    assert all(s < 0.1 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'])
示例#4
0
  def test_weave_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'classification', 'Weave')

    model = WeaveModel(len(tasks), mode='classification')

    model.fit(dataset, nb_epoch=50)
    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'])
示例#5
0
  def test_graph_conv_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'classification', 'GraphConv')

    batch_size = 50
    model = GraphConvModel(
        len(tasks), batch_size=batch_size, mode='classification')

    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'])
示例#6
0
  def test_change_loss_function(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'regression', 'GraphConv', num_tasks=1)

    batch_size = 50
    model = GraphConvModel(len(tasks), batch_size=batch_size, mode='regression')

    model.fit(dataset, nb_epoch=1)
    model.save()

    model2 = TensorGraph.load_from_dir(model.model_dir, restore=False)
    dummy_label = model2.labels[-1]
    dummy_ouput = model2.outputs[-1]
    loss = ReduceSum(L2Loss(in_layers=[dummy_label, dummy_ouput]))
    module = model2.create_submodel(loss=loss)
    model2.restore()
    model2.fit(dataset, nb_epoch=1, submodel=module)
示例#7
0
  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'])
示例#8
0
    def test_mpnn_model(self):
        tasks, dataset, transformers, metric = self.get_dataset(
            'classification', 'Weave')

        model = MPNNModel(len(tasks),
                          mode='classification',
                          n_hidden=75,
                          n_atom_feat=75,
                          n_pair_feat=14,
                          T=1,
                          M=1)

        model.fit(dataset, nb_epoch=20)
        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'])
示例#9
0
    def test_change_loss_function_weave(self):
        tasks, dataset, transformers, metric = self.get_dataset('regression',
                                                                'Weave',
                                                                num_tasks=1)

        batch_size = 50
        model = WeaveModel(len(tasks),
                           batch_size=batch_size,
                           mode='regression',
                           use_queue=False)

        model.fit(dataset, nb_epoch=1)
        model.save()

        model2 = TensorGraph.load_from_dir(model.model_dir, restore=False)
        dummy_label = model2.labels[-1]
        dummy_ouput = model2.outputs[-1]
        loss = ReduceSum(L2Loss(in_layers=[dummy_label, dummy_ouput]))
        module = model2.create_submodel(loss=loss)
        model2.restore()
        model2.fit(dataset, nb_epoch=1, submodel=module)
示例#10
0
  def test_mpnn_regression_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'regression', 'Weave')

    model = MPNNModel(
        len(tasks),
        mode='regression',
        n_hidden=75,
        n_atom_feat=75,
        n_pair_feat=14,
        T=1,
        M=1)

    model.fit(dataset, nb_epoch=50)
    scores = model.evaluate(dataset, [metric], transformers)
    assert all(s < 0.1 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'])
示例#11
0
    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'])
示例#12
0
  def test_mpnn_regression_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'regression', 'Weave')

    model = MPNNModel(
        len(tasks),
        mode='regression',
        n_hidden=75,
        n_atom_feat=75,
        n_pair_feat=14,
        T=1,
        M=1)

    model.fit(dataset, nb_epoch=50)
    scores = model.evaluate(dataset, [metric], transformers)
    assert all(s < 0.1 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'])
示例#13
0
  def test_mpnn_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'classification', 'Weave')

    model = MPNNModel(
        len(tasks),
        mode='classification',
        n_hidden=75,
        n_atom_feat=75,
        n_pair_feat=14,
        T=1,
        M=1)

    model.fit(dataset, nb_epoch=20)
    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'])
示例#14
0
    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'])
示例#15
0
  def test_save_load(self):
    """Test SaScoreModel anc be saved and loaded"""
    n_samples = 10
    n_features = 3
    n_tasks = 1

    # Create a dataset and an input function for processing it.

    np.random.seed(123)
    X = np.random.rand(n_samples, 2, n_features)
    y = np.zeros((n_samples, n_tasks))
    dataset = deepchem.data.NumpyDataset(X, y)

    model = deepchem.models.ScScoreModel(n_features, dropouts=0)

    model.fit(dataset, nb_epoch=1)
    pred1 = model.predict(dataset)

    model.save()
    model = TensorGraph.load_from_dir(model.model_dir)

    pred2 = model.predict(dataset)
    for m1, m2 in zip(pred1, pred2):
      self.assertTrue(np.all(m1 == m2))
示例#16
0
    def test_save_load(self):
        """Test SaScoreModel anc be saved and loaded"""
        n_samples = 10
        n_features = 3
        n_tasks = 1

        # Create a dataset and an input function for processing it.

        np.random.seed(123)
        X = np.random.rand(n_samples, 2, n_features)
        y = np.zeros((n_samples, n_tasks))
        dataset = deepchem.data.NumpyDataset(X, y)

        model = deepchem.models.ScScoreModel(n_features, dropouts=0)

        model.fit(dataset, nb_epoch=1)
        pred1 = model.predict(dataset)

        model.save()
        model = TensorGraph.load_from_dir(model.model_dir)

        pred2 = model.predict(dataset)
        for m1, m2 in zip(pred1, pred2):
            self.assertTrue(np.all(m1 == m2))
示例#17
0
  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'])