Exemplo n.º 1
0
 def testPCAWithZeroAxis(self):
     """Test a PCA example with one zero variance axis."""
     analyzer = analyzers._PCACombinerSpec(output_dim=2,
                                           numpy_dtype=np.float64)
     shards = [[[[0, 0, 1]]], [[[4, 0, 1], [2, -1, 1]]], [[[2, 1, 1]]]]
     out = np.array([[1, 0], [0, 1], [0, 0]])
     self.assertCombine(analyzer, shards, out)
Exemplo n.º 2
0
 def testPCAWithDegenerateCovarianceMatrix(self):
     self._test_combiner_spec_helper(
         combiner_spec=analyzers._PCACombinerSpec(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([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype=np.float64)
         ])
Exemplo n.º 3
0
    ],
)

_COVARIANCE_WITH_LARGE_NUMBERS_TEST = dict(
    testcase_name='CovarianceWithLargeNumbers',
    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)],
)

_PCA_WITH_DEGENERATE_COVARIANCE_MATRIX_TEST = dict(
    testcase_name='PCAWithDegenerateCovarianceMatrix',
    combiner_spec=analyzers._PCACombinerSpec(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([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype=np.float64)
    ],
)

_QUANTILES_SINGLE_BATCH_TESTS = [
    dict(
        testcase_name='ComputeQuantilesSingleBatch-{}'.format(np_type),
        combiner_spec=analyzers._QuantilesCombinerSpec(
            num_quantiles=5, epsilon=0.00001, bucket_numpy_dtype=np.float32),