Changeset 26344
- Timestamp:
- Dec 5, 2009, 5:57:23 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/psLib/src/math/psMatrix.c
r26001 r26344 1093 1093 } 1094 1094 1095 1096 1097 1095 // This code supplied by Andy Becker (becker@astro.washington.edu) 1098 psImage *psMatrixSVD (psImage* evec, psVector* eval, const psImage* in)1096 psImage *psMatrixSVD_old(psImage* evec, psVector* eval, const psImage* in) 1099 1097 { 1100 1098 #define psMatrixSVD_EXIT {psFree(evec); psFree(eval); return NULL;} … … 1145 1143 return evec; 1146 1144 } 1145 1146 // this is basically a wrapper for the gsl function: gsl_linalg_SV_decomp() 1147 // SVD decomposes matrix A based on the following equation: A = U w V^T . 1148 // This function (as usual for SVD implementations) returns V not V^T. 1149 // U and V are returned to images; w is returned to a vector. The input image is not modified. 1150 // U, V, and w must be supplied as allocated structures, but their lengths are set here to match the 1151 // dimensionality of A. 1152 // XXX there is no error handling for the gsl functions (anywhere in psMatrix.c) 1153 bool psMatrixSVD(psImage *U, psVector *w, psImage *V, const psImage *A) 1154 { 1155 // Error checks Missing one for eval 1156 PS_ASSERT_GENERAL_IMAGE_NON_NULL(A, false); 1157 PS_CHECK_POINTERS(A, evec, false); 1158 PS_CHECK_DIMEN_AND_TYPE(A, PS_DIMEN_IMAGE, false); 1159 1160 // A is provided with size Nx,Ny = numCols,numRows 1161 // U has size Nx,Ny 1162 // V has size Nx,Nx 1163 // w has size Nx 1164 1165 // Initialize data 1166 int numRows = A->numRows; 1167 int numCols = A->numCols; 1168 1169 U = psImageRecycle(U, numCols, numRows, A->type.type); 1170 V = psImageRecycle(V, numCols, numCols, A->type.type); 1171 w = psVectorRecycle(w, numCols, A->type.type); 1172 1173 gsl_matrix *Agsl = gsl_matrix_alloc(numRows, numCols); 1174 gsl_matrix *Vgsl = gsl_matrix_alloc(numCols, numCols); 1175 gsl_vector *Sgsl = gsl_vector_alloc(numCols); 1176 gsl_vector *work = gsl_vector_alloc(numCols); 1177 1178 // Copy psImage data into GSL matrix data 1179 matrixPStoGSL(Agsl, A); 1180 1181 // Calculate SVD decomposition 1182 gsl_linalg_SV_decomp(Agsl, Vgsl, Sgsl, work); 1183 1184 // Copy GSL matrix data to psImage data 1185 matrixGSLtoPS(V, Vgsl); 1186 matrixGSLtoPS(U, Agsl); // gsl_linalg_SV_decomp replaces A with U 1187 vectorGSLtoPS(S, Sgsl); 1188 1189 // Free GSL data 1190 gsl_matrix_free(A); 1191 gsl_matrix_free(V); 1192 gsl_vector_free(S); 1193 gsl_vector_free(work); 1194 1195 return true; 1196 }
Note:
See TracChangeset
for help on using the changeset viewer.
