Пример #1
0
        np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype=np.float64)
    ],
)


def _make_mean_and_var_accumulator_from_instance(instance, axis=None):
    return analyzers._MeanAndVarAccumulator(count=np.sum(
        np.ones_like(instance), axis=axis),
                                            mean=np.mean(instance, axis=axis),
                                            variance=np.var(instance,
                                                            axis=axis))


_MEAN_AND_VAR_TEST = dict(
    testcase_name='MeanAndVar',
    combiner=analyzers.MeanAndVarCombiner(np.float32),
    batches=[
        _make_mean_and_var_accumulator_from_instance([[1, 2, 3, 4, 5, 6, 7]]),
        # Count is 5*0xFFFF=327675 for this accumulator.
        _make_mean_and_var_accumulator_from_instance([[8, 9, 10, 11, 12]] *
                                                     0xFFFF),
        _make_mean_and_var_accumulator_from_instance([[100, 200, 3000]]),
    ],
    expected_outputs=[
        np.float32(10.00985092390558),
        np.float32(29.418185761379473),
    ],
)

_MEAN_AND_VAR_BIG_TEST = dict(
    testcase_name='MeanAndVarBig',
Пример #2
0
 def __init__(self):
     self._combiner = analyzers.MeanAndVarCombiner(np.float32)