Commit 6fe6e3a9 authored by Ubuntu's avatar Ubuntu
Browse files

yapfed

parent e39c4a01
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ def featurize_smiles_df(df, featurizer, field, log_every_N=1000, verbose=True):
  features = [elt for (is_valid, elt) in zip(valid_inds, features) if is_valid]
  return np.squeeze(np.array(features)), valid_inds


def featurize_smiles_np(arr, featurizer, log_every_N=1000, verbose=True):
  """Featurize individual compounds in a numpy array.

@@ -100,7 +101,9 @@ def featurize_smiles_np(arr, featurizer, log_every_N=1000, verbose=True):
      [1 if elt.size > 0 else 0 for elt in features], dtype=bool)
  features = [elt for (is_valid, elt) in zip(valid_inds, features) if is_valid]
  features = np.squeeze(np.array(features))
  return features.reshape(-1,)
  return features.reshape(
      -1,)


def get_user_specified_features(df, featurizer, verbose=True):
  """Extract and merge user specified features. 
+4 −4
Original line number Diff line number Diff line
@@ -931,8 +931,8 @@ class DiskDataset(Dataset):
          if indices_count + num_shard_elts >= len(indices):
            break
        # Need to offset indices to fit within shard_size
        shard_inds = indices[indices_count:indices_count +
                             num_shard_elts] - count
        shard_inds = indices[indices_count:
                             indices_count + num_shard_elts] - count
        X_sel = X[shard_inds]
        # Handle the case of datasets with y/w missing
        if y is not None:
+6 −4
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ def pearson_r2_score(y, y_pred):
  """Computes Pearson R^2 (square of Pearson correlation)."""
  return pearsonr(y, y_pred)[0]**2


def prc_auc_score(y, y_pred):
  """Compute area under precision-recall curve"""
  assert y_pred.shape == y.shape
@@ -110,13 +111,14 @@ def kappa_score(y_true, y_pred):
  assert len(y_true) == len(y_pred), 'Number of examples does not match.'
  yt = np.asarray(y_true, dtype=int)
  yp = np.asarray(y_pred, dtype=int)
  assert np.array_equal(np.unique(yt), [0, 1]), (
      'Class labels must be binary: %s' % np.unique(yt))
  assert np.array_equal(
      np.unique(yt), [0,
                      1]), ('Class labels must be binary: %s' % np.unique(yt))
  observed_agreement = np.true_divide(
      np.count_nonzero(np.equal(yt, yp)), len(yt))
  expected_agreement = np.true_divide(
      np.count_nonzero(yt == 1) * np.count_nonzero(yp == 1) + np.count_nonzero(
          yt == 0) * np.count_nonzero(yp == 0), len(yt)**2)
      np.count_nonzero(yt == 1) * np.count_nonzero(yp == 1) +
      np.count_nonzero(yt == 0) * np.count_nonzero(yp == 0), len(yt)**2)
  kappa = np.true_divide(observed_agreement - expected_agreement,
                         1.0 - expected_agreement)
  return kappa
+6 −5
Original line number Diff line number Diff line
@@ -151,7 +151,8 @@ class WeaveTensorGraph(TensorGraph):
          C0, C1 = np.meshgrid(np.arange(n_atoms), np.arange(n_atoms))
          atom_to_pair.append(
              np.transpose(
                  np.array([C1.flatten() + start, C0.flatten() + start])))
                  np.array([C1.flatten() + start,
                            C0.flatten() + start])))
          # number of pairs for each atom
          pair_split.extend(C1.flatten() + start)
          start = start + n_atoms