def check_forward(self, x_data): xp = cuda.get_array_module(x_data) y = maximum_entropy_mellowmax(x_data) self.assertEqual(y.data.dtype, self.dtype) print('y', y.data) # Outputs must be positive xp.testing.assert_array_less(xp.zeros_like(y.data), y.data) # Sums must be ones sums = xp.sum(y.data, axis=1) testing.assert_allclose(sums, xp.ones_like(sums)) # Expectations must be equal to memllowmax's outputs testing.assert_allclose(xp.sum(y.data * x_data, axis=1), mellowmax(x_data, axis=1).data)
def check_forward(self, x_data): xp = cuda.get_array_module(x_data) y = mellowmax(x_data, axis=self.axis, omega=self.omega) self.assertEqual(y.data.dtype, self.dtype) x_min = xp.min(x_data, axis=self.axis) x_max = xp.max(x_data, axis=self.axis) x_mean = xp.mean(x_data, axis=self.axis) print('x_min', x_min) print('y.data', y.data) # min <= mellowmax <= max eps = 1e-5 self.assertTrue(xp.all(x_min <= y.data + eps)) self.assertTrue(xp.all(x_max >= y.data - eps)) # omega > 0 -> mellowmax is more like max if self.omega > 0: self.assertTrue(xp.all(x_mean <= y.data + eps)) # omega < 0 -> mellowmax is more like min if self.omega < 0: self.assertTrue(xp.all(x_mean >= y.data - eps))