IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4321 for trunk/psLib/src/math


Ignore:
Timestamp:
Jun 20, 2005, 12:42:30 PM (21 years ago)
Author:
drobbin
Message:

* empty log message *

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

Legend:

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

    r4160 r4321  
    2121 *  @author Robert DeSonia, MHPCC
    2222 *
    23  *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
    24  *  @date $Date: 2005-06-08 22:28:07 $
     23 *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
     24 *  @date $Date: 2005-06-20 22:42:29 $
    2525 *
    2626 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    191191    psS32 numCols = 0;
    192192    gsl_matrix *lu = NULL;
    193     gsl_permutation perm;
     193    gsl_permutation permGSL;
    194194
    195195
     
    212212
    213213    // Initialize GSL data
    214     perm.size = numCols;
     214    permGSL.size = numCols;
    215215    if (sizeof(size_t) == 4) {
    216216        *outPerm = psVectorRecycle(*outPerm, numCols, PS_TYPE_S32);
     
    225225
    226226    (*outPerm)->n = numCols;
    227     perm.data = (psPtr)((*outPerm)->data.U8);
     227    permGSL.data = (psPtr)((*outPerm)->data.U8);
    228228    lu = gsl_matrix_alloc(numRows, numCols);
    229229
     
    232232
    233233    // Calculate LU decomposition
    234     gsl_linalg_LU_decomp(lu, &perm, &signum); // N.B., uses Gaussian Elimination with partial pivoting.
     234    gsl_linalg_LU_decomp(lu, &permGSL, &signum); // N.B., uses Gaussian Elimination with partial pivoting.
    235235
    236236    // Copy GSL matrix data to psImage data
     
    298298}
    299299
    300 psImage* psMatrixInvert(psImage* outImage, const psImage* inImage, psF32 *det)
     300psImage* psMatrixInvert(psImage* outImage, const psImage* inImage, float *det)
    301301{
    302302    psS32 signum = 0;
     
    346346}
    347347
    348 psF32 *psMatrixDeterminant(const psImage* inImage)
     348float *psMatrixDeterminant(const psImage* in)
    349349{
    350350    psS32 signum = 0;
     
    357357    #define DETERMINANT_EXIT { return NULL; }
    358358    // Error checks
    359     PS_ASSERT_GENERAL_IMAGE_NON_NULL(inImage, DETERMINANT_EXIT);
    360     PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, DETERMINANT_EXIT);
    361     PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(inImage, DETERMINANT_EXIT);
    362     PS_CHECK_SQUARE(inImage, DETERMINANT_EXIT);
     359    PS_ASSERT_GENERAL_IMAGE_NON_NULL(in, DETERMINANT_EXIT);
     360    PS_CHECK_DIMEN_AND_TYPE(in, PS_DIMEN_IMAGE, DETERMINANT_EXIT);
     361    PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(in, DETERMINANT_EXIT);
     362    PS_CHECK_SQUARE(in, DETERMINANT_EXIT);
    363363
    364364    // Initialize data
    365     numRows = inImage->numRows;
    366     numCols = inImage->numCols;
     365    numRows = in->numRows;
     366    numCols = in->numCols;
    367367
    368368    // Allocate GSL structs
    369369    perm = gsl_permutation_alloc(numRows);
    370370    lu = gsl_matrix_alloc(numRows, numCols);
    371     psImageToGslMatrix(lu, inImage);
     371    psImageToGslMatrix(lu, in);
    372372
    373373    // Calculate determinant
     
    480480}
    481481
    482 psImage* psMatrixEigenvectors(psImage* outImage, psImage* inImage)
     482psImage* psMatrixEigenvectors(psImage* out, psImage* in)
    483483{
    484484    psS32 numRows = 0;
     
    486486    gsl_vector *eVals = NULL;
    487487    gsl_eigen_symmv_workspace *w = NULL;
    488     gsl_matrix *out = NULL;
    489     gsl_matrix *in = NULL;
    490 
    491     #define EIGENVECTORS_CLEANUP { psFree(outImage); return NULL; }
    492     // Error checks
    493     PS_ASSERT_GENERAL_IMAGE_NON_NULL(inImage, EIGENVECTORS_CLEANUP);
    494     PS_CHECK_DIMEN_AND_TYPE(inImage, PS_DIMEN_IMAGE, EIGENVECTORS_CLEANUP);
    495     PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(inImage, EIGENVECTORS_CLEANUP);
    496     PS_CHECK_POINTERS(inImage, outImage, EIGENVECTORS_CLEANUP);
    497 
    498     outImage = psImageRecycle(outImage, inImage->numCols, inImage->numRows, inImage->type.type);
     488    gsl_matrix *outGSL = NULL;
     489    gsl_matrix *inGSL = NULL;
     490
     491    #define EIGENVECTORS_CLEANUP { psFree(out); return NULL; }
     492    // Error checks
     493    PS_ASSERT_GENERAL_IMAGE_NON_NULL(in, EIGENVECTORS_CLEANUP);
     494    PS_CHECK_DIMEN_AND_TYPE(in, PS_DIMEN_IMAGE, EIGENVECTORS_CLEANUP);
     495    PS_ASSERT_GENERAL_IMAGE_NON_EMPTY(in, EIGENVECTORS_CLEANUP);
     496    PS_CHECK_POINTERS(in, out, EIGENVECTORS_CLEANUP);
     497
     498    out = psImageRecycle(out, in->numCols, in->numRows, in->type.type);
    499499
    500500    // Initialize data
    501     numRows = inImage->numRows;
    502     numCols = inImage->numCols;
    503 
    504     in = gsl_matrix_alloc(numRows, numCols);
    505     psImageToGslMatrix(in, inImage);
    506     out = gsl_matrix_alloc(numRows, numCols);
     501    numRows = in->numRows;
     502    numCols = in->numCols;
     503
     504    inGSL = gsl_matrix_alloc(numRows, numCols);
     505    psImageToGslMatrix(inGSL, in);
     506    outGSL = gsl_matrix_alloc(numRows, numCols);
    507507
    508508    // Allocate GSL structs
     
    511511
    512512    // Non-square matrices not allowed
    513     PS_CHECK_SQUARE(inImage, EIGENVECTORS_CLEANUP);
    514     PS_CHECK_SQUARE(outImage, EIGENVECTORS_CLEANUP);
     513    PS_CHECK_SQUARE(in, EIGENVECTORS_CLEANUP);
     514    PS_CHECK_SQUARE(out, EIGENVECTORS_CLEANUP);
    515515
    516516    // Calculate Eigenvalues and Eigenvectors...Eigenvalues not currently used
    517     gsl_eigen_symmv(in, eVals, out, w);
     517    gsl_eigen_symmv(inGSL, eVals, outGSL, w);
    518518
    519519    // Copy GSL matrix data to psImage data
    520     gslMatrixToPsImage(outImage, out);
     520    gslMatrixToPsImage(out, outGSL);
    521521
    522522    // Free GSL structs
    523     gsl_matrix_free(in);
    524     gsl_matrix_free(out);
     523    gsl_matrix_free(inGSL);
     524    gsl_matrix_free(outGSL);
    525525    gsl_eigen_symmv_free(w);
    526526    gsl_vector_free(eVals);
    527527
    528     return outImage;
     528    return out;
    529529}
    530530
  • trunk/psLib/src/math/psMatrix.h

    r4162 r4321  
    2121 *  @author Ross Harman, MHPCC
    2222 *
    23  *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
    24  *  @date $Date: 2005-06-08 23:40:45 $
     23 *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
     24 *  @date $Date: 2005-06-20 22:42:29 $
    2525 *
    2626 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    7676    psImage* outImage,                 ///< Image to return, or NULL for in-place substitution.
    7777    const psImage* inImage,            ///< Image to be inverted
    78     psF32 *det                         ///< Determinant to return, or NULL
     78    float *det                         ///< Determinant to return, or NULL
    7979);
    8080
     
    8787 *  @return  float: Determinant from psImage.
    8888 */
    89 psF32 *psMatrixDeterminant(
    90     const psImage* inMatrix        ///< Image used to calculate determinant.
     89float *psMatrixDeterminant(
     90    const psImage* in                  ///< Image used to calculate determinant.
    9191);
    9292
     
    129129 */
    130130psImage* psMatrixEigenvectors(
    131     psImage* outImage,                 ///< Eigenvectors to return, or NULL.
    132     psImage* inImage                   ///< Input image.
     131    psImage* out,                      ///< Eigenvectors to return, or NULL.
     132    psImage* in                        ///< Input image.
    133133);
    134134
  • trunk/psLib/src/math/psMinimize.c

    r4225 r4321  
    99 *  @author GLG, MHPCC
    1010 *
    11  *  @version $Revision: 1.122 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-06-13 20:18:18 $
     11 *  @version $Revision: 1.123 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-06-20 22:42:30 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    562562
    563563// XXX EAM this is my re-implementation of MinLM
    564 psBool psMinimizeLMChi2(psMinimization *min,
    565                         psImage *covar,
    566                         psVector *params,
    567                         const psVector *paramMask,
    568                         const psArray *x,
    569                         const psVector *y,
    570                         const psVector *yErr,
    571                         psMinimizeLMChi2Func func)
     564bool psMinimizeLMChi2(psMinimization *min,
     565                      psImage *covar,
     566                      psVector *params,
     567                      const psVector *paramMask,
     568                      const psArray *x,
     569                      const psVector *y,
     570                      const psVector *yErr,
     571                      psMinimizeLMChi2Func func)
    572572{
    573573    PS_ASSERT_PTR_NON_NULL(min, NULL);
     
    14261426/******************************************************************************
    14271427 *****************************************************************************/
    1428 psMinimization *psMinimizationAlloc(psS32 maxIter,
    1429                                     psF32 tol)
     1428psMinimization *psMinimizationAlloc(int maxIter,
     1429                                    float tol)
    14301430{
    14311431    PS_ASSERT_INT_NONNEGATIVE(maxIter, NULL);
     
    19121912#define PS_MINIMIZE_POWELL_LINEMIN_ERROR_TOLERANCE 0.01
    19131913
    1914 psBool psMinimizePowell(psMinimization *min,
    1915                         psVector *params,
    1916                         const psVector *paramMask,
    1917                         const psArray *coords,
    1918                         psMinimizePowellFunc func)
     1914bool psMinimizePowell(psMinimization *min,
     1915                      psVector *params,
     1916                      const psVector *paramMask,
     1917                      const psArray *coords,
     1918                      psMinimizePowellFunc func)
    19191919{
    19201920    PS_ASSERT_PTR_NON_NULL(min, NULL);
     
    21892189psMinimizePowell().
    21902190 *****************************************************************************/
    2191 psBool psMinimizeChi2Powell(psMinimization *min,
    2192                             psVector *params,
    2193                             const psVector *paramMask,
    2194                             const psArray *coords,
    2195                             const psVector *value,
    2196                             const psVector *error,
    2197                             psMinimizeChi2PowellFunc func)
     2191bool psMinimizeChi2Powell(psMinimization *min,
     2192                          psVector *params,
     2193                          const psVector *paramMask,
     2194                          const psArray *coords,
     2195                          const psVector *value,
     2196                          const psVector *error,
     2197                          psMinimizeChi2PowellFunc model)
    21982198{
    21992199    myValue = (psVector *) value;
    22002200    myError = (psVector *) error;
    22012201
    2202     Chi2PowellFunc = func;
     2202    Chi2PowellFunc = model;
    22032203
    22042204    return(psMinimizePowell(min, params, paramMask, coords, myPowellChi2Func));
  • trunk/psLib/src/math/psMinimize.h

    r4285 r4321  
    88 *  @author GLG, MHPCC
    99 *
    10  *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2005-06-16 03:51:58 $
     10 *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2005-06-20 22:42:30 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5656*/
    5757psMinimization *psMinimizationAlloc(
    58     psS32 maxIter,                     ///< Number of minimization iterations to perform.
    59     psF32 tol                          ///< Requested error tolerance
     58    int maxIter,                       ///< Number of minimization iterations to perform.
     59    float tol                          ///< Requested error tolerance
    6060);
    6161
     
    111111 *  @return psBool:   True if successful.
    112112 */
    113 psBool psMinimizeLMChi2(
     113bool psMinimizeLMChi2(
    114114    psMinimization *min,               ///< Minimization specification
    115115    psImage *covar,                    ///< Covariance matrix
     
    167167 *  @return psBool:   True if successful.
    168168 */
    169 psBool psMinimizePowell(
     169bool psMinimizePowell(
    170170    psMinimization *min,               ///< Minimization specification
    171171    psVector *params,                  ///< "Best guess" for parameters that minimize func
     
    211211 *  @return psBool:   True is successful.
    212212 */
    213 psBool psMinimizeChi2Powell(
     213bool psMinimizeChi2Powell(
    214214    psMinimization *min,               ///< Minimization specification
    215215    psVector *params,                  ///< "Best guess" for parameters that minimize func
     
    218218    const psVector *value,             ///< Measured values at the coordinates
    219219    const psVector *error,             ///< Errors in the measure values (or NULL)
    220     psMinimizeChi2PowellFunc func      ///< Specified function
     220    psMinimizeChi2PowellFunc model     ///< Specified function
    221221);
    222222
Note: See TracChangeset for help on using the changeset viewer.