Package geometry :: Package manifolds :: Module matrix_linear_space
[hide private]
[frames] | no frames]

Source Code for Module geometry.manifolds.matrix_linear_space

 1  from . import np, DifferentiableManifold, contract 
 2  from .. import assert_allclose 
 3  from abc import abstractmethod 
 4  from contracts import check 
5 6 7 -class MatrixLinearSpace(DifferentiableManifold):
8 9 @contract(dimension='int,>0')
10 - def __init__(self, dimension, shape):
11 ''' Note dimension is the intrinsic dimension. ''' 12 # TODO: give basis? 13 self.shape = shape 14 DifferentiableManifold.__init__(self, dimension=dimension)
15
16 - def zero(self):
17 ''' Returns the zero element for this algebra. ''' 18 return np.zeros(self.shape)
19
20 - def norm(self, v):
21 ''' Return the norm of a vector in the algebra. 22 This is used in :py:class:`MatrixLieGroup` to measure 23 distances between points in the Lie group. 24 ''' 25 return np.linalg.norm(v, 2)
26 27 # Manifolds methods
28 - def distance(self, a, b):
29 return self.norm(a - b)
30 31 @contract(bv='belongs_ts')
32 - def expmap(self, bv):
33 base, vel = bv 34 return base + vel
35 36 @contract(base='belongs', target='belongs', returns='belongs_ts')
37 - def logmap(self, base, target):
38 return base, target - base
39 40 @contract(x='array')
41 - def belongs(self, x):
42 if x.shape != self.shape: 43 raise ValueError('Expected shape %r, not %r.' % 44 (self.shape, x.shape)) 45 46 # TODO: make contract 47 assert np.all(np.isreal(x)), "Expected real vector" 48 proj = self.project(x) 49 assert_allclose(proj, x, atol=1e-8) # XXX: tol
50
51 - def belongs_ts(self, bv):
52 # formatm('bv', bv) 53 check('tuple(shape(x),shape(x))', bv, x=self.shape) 54 base, vel = bv 55 self.belongs(base) 56 self.belongs(vel)
57 58 @abstractmethod
59 - def project(self, v): #@UnusedVariable
60 ''' Projects a vector onto this Lie Algebra. '''
61
62 - def project_ts(self, bv):
63 base, vel = bv 64 return base, self.project(vel)
65