Callbacks for templates
/home/dmai/miniconda3/envs/mrl/lib/python3.7/importlib/_bootstrap.py:219: RuntimeWarning: to-Python converter for boost::shared_ptr<RDKit::FilterCatalogEntry const> already registered; second conversion method ignored.
  return f(*args, **kwds)

Template Callback

The TemplateCallback class is used by the Environment to interface with a Template during training.

Templates serve two roles during training - filtering and scoring of samples

Filtering

Templates filter all samples added to the Buffer and sampled during each batch. If the argument prefilter=True is passed to the template callback, the template will remove all samples that fail the template's hard filters. If prefilter=False is passed, Template.validate will be used to remove invalid compounds, but will ignore compounds that violate the hard filters

Scoring

If the Template has any soft filters, those filters will be used to score compounds each batch. The aggregate soft filter score will be multiplied by TemplateCallback.weight and added to the total reward

class TemplateCallback[source]

TemplateCallback(template=None, sample_name='samples', weight=1.0, track=True, prefilter=True, do_filter=True) :: Callback

TemplateCallback - callback wrapper for Template class

Inputs:

  • template Template: template to use

  • sample_name str: BatchState attribute to grab samples from

  • weight float: weight used to scale template soft filter score

  • track bool: if True, template results are added to the batch log and metric log

  • prefilter bool: if True, samples that fail hard filters in the template are removed

  • do_filter bool: controls if filtering is done at aall

Contrastive Template

The ContrastiveTemplate class applies a template to tasks based around comparing input and output compounds (ie making relative improvements to a compound's properties).

During filtering, the contrastive template will keep samples where both input and output compounds pass the filters.

Contrastive templates also use a similarity function to impose a similarity constraint on sample pairs (ie output compound must have a similarity of X to the input compound).

One consideration in using contrastive scores is how to properly scale contrastive scores. If we have a score with a maximum value of 1, a contrastive sample pair where the score goes from 0.8 to 1 should get the same reward as a sample pair where the score goes from 0.6 to 1. In both cases, the model maximized the output score to the greatest extent possible. To do this, we can scale the reward differences by the maximum possible reward different (ie reward = (output_reward - input_reward)/(max_reward - input_reward)). Passing a value to max_score will cause the contrastive template to perform this scaling.

class ContrastiveTemplate[source]

ContrastiveTemplate(similarity_function, sample_name='samples', max_score=None, template=None, weight=1.0, track=True, prefilter=True, do_filter=True) :: TemplateCallback

ContrastiveTemplate - contrasttive callback wrapper for Template class

Inputs:

  • similarity_function SimilarityFunction: evaluates similarity between source and targe samples

  • sample_name str: BatchState attribute to grab samples from

  • max_score Optional[float]: maximum template reward. If given, will be used to scale contrastive scores

  • template Template: template to use

  • weight float: weight used to scale template soft filter score

  • track bool: if True, template results are added to the batch log and metric log

  • prefilter bool: if True, samples that fail hard filters in the template are removed

  • do_filter bool: controls if filtering is done at aall

class SimilarityFunction[source]

SimilarityFunction()

SimilarityFunction - compares similarity between source and target samples

class FPSimilarity[source]

FPSimilarity(fp_function, similarity_function, min_sim, max_sim, passscore, failscore, soft_min=None, soft_max=None) :: SimilarityFunction

FPSimilarity - computes paired sample similarity using fingerprint similarity

Inputs:

  • fp_function Callable: Fingerprint function, ie ECFP6. Should return a fingerprint when called

  • similarity_function Callable: fingerprint similarity function, ie tanimoto

  • min_sim float: minimum similarity between paired samples

  • max_sim float: maximum similarity between samples

  • passscore float: score for passing samples

  • failscore float: score for failling compounds

  • soft_min Optional[float]: if given, this value is used as the minimum similarity cutoff during scoring but not for filtering

  • soft_max Optional[float]: if given, this value is used as the maximum similarity cutoff during scoring but not for filtering