def compile(self, mod_y, ref_y, regterm=None):
        """Compute the loss function tensor.

        Parameters
        ----------

        mode_y : tf.Tensor
            model output tensor

        ref_y : tf.Tensor
            reference input tensor

        regterm : tf.Tensor, optional (default = None)
            Regularization term tensor

        Returns
        -------

        Loss function tensor.
        """
        with tf.name_scope(self.name):
            if self.lfunc == 'cross_entropy':
                clip_inf = tf.clip_by_value(mod_y, 1e-10, float('inf'))
                clip_sup = tf.clip_by_value(1 - mod_y, 1e-10, float('inf'))

                cost = - tf.reduce_mean(tf.add(
                        tf.multiply(ref_y, tf.log(clip_inf)),
                        tf.multiply(tf.subtract(1.0, ref_y), tf.log(clip_sup))))

            elif self.lfunc == 'softmax_cross_entropy':
                cost = tf.losses.softmax_cross_entropy(ref_y, mod_y)

            elif self.lfunc == 'mse':
                cost = tf.sqrt(tf.reduce_mean(
                    tf.square(tf.subtract(ref_y, mod_y))))

            else:
                cost = None

        if cost is not None:
            cost = cost + regterm if regterm is not None else cost
            tf.summary.scalar(self.lfunc, cost)
        else:
            cost = None

        return cost
Compute the loss function tensor.

        Parameters
        ----------

        mode_y : tf.Tensor
            model output tensor

        ref_y : tf.Tensor
            reference input tensor

        regterm : tf.Tensor, optional (default = None)
            Regularization term tensor

        Returns
        -------

        Loss function tensor.
        
yadlt/core/trainers.py