Exemplo n.º 1
0
 def _test_compute_quantiles_single_batch_helper(self, nptype):
     self._test_combiner_spec_helper(
         combiner_spec=analyzers._QuantilesCombinerSpec(
             num_quantiles=3,
             epsilon=0.00001,
             bucket_numpy_dtype=np.float32),
         batches=[[np.linspace(1, 100, 100, nptype)]],
         expected_outputs=[np.array([35, 68], dtype=np.float32)])
Exemplo n.º 2
0
 def _test_compute_quantiles_multipe_batch_helper(self, nptype):
     self._test_combiner_spec_helper(
         combiner_spec=analyzers._QuantilesCombinerSpec(
             num_quantiles=5,
             epsilon=0.00001,
             bucket_numpy_dtype=np.float32),
         batches=[[np.linspace(1, 100, 100, dtype=nptype)],
                  [np.linspace(101, 200, 100, dtype=nptype)],
                  [np.linspace(201, 300, 100, dtype=nptype)]],
         expected_outputs=[np.array([61, 121, 181, 241], dtype=np.float32)])
Exemplo n.º 3
0
 def __init__(self, num_quantiles, epsilon):
     self._num_quantiles = num_quantiles
     self._epsilon = epsilon
     self._quantiles_spec = analyzers._QuantilesCombinerSpec(
         num_quantiles=num_quantiles,
         epsilon=epsilon,
         bucket_numpy_dtype=np.float32,
         always_return_num_quantiles=True)
     # Initializes non-pickleable local state of the combiner spec.
     self._quantiles_spec.initialize_local_state()
Exemplo n.º 4
0
    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),
        batches=[
            [np.linspace(1, 100, 100, dtype=np_type)],
            [np.linspace(101, 200, 100, dtype=np_type)],
            [np.linspace(201, 300, 100, dtype=np_type)],
        ],
        expected_outputs=[np.array([61, 121, 181, 241], dtype=np.float32)],
    ) for np_type in _NP_TYPES
]

_QUANTILES_MULTIPLE_BATCH_TESTS = [
    dict(
        testcase_name='ComputeQuantilesMultipleBatch-{}'.format(np_type),
        combiner_spec=analyzers._QuantilesCombinerSpec(
            num_quantiles=3, epsilon=0.00001, bucket_numpy_dtype=np.float32),
        batches=[
Exemplo n.º 5
0
                                                     axis=0),
        _make_mean_and_var_accumulator_from_instance(
            [[100, 200, 3000, 17, 27, 53]], axis=0),
    ],
    expected_outputs=[
        np.float32([36., 70., 1004., 10.33333333, 14.33333333, 23.66666667]),
        np.float32(
            [2054., 8456., 1992014., 28.22222222, 86.22222222, 436.22222222]),
    ],
)

_QUANTILES_NO_ELEMENTS_TEST = dict(
    testcase_name='ComputeQuantilesNoElements',
    combiner_spec=analyzers._QuantilesCombinerSpec(
        num_quantiles=5,
        epsilon=0.00001,
        bucket_numpy_dtype=np.float32,
        always_return_num_quantiles=False),
    batches=[
        (np.empty((0, 1), dtype=np.float32), ),
    ],
    expected_outputs=[np.zeros((0, ), dtype=np.float32)],
)

_QUANTILES_EXACT_NO_ELEMENTS_TEST = dict(
    testcase_name='ComputeExactQuantilesNoElements',
    combiner_spec=analyzers._QuantilesCombinerSpec(
        num_quantiles=5,
        epsilon=0.00001,
        bucket_numpy_dtype=np.float32,
        always_return_num_quantiles=True),