IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10381


Ignore:
Timestamp:
Dec 1, 2006, 11:48:47 AM (20 years ago)
Author:
Paul Price
Message:

Adding SVD provided by Andy Becker.

Location:
trunk/psLib/src/math
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psMatrix.c

    r10251 r10381  
    2020 *  @author Ross Harman, MHPCC
    2121 *  @author Robert DeSonia, MHPCC
     22 *  @author Andy Becker, University of Washington (SVD).
    2223 *
    23  *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
    24  *  @date $Date: 2006-11-29 02:14:49 $
     24 *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
     25 *  @date $Date: 2006-12-01 21:48:47 $
    2526 *
    2627 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    871872    return outImage;
    872873}
     874
     875// This code supplied by Andy Becker (becker@astro.washington.edu)
     876psImage *psMatrixSVDSolve(psImage* evec, psVector* eval, const psImage* in)
     877{
     878    #define psMatrixSVD_EXIT {psFree(evec); psFree(eval); return NULL;}
     879
     880    // Error checks  Missing one for eval
     881    PS_ASSERT_GENERAL_IMAGE_NON_NULL(in, psMatrixSVD_EXIT);
     882    PS_CHECK_POINTERS(in, evec, psMatrixSVD_EXIT);
     883    PS_CHECK_DIMEN_AND_TYPE(in, PS_DIMEN_IMAGE, psMatrixSVD_EXIT);
     884
     885    // evec ends up : numCols x numCols
     886    evec = psImageRecycle(evec,  in->numCols, in->numCols, in->type.type);
     887    eval = psVectorRecycle(eval, in->numCols, in->type.type);
     888
     889    // Initialize data
     890    int numRows = in->numRows;
     891    int numCols = in->numCols;
     892
     893    gsl_matrix *A = gsl_matrix_alloc(numRows, numCols);
     894    gsl_matrix *V = gsl_matrix_alloc(numCols, numCols);
     895    gsl_vector *S = gsl_vector_alloc(numCols);
     896    gsl_vector *work = gsl_vector_alloc(numCols);
     897
     898    // Copy psImage data into GSL matrix data
     899    psImageToGslMatrix(A, in);
     900
     901    // Calculate SVD decomposition
     902    gsl_linalg_SV_decomp(A, V, S, work);
     903
     904    // Copy GSL matrix data to psImage data
     905    gslMatrixToPsImage(evec, V);
     906    gslVectorToPsVector(eval, S);
     907
     908    // Take the square root of eval
     909    for (int i = 0; i < eval->n; i++) {
     910        eval->data.F64[i] = sqrt(eval->data.F64[i]);
     911        /* make sure that these things are sorted! */
     912        if (i > 0) {
     913            assert(eval->data.F64[i] > eval->data.F64[i-1]);
     914        }
     915    }
     916
     917    // Free GSL data
     918    gsl_matrix_free(A);
     919    gsl_matrix_free(V);
     920    gsl_vector_free(S);
     921    gsl_vector_free(work);
     922
     923    return evec;
     924}
  • trunk/psLib/src/math/psMatrix.h

    r10251 r10381  
    2121 *  @author Ross Harman, MHPCC
    2222 *
    23  *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    24  *  @date $Date: 2006-11-29 02:14:49 $
     23 *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
     24 *  @date $Date: 2006-12-01 21:48:47 $
    2525 *
    2626 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    179179);
    180180
     181/// Single value decomposition, provided by Andy Becker
     182psImage *psMatrixSVDSolve(psImage* evec, psVector* eval, const psImage* in);
     183
    181184/// @}
    182185
Note: See TracChangeset for help on using the changeset viewer.