Example #1
0
def zero_one(p_y, y):
    """
    :param p_y: the probability distribution of y given x
        :type y: my_theano.tensor.TensorType
        :param y: corresponds to a vector that gives for each example the
                  correct label
    :param p_y:
    :param y:
    :return:
    """
    return T.mean(T.neq(T.argmax(p_y, axis=1), y))
Example #2
0
    def errors(self, y):
        """Return a float representing the number of errors in the minibatch
        over the total number of examples of the minibatch ; zero one
        loss over the size of the minibatch

        :type y: my_theano.tensor.TensorType
        :param y: corresponds to a vector that gives for each example the
                  correct label
        """

        # check if y has same dimension of y_pred
        if y.ndim != self.y_pred.ndim:
            raise TypeError(
                'y should have the same shape as self.y_pred',
                ('y', y.type, 'y_pred', self.y_pred.type)
            )
        # check if y is of the correct datatype
        if y.dtype.startswith('int'):
            # the T.neq operator returns a vector of 0s and 1s, where 1
            # represents a mistake in prediction
            return T.mean(T.neq(self.y_pred, y))
        else:
            raise NotImplementedError()