def test_weighted_values_check_results(self): values = numpy.array([1.0, 2.0, 3.0]) probabilities = numpy.array([0.2, 0.5, 0.3]) size = (5,) forced_random = numpy.array([0.19, 0.21, 0.69, 0.71, 0.99]) result = weighted_values(values, probabilities, size, forced_random=forced_random) actual = numpy.array([1, 2, 2, 3, 3]) msg = 'fail. ' + str(result) + '!=' + str(actual) self.assertTrue(allclose(result, actual), msg)
def __call__(self, context, var, values, forced_random=None): """ A dummy job for testing. :param context: The context instance, used to move data around. :param var: Variable to add to context. :param values: Value of the variable added. :param forced_random: Used for testing. A vector or value to be used as the random numbers. """ shape = context.get_site_shape() s_keys, s_probs = misc.sorted_dict_values(values) s_probs = scipy.asarray(s_probs) s_keys = scipy.asarray(s_keys) values_array = misc.weighted_values(s_keys, s_probs, shape, forced_random=forced_random) context.exposure_att[var] = values_array