chemprop.nn.predictors
======================

.. py:module:: chemprop.nn.predictors


Attributes
----------

.. autoapisummary::

   chemprop.nn.predictors.PredictorRegistry


Classes
-------

.. autoapisummary::

   chemprop.nn.predictors.Predictor
   chemprop.nn.predictors.RegressionFFN
   chemprop.nn.predictors.MveFFN
   chemprop.nn.predictors.EvidentialFFN
   chemprop.nn.predictors.BinaryClassificationFFNBase
   chemprop.nn.predictors.BinaryClassificationFFN
   chemprop.nn.predictors.BinaryDirichletFFN
   chemprop.nn.predictors.MulticlassClassificationFFN
   chemprop.nn.predictors.MulticlassDirichletFFN
   chemprop.nn.predictors.SpectralFFN


Module Contents
---------------

.. py:class:: Predictor(*args, **kwargs)

   Bases: :py:obj:`torch.nn.Module`, :py:obj:`chemprop.nn.hparams.HasHParams`


   A :class:`Predictor` is a protocol that defines a differentiable function
   :math:`f` : \mathbb R^d \mapsto \mathbb R^o


   .. py:attribute:: input_dim
      :type:  int

      the input dimension


   .. py:attribute:: output_dim
      :type:  int

      the output dimension


   .. py:attribute:: n_tasks
      :type:  int

      the number of tasks `t` to predict for each input


   .. py:attribute:: n_targets
      :type:  int

      the number of targets `s` to predict for each task `t`


   .. py:attribute:: criterion
      :type:  chemprop.nn.metrics.ChempropMetric

      the loss function to use for training


   .. py:attribute:: task_weights
      :type:  torch.Tensor

      the weights to apply to each task when calculating the loss


   .. py:attribute:: output_transform
      :type:  chemprop.nn.transforms.UnscaleTransform

      the transform to apply to the output of the predictor


   .. py:method:: forward(Z)
      :abstractmethod:



   .. py:method:: train_step(Z)
      :abstractmethod:



   .. py:method:: encode(Z, i)
      :abstractmethod:


      Calculate the :attr:`i`-th hidden representation

      :param Z: a tensor of shape ``n x d`` containing the input data to encode, where ``d`` is the
                input dimensionality.
      :type Z: Tensor
      :param i: The stop index of slice of the MLP used to encode the input. That is, use all
                layers in the MLP *up to* :attr:`i` (i.e., ``MLP[:i]``). This can be any integer
                value, and the behavior of this function is dependent on the underlying list
                slicing behavior. For example:

                * ``i=0``: use a 0-layer MLP (i.e., a no-op)
                * ``i=1``: use only the first block
                * ``i=-1``: use *up to* the final block
      :type i: int

      :returns: a tensor of shape ``n x h`` containing the :attr:`i`-th hidden representation, where
                ``h`` is the number of neurons in the :attr:`i`-th hidden layer.
      :rtype: Tensor



.. py:data:: PredictorRegistry

.. py:class:: RegressionFFN(n_tasks = 1, input_dim = DEFAULT_HIDDEN_DIM, hidden_dim = 300, n_layers = 1, dropout = 0.0, activation = 'relu', criterion = None, task_weights = None, threshold = None, output_transform = None)

   Bases: :py:obj:`_FFNPredictorBase`


   A :class:`_FFNPredictorBase` is the base class for all :class:`Predictor`\s that use an
   underlying :class:`MLP` to map the learned fingerprint to the desired output.


   .. py:attribute:: n_targets
      :value: 1


      the number of targets `s` to predict for each task `t`


   .. py:method:: forward(Z)


   .. py:attribute:: train_step


.. py:class:: MveFFN(n_tasks = 1, input_dim = DEFAULT_HIDDEN_DIM, hidden_dim = 300, n_layers = 1, dropout = 0.0, activation = 'relu', criterion = None, task_weights = None, threshold = None, output_transform = None)

   Bases: :py:obj:`RegressionFFN`


   A :class:`_FFNPredictorBase` is the base class for all :class:`Predictor`\s that use an
   underlying :class:`MLP` to map the learned fingerprint to the desired output.


   .. py:attribute:: n_targets
      :value: 2


      the number of targets `s` to predict for each task `t`


   .. py:method:: forward(Z)


   .. py:attribute:: train_step


