1 from . import DifferentiableManifold, contract, np
5 @contract(components='seq[>=2,N](DifferentiableManifold)',
6 weights='None|array[N](>0)')
7 - def __init__(self, components, weights=None):
8 dim = sum([m.dimension for m in components])
9 DifferentiableManifold.__init__(self, dimension=dim)
10 self.components = components
11 if weights is None:
12 weights = np.ones(len(components))
13 self.weights = weights
14
15 @contract(a='seq')
17 if not len(a) == len(self.components):
18 raise ValueError('I expect a sequence of length %d, not %d.' %
19 (len(a), len(self.components)))
20 for x, m in zip(a, self.components):
21 m.belongs(x)
22
24 ''' Computes the geodesic distance between two points. '''
25 distances = [m.distance_(x) for x, m in zip(a, self.components)]
26 distances = np.array(distances)
27 return (distances * self.weights).sum()
28
30 ''' Computes the logarithmic map from base point *a* to target *b*. '''
31 raise ValueError('Not implemented')
32
34 raise ValueError('Not implemented')
35
37 raise ValueError('Not implemented')
38
40 return 'P(%s)' % "x".join([str(x) for x in self.components])
41