Commit ba82f3b3 authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

Cleanup and test fix

parent d2aa9a97
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -174,10 +174,6 @@ def get_task_support(dataset, n_episodes, n_pos, n_neg, task, log_every_n=50):
    if episode % log_every_n == 0:
      print("Sampling support %d" % episode)
    # No replacement allowed for supports
    ############################################################# DEBUG
    print("len(pos_mols), n_pos, len(neg_mols), n_neg")
    print(len(pos_mols), n_pos, len(neg_mols), n_neg)
    ############################################################# DEBUG
    pos_ids = np.random.choice(len(pos_mols), (n_pos,), replace=False)
    neg_ids = np.random.choice(len(neg_mols), (n_neg,), replace=False)
    pos_inds, neg_inds = pos_mols[pos_ids], neg_mols[neg_ids]
+12 −18
Original line number Diff line number Diff line
@@ -667,9 +667,8 @@ class TestOverfit(test_util.TensorFlowTestCase):
      n_pos = 6
      n_neg = 4
      test_batch_size = 10
      n_train_trials = 60
      n_train_trials = 80
      support_batch_size = n_pos + n_neg
      replace = False
      
      # Load mini log-solubility dataset.
      featurizer = dc.feat.ConvMolFeaturizer()
@@ -705,10 +704,9 @@ class TestOverfit(test_util.TensorFlowTestCase):
          verbosity="high")

        # Fit trained model. Dataset has 6 positives and 4 negatives, so set
        # n_pos/n_neg accordingly.  Set replace to false to ensure full dataset
        # is always passed in to support.
        model.fit(dataset, n_trials=n_train_trials, n_pos=n_pos,
                  n_neg=n_neg, replace=False)
        # n_pos/n_neg accordingly.
        model.fit(dataset, n_episodes_per_epoch=n_train_trials, n_pos=n_pos,
                  n_neg=n_neg)
        model.save()

        # Eval model on train. Dataset has 6 positives and 4 negatives, so set
@@ -738,8 +736,7 @@ class TestOverfit(test_util.TensorFlowTestCase):
      n_neg = 4
      test_batch_size = 10
      support_batch_size = n_pos + n_neg
      n_train_trials = 60
      replace = False
      n_train_trials = 80
      
      # Load mini log-solubility dataset.
      featurizer = dc.feat.ConvMolFeaturizer()
@@ -780,10 +777,9 @@ class TestOverfit(test_util.TensorFlowTestCase):
          verbosity="high")

        # Fit trained model. Dataset has 6 positives and 4 negatives, so set
        # n_pos/n_neg accordingly.  Set replace to false to ensure full dataset
        # is always passed in to support.
        model.fit(dataset, n_trials=n_train_trials, n_pos=n_pos, n_neg=n_neg,
                  replace=False)
        # n_pos/n_neg accordingly.
        model.fit(dataset, n_episodes_per_epoch=n_train_trials, n_pos=n_pos,
                  n_neg=n_neg)
        model.save()

        # Eval model on train. Dataset has 6 positives and 4 negatives, so set
@@ -811,8 +807,7 @@ class TestOverfit(test_util.TensorFlowTestCase):
      n_neg = 4
      test_batch_size = 10
      support_batch_size = n_pos + n_neg
      n_train_trials = 60
      replace = False
      n_train_trials = 80
      
      # Load mini log-solubility dataset.
      featurizer = dc.feat.ConvMolFeaturizer()
@@ -853,11 +848,10 @@ class TestOverfit(test_util.TensorFlowTestCase):
          verbosity="high")

        # Fit trained model. Dataset has 6 positives and 4 negatives, so set
        # n_pos/n_neg accordingly.  Set replace to false to ensure full dataset
        # is always passed in to support.
        # n_pos/n_neg accordingly.

        model.fit(dataset, n_trials=n_train_trials, n_pos=n_pos, n_neg=n_neg,
                  replace=False)
        model.fit(dataset, n_episodes_per_epoch=n_train_trials, n_pos=n_pos,
                  n_neg=n_neg)
        model.save()

        # Eval model on train. Dataset has 6 positives and 4 negatives, so set
+1 −23
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ class SupportGraphClassifier(Model):
    feed_total, run_total, test_total = 0, 0, 0
    # Create different support sets
    support_generator = SupportGenerator(dataset, range(n_tasks),
        n_pos, n_neg, n_trials, replace)
        n_pos, n_neg, n_trials)
    recent_losses = []
    for ind, (task, support) in enumerate(support_generator):
      if ind % log_every_n_samples == 0:
@@ -204,10 +204,6 @@ class SupportGraphClassifier(Model):
      for ind, (task, support, test) in enumerate(episode_generator):
        if ind % log_every_n_samples == 0:
          print("Epoch %d, Sample %d from task %s" % (epoch, ind, str(task)))
          ############################################################### DEBUG
          print("task, len(support), len(test)")
          print(task, len(support), len(test))
          ############################################################### DEBUG
        # Get batch to try it out on
        feed_start = time.time()
        feed_dict = self.construct_feed_dict(test, support)
@@ -402,8 +398,6 @@ class SupportGraphClassifier(Model):
      Number of negative samples per support.
    exclude_support: bool, optional
      Whether support set should be excluded when computing model accuracy.
    replace: bool, optional
      Whether or not to use replacement when sampling supports.
    """
    # Get batches
    test_tasks = range(len(dataset.get_task_names()))
@@ -420,22 +414,6 @@ class SupportGraphClassifier(Model):
        print("Keeping support datapoints for eval.")
        task_dataset = get_task_dataset(dataset, task)
      y_pred = self.predict_proba(support, task_dataset)
      ################################################################ DEBUG
      task_y = dataset.y[:, task]
      task_w = dataset.w[:, task]
      print("Number of y elements (including missing data)")
      print(len(task_y))
      task_y = task_y[task_w != 0]
      print("Number of y elements (excluding missing data)")
      print(len(task_y))
      print("Verifying that no elements were dropped.")
      print("len(task_y), len(support), len(task_dataset)")
      print(len(task_y), len(support), len(task_dataset))
      assert len(task_y) == len(support) + len(task_dataset)
      print("Verifying that task_dataset doesn't overlap with support.")
      for task_id in task_dataset.ids:
        assert task_id not in set(support.ids)
      ################################################################ DEBUG
      task_scores[task].append(metric.compute_metric(
          task_dataset.y, y_pred, task_dataset.w))