Ejemplo n.º 1
0
    def test_extrinsic_to_angle(self):
        space = Hypersphere(1)
        point = gs.array([1., 1.]) / gs.sqrt(2.)
        result = space.extrinsic_to_angle(point)
        expected = gs.pi / 4
        self.assertAllClose(result, expected)

        point = gs.array([[1. / 2, gs.sqrt(3.) / 2], [1., 0.]])
        result = space.extrinsic_to_angle(point)
        expected = gs.array([1. / 3, 0.]) * gs.pi
        self.assertAllClose(result, expected)
Ejemplo n.º 2
0
    def test_extrinsic_to_angle_inverse(self):
        space = Hypersphere(1)
        point = space.random_uniform()
        angle = space.extrinsic_to_angle(point)
        result = space.angle_to_extrinsic(angle)
        self.assertAllClose(result, point)

        space = Hypersphere(1, default_coords_type='intrinsic')
        angle = space.random_uniform()
        extrinsic = space.angle_to_extrinsic(angle)
        result = space.extrinsic_to_angle(extrinsic)
        self.assertAllClose(result, angle)
Ejemplo n.º 3
0
def _circle_mean(points):
    """Determine the mean on a circle.

    Data are expected in radians in the range [-pi, pi). The mean is returned
    in the same range. If the mean is unique, this algorithm is guaranteed to
    find it. It is not vulnerable to local minima of the Frechet function. If
    the mean is not unique, the algorithm only returns one of the means. Which
    mean is returned depends on numerical rounding errors.

    Reference
    ---------
    ..[HH15]     Hotz, T. and S. F. Huckemann (2015), "Intrinsic means on the circle:
                 Uniqueness, locus and asymptotics", Annals of the Institute of
                 Statistical Mathematics 67 (1), 177–193.
                 https://arxiv.org/abs/1108.2141
    """
    if points.ndim > 1:
        points_ = Hypersphere.extrinsic_to_angle(points)
    else:
        points_ = gs.copy(points)
    sample_size = points_.shape[0]
    mean0 = gs.mean(points_)
    var0 = gs.sum((points_ - mean0) ** 2)
    sorted_points = gs.sort(points_)
    means = _circle_variances(mean0, var0, sample_size, sorted_points)
    return means[gs.argmin(means[:, 1]), 0]