5
5
6
6
import pyximport ; pyximport .install ()
7
7
from perfx import XYTConstraint_residual , XYTConstraint_jacobians
8
- from perfx import cycle_2PI_towards_zero
8
+ from perfx import normalize_angle_range
9
9
10
10
11
11
@@ -103,7 +103,7 @@ def __init__(self, v, gaussian):
103
103
104
104
def residual (self , aggregate_state = None ):
105
105
r = self ._gaussian .mu - self ._vx [0 ].state
106
- r [2 ] = cycle_2PI_towards_zero (r [2 ])
106
+ r [2 ] = normalize_angle_range (r [2 ])
107
107
return r
108
108
109
109
def chi2 (self ):
@@ -118,11 +118,11 @@ def jacobian(self, roff=0, eps=1e-5):
118
118
Compute the jacobian matrix of the residual error function
119
119
evaluated at the current states of the connected vertices.
120
120
121
- Returns a (dok format) sparse matrix since the jacobian of an
122
- edge constraint is sparse. The `graph_state_length` parameter is
123
- required to fix the column dimension of this sparse matrix.
124
- Thus, the sparse matrix has `graph_state_length` columns and
125
- `len(self.residual())` rows .
121
+ returns the sparse Jacobian matrix entries in triplet format
122
+ (i,j,v). The row index of the entries is offset by `roff`.
123
+
124
+ It is useful to specify `roff` when this Jacobian matrix is
125
+ computed as a sub-matrix of the graph Jacobian .
126
126
"""
127
127
if self ._jacobian_ijv_cache is None :
128
128
J = - np .eye (3 )
@@ -152,15 +152,19 @@ def __init__(self, vertices, edges):
152
152
v ._graph_state_ndx = i
153
153
154
154
def anchor_first_vertex (self ):
155
- v0 = self .vertices [0 ]
155
+ if hasattr (self , '_anchor' ) == False :
156
+ v0 = self .vertices [0 ]
156
157
157
- mu = v0 .state .copy ()
158
- P = 1000. * np .eye (len (mu ))
159
- self ._anchor = AnchorConstraint (v0 , MultiVariateGaussian (mu , P ))
158
+ mu = v0 .state .copy ()
159
+ P = 1000. * np .eye (len (mu ))
160
+ self ._anchor = AnchorConstraint (v0 , MultiVariateGaussian (mu , P ))
160
161
161
- self .edges .append (self ._anchor )
162
+ self .edges .append (self ._anchor )
162
163
163
164
def get_stats (self ):
164
- DOF = sum (e ._DOF for e in self .edges ) - len (self .state )
165
- chi2 = sum (e .chi2 () for e in self .edges )
165
+ original_edges = [ e for e in self .edges if e is not self ._anchor ]
166
+
167
+ DOF = sum (e ._DOF for e in original_edges ) - len (self .state )
168
+ chi2 = sum (e .chi2 () for e in original_edges )
169
+
166
170
return GraphStats (chi2 , chi2 / DOF , DOF )
0 commit comments