Commit 83a66d62 authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

Merge pull request #167 from rbharath/featurization_fix

Fixes to featurization code
parents 3752f9da eaf30e02
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -397,12 +397,12 @@ def _df_to_numpy(df, feature_types, tasks):
  # perform common train/test split across all tasks
  n_samples = df.shape[0]
  n_tasks = len(tasks)
  n_features = None
  y = df[tasks].values
  y = np.reshape(y, (n_samples, n_tasks))
  w = np.ones((n_samples, n_tasks))
  missing = np.zeros_like(y).astype(int)
  tensors = []
  feature_shape = None
  for ind in range(n_samples):
    datapoint = df.iloc[ind]
    feature_list = []
@@ -414,13 +414,17 @@ def _df_to_numpy(df, feature_types, tasks):
        if features[feature_ind] == "":
          features[feature_ind] = 0.
      features = features.astype(float)
      n_features = features.shape[0]
      if feature_shape is None:
        feature_shape = features.shape
    except ValueError:
      missing[ind, :] = 1
      continue
    for task in range(n_tasks):
      if y[ind, task] == "":
        missing[ind, task] = 1
    if features.shape != feature_shape:
      missing[ind, :] = 1
      continue
    tensors.append(features)
  x = np.stack(tensors)
  sorted_ids = df["mol_id"]
+4 −1
Original line number Diff line number Diff line
@@ -141,7 +141,10 @@ class Featurizer(object):
      for i, mol in enumerate(mols):
        if verbosity is not None and i % log_every_n == 0:
          log("Featurizing %d / %d" % (i, len(mols)))
        features = [self._featurize(mol) for mol in mols]
        if mol is not None:
          features.append(self._featurize(mol))
        else:
          features.append(np.array([]))

    if self.conformers:
      features = self.conformer_container(mols, features)
+0 −3
Original line number Diff line number Diff line
@@ -134,8 +134,6 @@ class Metric(object):
    Returns:
      A numpy array containing metric values for each task.
    """
    print("y_true.shape, y_pred.shape")
    print(y_true.shape, y_pred.shape)
    assert y_true.shape[0] == y_pred.shape[0] == w.shape[0]
    n_samples, n_tasks = y_true.shape[0], y_true.shape[1] 
    if self.mode == "classification":
@@ -175,7 +173,6 @@ class Metric(object):
    Raises:
      NotImplementedError: If metric_str is not in METRICS.
    """
    print("compute_singletask_metric()")
    y_true = np.array(np.squeeze(y_true[w != 0]))
    y_pred = np.array(np.squeeze(y_pred[w != 0]))
    if len(y_true.shape) == 0:
+0 −1
Original line number Diff line number Diff line
@@ -160,7 +160,6 @@ class TensorflowGraph(object):
    return tf.name_scope(self._name_scopes[name])

  def add_training_cost(self):
    print(self.output)
    with self.graph.as_default():
      self.require_attributes(['output', 'labels', 'weights'])
      epsilon = 1e-3  # small float to avoid dividing by zero