コード例 #1
0
 def test_duplicate_non_winner(self):
     softmax_values = np.array([[0.1, 0.8, 0.05, 0.05],
                                [0.2, 0.09, 0.7, 0.01]])
     prediction, softmax = MaxSoftmax.calculate(softmax_values)
     self.assertEqual((2, ), prediction.shape)
     self.assertEqual((2, ), softmax.shape)
     self.assertEqual(1, prediction[0])
     self.assertAlmostEqual(0.8, softmax[0])
     self.assertEqual(2, prediction[1])
     self.assertAlmostEqual(0.7, softmax[1])
コード例 #2
0
 def test_happy_path_batch(self):
     softmax_values = np.array([[0.1, 0.8, 0.08, 0.02],
                                [0.1, 0.8, 0.08, 0.02],
                                [0.2, 0.09, 0.7, 0.01]])
     prediction, softmax = MaxSoftmax.calculate(softmax_values)
     self.assertEqual((3, ), prediction.shape)
     self.assertEqual((3, ), softmax.shape)
     self.assertEqual(1, prediction[0])
     self.assertAlmostEqual(0.8, softmax[0])
     self.assertEqual(1, prediction[1])
     self.assertAlmostEqual(0.8, softmax[1])
     self.assertEqual(2, prediction[2])
     self.assertAlmostEqual(0.7, softmax[2])
コード例 #3
0
 def test_duplicate_winner(self):
     softmax_values = np.array([[0.4, 0.4, 0.1, 0.1],
                                [0.2, 0.09, 0.7, 0.01]])
     prediction, softmax = MaxSoftmax.calculate(softmax_values)
     self.assertEqual((2, ), prediction.shape)
     self.assertEqual((2, ), softmax.shape)
     self.assertTrue(
         0 == prediction[0] or 1 == prediction[0],
         "Prediction must be index 0 or 1, but was {0}".format(
             prediction[0]),
     )
     self.assertAlmostEqual(0.4, softmax[0])
     self.assertEqual(2, prediction[1])
     self.assertAlmostEqual(0.7, softmax[1])
コード例 #4
0
 def test_happy_path_single(self):
     softmax_values = np.array([0.1, 0.8, 0.08, 0.02])
     softmax_values = np.expand_dims(softmax_values, 0)
     prediction, softmax = MaxSoftmax.calculate(softmax_values)
     self.assertEqual(1, prediction[0])
     self.assertAlmostEqual(0.8, softmax[0])