IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26551


Ignore:
Timestamp:
Jan 8, 2010, 4:45:02 PM (16 years ago)
Author:
Paul Price
Message:

Allow trimming of singular values when solving using SVD.

Location:
branches/eam_branches/20091201/psLib/src/math
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/psLib/src/math/psMatrix.c

    r26372 r26551  
    10331033}
    10341034
    1035 psVector *psMatrixSolveSVD(psVector *out, const psImage *matrix, const psVector *vector)
     1035psVector *psMatrixSolveSVD(psVector *out, const psImage *matrix, const psVector *vector, float thresh)
    10361036{
    10371037    #define psMatrixSolveSVD_EXIT {psFree(out); return NULL; }
     
    10631063    gsl_vector_free(work);
    10641064
     1065    if (isfinite(thresh) && thresh > 0.0) {
     1066        // Trim the singular values
     1067        thresh *= gsl_vector_get(S, 0);
     1068        psTrace("psLib.math", 8, "Singular value 0: %lf", gsl_vector_get(S, 0));
     1069        for (int i = 1; i < numCols; i++) {
     1070            double value = gsl_vector_get(S, i); // Singular value
     1071            if (value < thresh) {
     1072                psTrace("psLib.math", 5, "Trimming singular value %d: %lf", i, value);
     1073                gsl_vector_set(S, i, 0.0);
     1074                for (int j = 0; j < numCols; j++) {
     1075                    // Being thorough; probably unnecessary
     1076                    gsl_matrix_set(V, j, i, 0.0);
     1077                    gsl_matrix_set(A, j, i, 0.0);
     1078                }
     1079            } else {
     1080                psTrace("psLib.math", 5, "Singular value %d: %lf", i, value);
     1081            }
     1082        }
     1083    }
     1084
    10651085    // Solve system (or minimise least-squares if overconstrained): Ax = b
    10661086    gsl_vector *b = gsl_vector_alloc(numCols); // Vector b
     
    11961216    return true;
    11971217}
     1218
  • branches/eam_branches/20091201/psLib/src/math/psMatrix.h

    r26372 r26551  
    192192    psVector *solution,                 ///< Solution to output, or NULL
    193193    const psImage *matrix,              ///< Matrix to be solved
    194     const psVector *vector              ///< Vector of values
     194    const psVector *vector,             ///< Vector of values
     195    float thresh                        ///< Threshold relative to maximum for trimming singular values
    195196    );
    196 
    197197
    198198/// Single value decomposition (original by Andy Becker, updated by EAM)
Note: See TracChangeset for help on using the changeset viewer.