@@ -126,6 +126,36 @@ def test_pca_runs_from_stats(self):
126126 stats = spy .calc_stats (data )
127127 xdata = spy .principal_components (stats ).transform (data )
128128
129+ def test_orthogonalize (self ):
130+ '''Can correctly create an orthogonal basis from vectors.'''
131+ x = np .linspace (0 , np .pi , 1001 )
132+ # Create sin and cos vectors of unit length
133+ sin_h = np .sin (x )
134+ sin_h /= np .linalg .norm (sin_h )
135+ cos_h = np .cos (x )
136+ cos_h /= np .linalg .norm (cos_h )
137+
138+ X = np .array ([50 * sin_h , 75 * cos_h ])
139+ Y = spy .orthogonalize (X )
140+ assert (np .allclose (Y .dot (Y .T ), np .array ([[1 , 0 ], [0 , 1 ]])))
141+ assert (np .allclose (X .dot (Y .T ), np .array ([[50 , 0 ], [0 , 75 ]])))
142+
143+ def test_orthogonalize_subset (self ):
144+ '''Can correctly create an orthogonal basis from vector subset.'''
145+ x = np .linspace (0 , np .pi , 1001 )
146+ # Create sin and cos vectors of unit length
147+ sin_h = np .sin (x )
148+ sin_h /= np .linalg .norm (sin_h )
149+ cos_h = np .cos (x )
150+ cos_h /= np .linalg .norm (cos_h )
151+
152+ # First vector in X will already be a unit vector
153+ X = np .array ([sin_h , 75 * cos_h ])
154+ Y = spy .orthogonalize (X , start = 1 )
155+ assert (np .allclose (Y .dot (Y .T ), np .array ([[1 , 0 ], [0 , 1 ]])))
156+ assert (np .allclose (X .dot (Y .T ), np .array ([[1 , 0 ], [0 , 75 ]])))
157+
158+
129159def run ():
130160 print ('\n ' + '-' * 72 )
131161 print ('Running dimensionality tests.' )
0 commit comments