class_docstr: Mixin utility for training loss methods for models that own their own data. It provides
  
    - a uniform API for the training loss :meth:`training_loss`
    - a convenience method :meth:`training_loss_closure` for constructing the closure expected by
      various optimizers, namely :class:`gpflow.optimizers.Scipy` and subclasses of
      `tf.optimizers.Optimizer`.
  
  See :class:`ExternalDataTrainingLossMixin` for an equivalent mixin for models that do **not**
  own their own data.
class_docstr_tok: ["Mixin","utility","for","training","loss","methods","for","models","that","own","their","own","data",".","It","provides","-","a","uniform","API","for","the","training","loss",":","meth",":","`","training_loss","`","-","a","convenience","method",":","meth",":","`","training_loss_closure","`","for","constructing","the","closure","expected","by","various","optimizers",",","namely",":","class",":","`","gpflow.optimizers.Scipy","`","and","subclasses","of","`","tf.optimizers.Optimizer","`",".","See",":","class",":","`","ExternalDataTrainingLossMixin","`","for","an","equivalent","mixin","for","models","that","do","*","*","not","*","*","own","their","own","data","."]
docstr: Convenience method. Returns a closure which itself returns the training loss. This closure
  can be passed to the minimize methods on :class:`gpflow.optimizers.Scipy` and subclasses of
  `tf.optimizers.Optimizer`.
  
  :param compile: If `True` (default), compile the training loss function in a TensorFlow
      graph by wrapping it in tf.function()
docstr_tok: ["Convenience","method",".","Returns","a","closure","which","itself","returns","the","training","loss",".","This","closure","can","be","passed","to","the","minimize","methods","on",":","class",":","`","gpflow.optimizers.Scipy","`","and","subclasses","of","`","tf.optimizers.Optimizer","`",".",":","param","compile",":","If","`","True","`","(","default",")",",","compile","the","training","loss","function","in","a","TensorFlow","graph","by","wrapping","it","in","tf.function","(",")"]
code: def training_loss_closure(
      self, *, compile: bool = True
  ) -> Callable[[], tf.Tensor]:
      """
      Convenience method. Returns a closure which itself returns the training loss. This closure
      can be passed to the minimize methods on :class:`gpflow.optimizers.Scipy` and subclasses of
      `tf.optimizers.Optimizer`.
  
      :param compile: If `True` (default), compile the training loss function in a TensorFlow
          graph by wrapping it in tf.function()
      """
      closure = self.training_loss
      if compile:
          closure = tf.function(closure)
      return closure
  
file_path: GPflow/gpflow/models/training_mixins.py
imports: from typing import Callable, TypeVar, Union
  import tensorflow
  from check_shapes import check_shapes
  from tensorflow.python.data.ops.iterator_ops import OwnedIterator
  from ..base import InputData, OutputData, RegressionData
label_desc: Use image node_id 2 for calling the InternalDataTrainingLossMixin obj's underlying member method code with example usage: obj.training_loss_closure() and returns: closure