def testVonMisesSampleMoments(self): locs_v = np.array([-1., 0.3, 2.3]) concentrations_v = np.array([1., 2., 10.]) von_mises = tfd.VonMises(self.make_tensor(locs_v), self.make_tensor(concentrations_v), validate_args=True) n = 10000 seed = test_util.test_seed() samples = von_mises.sample(n, seed=seed) expected_mean = von_mises.mean() actual_mean = tf.atan2(tf.reduce_mean(tf.sin(samples), axis=0), tf.reduce_mean(tf.cos(samples), axis=0)) expected_variance = von_mises.variance() standardized_samples = samples - tf.expand_dims(von_mises.mean(), 0) variance_samples = 1. - tf.cos(standardized_samples) [ expected_mean_val, expected_variance_val, actual_mean_val, variance_samples_ ] = self.evaluate( [expected_mean, expected_variance, actual_mean, variance_samples]) # TODO(axch, cgs): atan2(means) is not mean(atan2), but maybe there # is a formulation of what this is testing that does use IID samples # and is amenable to assertAllMeansClose? self.assertAllClose(actual_mean_val, expected_mean_val, rtol=0.1) self.assertAllMeansClose(variance_samples_, expected_variance_val, axis=0, rtol=0.1)
def testVonMisesSampleMoments(self): locs_v = np.array([-1., 0.3, 2.3]) concentrations_v = np.array([1.0, 2.0, 10.0]) von_mises = tfd.VonMises(self.make_tensor(locs_v), self.make_tensor(concentrations_v), validate_args=True) n = 10000 seed = test_util.test_seed() samples = von_mises.sample(n, seed=seed) expected_mean = von_mises.mean() actual_mean = tf.atan2(tf.reduce_mean(tf.sin(samples), axis=0), tf.reduce_mean(tf.cos(samples), axis=0)) expected_variance = von_mises.variance() standardized_samples = samples - tf.expand_dims(von_mises.mean(), 0) actual_variance = 1. - tf.reduce_mean(tf.cos(standardized_samples), axis=0) [ expected_mean_val, expected_variance_val, actual_mean_val, actual_variance_val ] = self.evaluate( [expected_mean, expected_variance, actual_mean, actual_variance]) self.assertAllClose(expected_mean_val, actual_mean_val, rtol=0.1) self.assertAllClose(expected_variance_val, actual_variance_val, rtol=0.1)
def transform_box(bboxes, transform): """Transform bboxes.""" center_xyz = bboxes[..., :3] dimensions = bboxes[..., 3:6] rot = bboxes[..., 6:] center_xyz = transform_points_with_transform(center_xyz, transform) rot += tf.atan2(transform[..., 1:2, 0:1], transform[..., 0:1, 0:1]) rot = wrap_angle_rad(rot) bboxes = tf.concat([center_xyz, dimensions, rot], axis=-1) return bboxes