torchdrug.metrics#

Basic Metrics#

AUROC#

area_under_roc(pred, target)[source]#

Area under receiver operating characteristic curve (ROC).

Parameters
  • pred (Tensor) – predictions of shape \((n,)\)

  • target (Tensor) – binary targets of shape \((n,)\)

AUROC()#

alias of torchdrug.metrics.area_under_roc

AUPRC#

area_under_prc(pred, target)[source]#

Area under precision-recall curve (PRC).

Parameters
  • pred (Tensor) – predictions of shape \((n,)\)

  • target (Tensor) – binary targets of shape \((n,)\)

AUPRC()#

alias of torchdrug.metrics.area_under_prc

R2#

r2(pred, target)[source]#

\(R^2\) regression score.

Parameters
  • pred (Tensor) – predictions of shape \((n,)\)

  • target (Tensor) – targets of shape \((n,)\)

Accuracy#

accuracy(pred, target)[source]#

Classification accuracy.

Suppose there are \(N\) sets and \(C\) categories.

Parameters
  • pred (Tensor) – prediction of shape \((N, C)\)

  • target (Tensor) – target of shape \((N,)\)

Matthews Correlation Coefficient#

matthews_corrcoef(pred, target)[source]#

Matthews correlation coefficient between prediction and target.

Definition follows matthews_corrcoef for K classes in sklearn. For details, see: https://scikit-learn.org/stable/modules/model_evaluation.html#matthews-corrcoef

Parameters
  • pred (Tensor) – prediction of shape :math: (N, K)

  • target (Tensor) – target of shape :math: (N,)

Pearson Correlation Coefficient#

pearsonr(pred, target)[source]#

Pearson correlation between prediction and target.

Parameters
  • pred (Tensor) – prediction of shape :math: (N,)

  • target (Tensor) – target of shape :math: (N,)

Spearman’s Rank Correlation Coefficient#

spearmanr(pred, target)[source]#

Spearman correlation between prediction and target.

Parameters
  • pred (Tensor) – prediction of shape :math: (N,)

  • target (Tensor) – target of shape :math: (N,)

Variadic Accuracy#

variadic_accuracy(input, target, size)[source]#

Classification accuracy for categories with variadic sizes.

Suppose there are \(N\) samples, and the number of categories in all samples is summed to \(B\).

Parameters
  • input (Tensor) – prediction of shape \((B,)\)

  • target (Tensor) – target of shape \((N,)\). Each target is a relative index in a sample.

  • size (Tensor) – number of categories of shape \((N,)\)

Variadic Area Under ROC#

variadic_area_under_roc(pred, target, size)[source]#

Area under receiver operating characteristic curve (ROC) for sets with variadic sizes.

Suppose there are \(N\) sets, and the sizes of all sets are summed to \(B\).

Parameters
  • pred (Tensor) – prediction of shape \((B,)\)

  • target (Tensor) – target of shape \((B,)\).

  • size (Tensor) – size of sets of shape \((N,)\)

Variadic Area Under PRC#

variadic_area_under_prc(pred, target, size)[source]#

Area under precision-recall curve (PRC) for sets with variadic sizes.

Suppose there are \(N\) sets, and the sizes of all sets are summed to \(B\).

Parameters
  • pred (Tensor) – prediction of shape \((B,)\)

  • target (Tensor) – target of shape \((B,)\).

  • size (Tensor) – size of sets of shape \((N,)\)

Variadic Top Precision#

variadic_top_precision(pred, target, size, k)[source]#

Top-k precision for sets with variadic sizes.

Suppose there are \(N\) sets, and the sizes of all sets are summed to \(B\).

Parameters
  • pred (Tensor) – prediction of shape \((B,)\)

  • target (Tensor) – target of shape \((B,)\)

  • size (Tensor) – size of sets of shape \((N,)\)

  • k (LongTensor) – the k in “top-k” for different sets of shape \((N,)\)

F1 Max#

f1_max(pred, target)[source]#

F1 score with the optimal threshold.

This function first enumerates all possible thresholds for deciding positive and negative samples, and then pick the threshold with the maximal F1 score.

Parameters
  • pred (Tensor) – predictions of shape \((B, N)\)

  • target (Tensor) – binary targets of shape \((B, N)\)

Chemical Metrics#

SA#

SA(pred)[source]#

Synthetic accesibility score.

Parameters

pred (PackedMolecule) – molecules to evaluate

QED#

QED(pred)[source]#

Quantitative estimation of drug-likeness.

Parameters

pred (PackedMolecule) – molecules to evaluate

Chemical Validity#

chemical_validity(pred)[source]#

Chemical validity of molecules.

Parameters

pred (PackedMolecule) – molecules to evaluate

LogP#

logP(pred)[source]#

Logarithm of partition coefficient between octanol and water for a compound.

Parameters

pred (PackedMolecule) – molecules to evaluate

Penalized LogP#

penalized_logP(pred)[source]#

Logarithm of partition coefficient, penalized by cycle length and synthetic accessibility.

Parameters

pred (PackedMolecule) – molecules to evaluate