Exemple #1
0
    def testOneHotMinusExactHard(self):
        inputs = tf.constant([[0., 1., 0.], [0., 0., 1.]])
        shift = tf.constant([[0., 1., 0.], [1., 0., 0.]])

        outputs = reversible.one_hot_minus(inputs, shift)
        outputs_val = self.evaluate(outputs)
        self.assertAllEqual(outputs_val, np.array([[1., 0., 0.], [0., 0.,
                                                                  1.]]))
Exemple #2
0
    def testOneHotMinusExactSoft(self):
        inputs = tf.constant([[0., 1., 0.], [0., 0., 1.]])
        shift = tf.constant([[0.1, 0.6, 0.3], [0.2, 0.4, 0.4]])

        outputs = reversible.one_hot_minus(inputs, shift)

        shift_zero = inputs
        shift_one = np.array([[1., 0., 0.], [0., 1., 0.]])
        shift_two = np.array([[0., 0., 1.], [1., 0., 0.]])
        expected_outputs = (shift[..., 0][..., tf.newaxis] * shift_zero +
                            shift[..., 1][..., tf.newaxis] * shift_one +
                            shift[..., 2][..., tf.newaxis] * shift_two)

        actual_outputs_val, expected_outputs_val = self.evaluate(
            [outputs, expected_outputs])
        self.assertAllEqual(actual_outputs_val, expected_outputs_val)