.. py:class:: EvidentialFFN(n_tasks = 1, input_dim = DEFAULT_HIDDEN_DIM, hidden_dim = 300, n_layers = 1, dropout = 0.0, activation = 'relu', criterion = None, task_weights = None, threshold = None, output_transform = None)

   Bases: :py:obj:`RegressionFFN`


   A :class:`_FFNPredictorBase` is the base class for all :class:`Predictor`\s that use an
   underlying :class:`MLP` to map the learned fingerprint to the desired output.


   .. py:attribute:: n_targets
      :value: 4


      the number of targets `s` to predict for each task `t`


   .. py:method:: forward(Z)


   .. py:attribute:: train_step


.. py:class:: BinaryClassificationFFNBase(n_tasks = 1, input_dim = DEFAULT_HIDDEN_DIM, hidden_dim = 300, n_layers = 1, dropout = 0.0, activation = 'relu', criterion = None, task_weights = None, threshold = None, output_transform = None)

   Bases: :py:obj:`_FFNPredictorBase`


   A :class:`_FFNPredictorBase` is the base class for all :class:`Predictor`\s that use an
   underlying :class:`MLP` to map the learned fingerprint to the desired output.


.. py:class:: BinaryClassificationFFN(n_tasks = 1, input_dim = DEFAULT_HIDDEN_DIM, hidden_dim = 300, n_layers = 1, dropout = 0.0, activation = 'relu', criterion = None, task_weights = None, threshold = None, output_transform = None)

   Bases: :py:obj:`BinaryClassificationFFNBase`


   A :class:`_FFNPredictorBase` is the base class for all :class:`Predictor`\s that use an
   underlying :class:`MLP` to map the learned fingerprint to the desired output.


   .. py:attribute:: n_targets
      :value: 1


      the number of targets `s` to predict for each task `t`


   .. py:method:: forward(Z)


   .. py:method:: train_step(Z)


.. py:class:: BinaryDirichletFFN(n_tasks = 1, input_dim = DEFAULT_HIDDEN_DIM, hidden_dim = 300, n_layers = 1, dropout = 0.0, activation = 'relu', criterion = None, task_weights = None, threshold = None, output_transform = None)

   Bases: :py:obj:`BinaryClassificationFFNBase`


   A :class:`_FFNPredictorBase` is the base class for all :class:`Predictor`\s that use an
   underlying :class:`MLP` to map the learned fingerprint to the desired output.


   .. py:attribute:: n_targets
      :value: 2


      the number of targets `s` to predict for each task `t`


   .. py:method:: forward(Z)


   .. py:method:: train_step(Z)


.. py:class:: MulticlassClassificationFFN(n_classes, n_tasks = 1, input_dim = DEFAULT_HIDDEN_DIM, hidden_dim = 300, n_layers = 1, dropout = 0.0, activation = 'relu', criterion = None, task_weights = None, threshold = None, output_transform = None)

   Bases: :py:obj:`_FFNPredictorBase`


   A :class:`_FFNPredictorBase` is the base class for all :class:`Predictor`\s that use an
   underlying :class:`MLP` to map the learned fingerprint to the desired output.


   .. py:attribute:: n_targets
      :value: 1


      the number of targets `s` to predict for each task `t`


   .. py:attribute:: n_classes


   .. py:property:: n_tasks
      :type: int


      the number of tasks `t` to predict for each input


   .. py:method:: forward(Z)


   .. py:method:: train_step(Z)


.. py:class:: MulticlassDirichletFFN(n_classes, n_tasks = 1, input_dim = DEFAULT_HIDDEN_DIM, hidden_dim = 300, n_layers = 1, dropout = 0.0, activation = 'relu', criterion = None, task_weights = None, threshold = None, output_transform = None)

   Bases: :py:obj:`MulticlassClassificationFFN`


   A :class:`_FFNPredictorBase` is the base class for all :class:`Predictor`\s that use an
   underlying :class:`MLP` to map the learned fingerprint to the desired output.


   .. py:method:: forward(Z)


   .. py:method:: train_step(Z)


.. py:class:: SpectralFFN(*args, spectral_activation = 'softplus', **kwargs)

   Bases: :py:obj:`_FFNPredictorBase`


   A :class:`_FFNPredictorBase` is the base class for all :class:`Predictor`\s that use an
   underlying :class:`MLP` to map the learned fingerprint to the desired output.


   .. py:attribute:: n_targets
      :value: 1


      the number of targets `s` to predict for each task `t`


   .. py:method:: forward(Z)


   .. py:attribute:: train_step


