IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37643


Ignore:
Timestamp:
Nov 19, 2014, 7:57:16 PM (12 years ago)
Author:
eugene
Message:

adding option to squish the bad pivots

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140904/Ohana/src/libohana/src/gaussj.c

    r37632 r37643  
    11# include <ohana.h>
    2 # define GROWTHTEST 1
    3 # define MAX_RANGE 1.0e9
     2# define GROWTHTEST 0
     3# define VERY_VERBOSE 0
     4# define MAX_RANGE 1.0e16
     5# define MIN_PIVOT 1.0e-7
    46
    57// Gauss-Jordan elimination using full pivots based on Press et al's description.  Substantially
     
    6870# if (GROWTHTEST)
    6971    fprintf (stderr, "maxcol: %d\n", maxcol);
    70     // fprintf (stderr, "full A matrix:\n");
    71     // for (row = 0; row < N; row++) {
    72     //   for (col = 0; col < N; col++) {
    73     //  fprintf (stderr, "%10.3e ", A[row][col]);
    74     //   }
    75     //   fprintf (stderr, "\n");
    76     // }
    77     // fprintf (stderr, "\n");
     72# if (VERY_VERBOSE)
     73    fprintf (stderr, "full A matrix:\n");
     74    for (row = 0; row < N; row++) {
     75      for (col = 0; col < N; col++) {
     76        fprintf (stderr, "%10.3e ", A[row][col]);
     77      }
     78      fprintf (stderr, "\n");
     79    }
     80    fprintf (stderr, "\n");
     81# endif
    7882# endif
    7983
     
    101105    /* rescale by pivot reciprocal */
    102106    double tmpval = 1.0 / A[maxcol][maxcol];
     107
     108    if (fabs(A[maxcol][maxcol]) < MIN_PIVOT) {
     109      // we are ill-conditioned.  set this row & col to 0.0, 1.0 on pivot
     110      fprintf (stderr, "WARNING: elliminating degenerate pivot %lf @ A[%d][%d]\n", A[maxcol][maxcol], maxcol, maxcol);
     111      for (col = 0; col < N; col++) A[maxcol][col] = 0.0;
     112      for (col = 0; col < M; col++) B[maxcol][col] = 0.0;
     113      for (row = 0; row < N; row++) A[row][maxcol] = 0.0;
     114      A[maxcol][maxcol] = 1.0;
     115      continue;
     116    }
     117
     118
    103119    // XXX why is this here (don't I double count this element?) A[maxcol][maxcol] = 1.0;
    104120    A[maxcol][maxcol] = 1.0;
     
    112128#   if (GROWTHTEST)
    113129    fprintf (stderr, "column: %d, maxval : %f, growth: %e, epsilon: %e\n", maxcol, tmpval, growth, epsilon);
    114     // fprintf (stderr, "A diagonal: ");
    115     // for (col = 0; col < N; col++) fprintf (stderr, "%f ", A[col][col]);
    116     // fprintf (stderr, "\n");
     130# if (VERY_VERBOSE)
     131    fprintf (stderr, "A diagonal: ");
     132    for (col = 0; col < N; col++) fprintf (stderr, "%f ", A[col][col]);
     133    fprintf (stderr, "\n");
     134# endif
    117135# endif
    118136
     
    132150  }
    133151
    134 # if (GROWTHTEST)
     152# if (GROWTHTEST && VERY_VERBOSE)
    135153  fprintf (stderr, "final A matrix:\n");
    136   // for (row = 0; row < N; row++) {
    137   //   for (col = 0; col < N; col++) {
    138   //     fprintf (stderr, "%10.3e ", A[row][col]);
    139   //   }
    140   //   fprintf (stderr, "\n");
    141   // }
    142   // fprintf (stderr, "\n");
     154  for (row = 0; row < N; row++) {
     155    for (col = 0; col < N; col++) {
     156      fprintf (stderr, "%10.3e ", A[row][col]);
     157    }
     158    fprintf (stderr, "\n");
     159  }
     160  fprintf (stderr, "\n");
    143161# endif
    144162
Note: See TracChangeset for help on using the changeset viewer.