Beispiel #1
0
 def testCovarianceWithLargeNumbers(self):
   self._test_combiner_spec_helper(
       combiner_spec=analyzers._CovarianceCombinerSpec(numpy_dtype=np.float64),
       batches=[
           [np.array([[2e15, 0], [1e15, 0]])],
           [np.array([[-2e15, 0], [-1e15, 0]])]
       ],
       expected_outputs=[np.array([[2.5e30, 0], [0, 0]], dtype=np.float64)])
Beispiel #2
0
 def testCovarianceWithLargeNumbers(self):
   """Test floating point precision with very large doubles."""
   analyzer = analyzers._CovarianceCombinerSpec(dtype=tf.float64)
   shards = [
       [[[2e15, 0], [1e15, 0]]],
       [[[-2e15, 0], [-1e15, 0]]]
   ]
   out = np.array([[2.5e30, 0], [0, 0]])
   self.assertCombine(analyzer, shards, out)
Beispiel #3
0
 def testCovarianceWithZeroAxis(self):
   """Test an example with one zero variance axis."""
   analyzer = analyzers._CovarianceCombinerSpec(dtype=tf.float64)
   shards = [
       [[[0, 0, 1]]],
       [[[4, 0, 1], [2, -1, 1]]],
       [[[2, 1, 1]]]
   ]
   out = np.array([[2, 0, 0], [0, 0.5, 0], [0, 0, 0]])
   self.assertCombine(analyzer, shards, out)
Beispiel #4
0
 def testCovarianceWithDegenerateCovarianceMatrix(self):
     self._test_combiner_spec_helper(
         combiner_spec=analyzers._CovarianceCombinerSpec(
             numpy_dtype=np.float64),
         batches=[[np.array([[0, 0, 1]])],
                  [np.array([[4, 0, 1], [2, -1, 1]])],
                  [np.array([[2, 1, 1]])]],
         expected_outputs=[
             np.array([[2, 0, 0], [0, 0.5, 0], [0, 0, 0]], dtype=np.float64)
         ])
Beispiel #5
0
_SUM_OF_SIZE_ZERO_TENSORS_TEST = dict(
    testcase_name='SumOfSizeZeroTensors',
    combiner_spec=analyzers._NumPyCombinerSpec(np.sum,
                                               reduce_instance_dims=False,
                                               output_dtypes=[np.int64]),
    batches=[
        [np.ones((2, 0))],
        [np.ones((1, 0))],
    ],
    expected_outputs=[np.ones((0, ), np.int64) * 3],
)

_COVARIANCE_SIZE_ZERO_TENSORS_TEST = dict(
    testcase_name='CovarianceSizeZeroTensors',
    combiner_spec=analyzers._CovarianceCombinerSpec(numpy_dtype=np.float64),
    batches=[
        [np.empty((1, 0))],
        [np.empty((2, 0))],
    ],
    expected_outputs=[np.empty((0, 0), dtype=np.float64)],
)

_COVARIANCE_WITH_DEGENERATE_COVARIANCE_MATRIX_TEST = dict(
    testcase_name='CovarianceWithDegenerateCovarianceMatrix',
    combiner_spec=analyzers._CovarianceCombinerSpec(numpy_dtype=np.float64),
    batches=[
        [np.array([[0, 0, 1]])],
        [np.array([[4, 0, 1], [2, -1, 1]])],
        [np.array([[2, 1, 1]])],
    ],
Beispiel #6
0
 def testCovarianceEmpty(self):
   """Test empty array of inputs."""
   analyzer = analyzers._CovarianceCombinerSpec(dtype=tf.float64)
   shards = [[[[]]], [[[]]]]
   out = np.empty((0, 0))
   self.assertCombine(analyzer, shards, out)
Beispiel #7
0
 def testCovarianceSizeZeroTensors(self):
     self._test_combiner_spec_helper(
         combiner_spec=analyzers._CovarianceCombinerSpec(
             numpy_dtype=np.float64),
         batches=[[np.empty((1, 0))], [np.empty((2, 0))]],
         expected_outputs=[np.empty((0, 0), dtype=np.float64)])