4 Linear algebra standard fitting module 6 (C) 2013 hashnote.net, Alisue 8 __author__ =
'Alisue (lambdalisue@hashnote.net)' 10 __date__ =
'2013-10-28' 11 __all__ = [
'standard_fit',
'projection',
'distance',
'function']
17 Find (n - 1) dimensional standard (e.g. line in 2 dimension, plane in 3 18 dimension, hyperplane in n dimension) via solving Singular Value 21 The idea was explained in the following references 23 - http://www.caves.org/section/commelect/DUSI/openmag/pdf/SphereFitting.pdf 24 - http://www.geometrictools.com/Documentation/LeastSquaresFitting.pdf 25 - http://www.ime.unicamp.br/~marianar/MI602/material%20extra/svd-regression-analysis.pdf 26 - http://www.ling.ohio-state.edu/~kbaker/pubs/Singular_Value_Decomposition_Tutorial.pdf 29 >>> XY = [[0, 1], [3, 3]] 31 >>> C, N = standard_fit(XY) 35 array([-0.5547002 , 0.83205029]) 38 X: n x m dimensional matrix which n indicate the number of the dimension 39 and m indicate the number of points 42 [C, N] where C is a centroid vector and N is a normal vector 45 C = np.average(X, axis=0)
49 U, S, V = np.linalg.svd(CX)
57 Create orthogonal projection matrix of x on the plane 60 x: n x m dimensional matrix 61 C: n dimensional vector whicn indicate the centroid of the standard 62 N: n dimensional vector which indicate the normal vector of the standard 65 n x m dimensional matrix which indicate the orthogonal projection points 69 NN = np.tile(N, (rows, 1))
71 DD = np.tile(D, (cols, 1)).T
76 Calculate an orthogonal distance between the points and the standard 79 x: n x m dimensional matrix 80 C: n dimensional vector whicn indicate the centroid of the standard 81 N: n dimensional vector which indicate the normal vector of the standard 84 m dimensional vector which indicate the orthogonal disntace. the value 85 will be negative if the points beside opposite side of the normal vector 91 Calculate an orthogonal projection of the points on the standard 94 x: (n-1) x m dimensional matrix 95 C: n dimensional vector whicn indicate the centroid of the standard 96 N: n dimensional vector which indicate the normal vector of the standard 99 m dimensional vector which indicate the last attribute value of 100 orthogonal projection 106 return np.dot(x-Ck, Nk) * -1.0 / Nu + Cu
113 if __name__ ==
'__main__':
114 import doctest; doctest.testmod()