IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 6, 2004, 8:07:53 PM (22 years ago)
Author:
gusciora
Message:

/

File:
1 edited

Legend:

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

    r1188 r1189  
    600600
    601601
    602 // NOTE: rewrite so there is no maximum order for the polynomials.
    603 #define MAX_POLY_ORDER 10
    604 #define MAX_POLYNOMIAL_TERMS  (((MAX_POLY_ORDER+1) * (MAX_POLY_ORDER + 2)) / 2)
    605 int MyInfoLevel = 0;
    606 /** @brief This procedure calculates various combinations of powers of x and y
    607  *   and stores them in the data structure sums[][].  After it completes:
    608  *          sums[i][j] == x^i * y^j
    609  */
    610 void buildSums(double x,
    611                double y,
    612                /*@out@*/double sums[MAX_POLY_ORDER+1][MAX_POLY_ORDER+1],
    613                int polyOrder)
    614 {
    615     int         i = 0;          // loop index variable
    616     int         j = 0;          // loop index variable
    617     double       xSum = 0.0;    // The running sum of X terms
    618     double       ySum = 0.0;    // The running sum of Y terms
    619 
     602/******************************************************************************
     603p_psBuildSums1D(x, sums, polyOrder): this routine calculates the powers of
     604input parameter "x" between 0 and input parameter polyOrder.  The result is
     605returned as a psVector.
     606 *****************************************************************************/
     607psVector *p_psBuildSums1D(double x,
     608                          int polyOrder)
     609{
     610    int       i = 0;
     611    double    xSum = 0.0;
     612    psVector *sums = NULL;
     613
     614    sums = psVectorAlloc(polyOrder+1, PS_TYPE_F32);
    620615    xSum = 1.0;
    621     ySum = 1.0;
    622616    for(i=0;i<=polyOrder;i++) {
    623         ySum = xSum;
    624         for(j=0;j<=polyOrder;j++) {
    625             sums[i][j] = ySum;
    626             ySum*= y;
    627         }
     617        sums->data.F32[i] = xSum;
    628618        xSum*= x;
    629619    }
    630 }
    631 
    632 /** @brief The coefficients of the matrix in equation (7) from the ADD will
    633  * be very large if the x and y values are in the 0-511 range (ie: the sum y^7
    634  * for all 0<y<512).  In order to avoid potential numerical instability, we
    635  * added ability to scale those x,y values arbitrarily.  The following code
    636  * creates a 1-D matrix imageScalingFactors[] which holds the scaled down
    637  * values of x,y: the i-th element of imageScalingFactors[] contains the scaled
    638  * down value for x=i, or y=i.
    639  *
    640  *     Input:
    641  *     <ul>
    642  *         <li>height
    643  *         <li>width
    644  *     </ul>
    645  *
    646  *     Output:
    647  *     <ul>
    648  *         <li>imageScalingFactors
    649  *     </ul>
    650  *
    651  * @return error status (PsError) indicating error information, or NULL on
    652  * success.
    653  */
    654 void buildImageScalingFactors(int height,
    655                               int width,
    656                               float **imageScalingFactors)
    657 {
    658     int maxDim = 0;             // The largest dimension of the image.
     620    return(sums);
     621}
     622
     623
     624/******************************************************************************
     625p_psBuildSums1D(x): this routine returns a psVector with "x" elements.  The
     626values of the vector will be scaled uniformly between -1.0 and 1.0.
     627 *****************************************************************************/
     628psVector *psBuildImageScalingFactors(int x)
     629
     630{
    659631    int i = 0;                  // loop index variable.
    660 
    661     // Calculate the maximum dimensional extent of the image.
    662     if (height > width) {
    663         maxDim = height;
    664     } else {
    665         maxDim = width;
    666     }
    667 
    668 
    669     // Allocate memory for the output array.
    670     *imageScalingFactors = (float *) psAlloc((maxDim+10) * sizeof(float));
    671 
    672     // This code is somewhat arbitrary.  For an image with a height/width
    673     // of 512x512, the scaling factors will be between 0.0-1.0.
    674     for (i=0;i<maxDim;i++) {
    675         (*imageScalingFactors)[i] = (((float) i) / ((float) maxDim)) - 0.5;
    676         //        (*imageScalingFactors)[i] = ((float) i);
    677     }
    678 }
    679 
    680 
    681 /** @brief buildPolyTerms(): this routine computes a 3-D array polyTerms[] that
    682  *         holds terms for the polynomial that is used to model the sky
    683  *         background.  We use this array primarily for convenience in many
    684  *         computations involving that sky model polynomials. It is defined as:
    685  *
    686  *             polyTerms[poly][i][0] = the power to which X is raised in the
    687  *         i-th term of in an poly-order sky
    688  *         background polynomial</P>.
    689  *             polyTerms[poly][i][1] = the power to which Y is raised in the
    690  *         i-th term of in an poly-order sky
    691  *         background polynomial</P>.
    692  *
    693  *    NOTE: the C_0 term defined in the ADD begins at i=2 in our data
    694  *        structures (ie. the x/y powers of the i-th term in the sky model
    695  *        polynomial are actually stored at polyTerms[][i+2][].  There are two
    696  *        reasons for this.  First, there is a term prior to C_0 in equation
    697  *        (7) of the ADD.  Second, our linear algebra codes assume data is
    698  *        stored offset from index 1.
    699  *
    700  *     Input:
    701  *     <ul>
    702  *         <li>polyTerms[][][]
    703  *     </ul>
    704  *
    705  *     Output:
    706  *     <ul>
    707  *         <li>polyTerms[][][]
    708  *     </ul>
    709  *
    710  * @return error status (PsError) indicating error information, or NULL on
    711  * success.
    712  */
    713 void buildPolyTerms(/*@out@*/ int polyTerms[MAX_POLY_ORDER+1][(MAX_POLYNOMIAL_TERMS+2)][2])
    714 {
    715     int polyOrder=0;                    // loop index variable.
    716     int i=0;                            // loop index variable.
    717     int term = 0;                       // loop index variable.
    718     int num=0;                          // loop index variable.
    719 
    720     for(polyOrder=0;polyOrder<=MAX_POLY_ORDER;polyOrder++) {
    721         // The following 4 terms should not be used in any of the subsequent
    722         // computation.  We initialize them to zero in order to produce stable
    723         // results for debugging purposes should they mistakenly be used.
    724         polyTerms[polyOrder][0][0] = 0;
    725         polyTerms[polyOrder][0][1] = 0;
    726         polyTerms[polyOrder][1][0] = 0;
    727         polyTerms[polyOrder][1][1] = 0;
    728 
    729         // This code segment loops through each term i in the polynomial and
    730         // calculates the power to which x/y are raised in that i-th term.
    731         i=2;
    732         for (term=0;term<=polyOrder;term++) {
    733             for (num=0;num<=term;num++) {
    734                 polyTerms[polyOrder][i][0] = term-num;
    735                 polyTerms[polyOrder][i][1] = num;
    736                 if (MyInfoLevel > 2) {
    737                     printf("%d-th order Sky polynomial term %d is x^%d y^%d\n",
    738                            polyOrder, i,
    739                            polyTerms[polyOrder][i][0], polyTerms[polyOrder][i][1]);
    740                 }
    741                 i++;
    742             }
    743         }
    744     }
    745 }
    746 
     632    psVector *imageScalingFactors = NULL;
     633
     634
     635    imageScalingFactors = psVectorAlloc(x, PS_TYPE_F32);
     636
     637    for (i=0;i<x;i++) {
     638        imageScalingFactors->data.F32[i] = (((float) 2*i) / ((float) x)) - 1.0;
     639    }
     640    return(imageScalingFactors);
     641}
    747642
    748643/** @brief This routine checks if all polyOrder-th terms in the polyOrder-th
     
    863758                     const psVector *restrict yErr)
    864759{
     760    /*
     761        int polyOrder = myPoly->n;
     762        float **A;
     763     
     764     
     765        // Numerical Recipes routines are all index offset 1.
     766        B = (float *) psAlloc((polyOrder+2) * sizeof(float));
     767        ludIndex = (int *) psAlloc((polyOrder+2) * sizeof(int));
     768     
     769        A = (float **) psAlloc((polyOrder+2) * sizeof(float *));
     770        for(i=0;i<(polyOrder+2);i++) {
     771            A[i] = (float *) psAlloc((polyOrder+2) * sizeof(float));
     772        }
     773     
     774        // Initialize data structures.
     775        for(i=0;i<(polyOrder+2);i++) {
     776            B[i] = 0.0;
     777            ludIndex[i] = 0;
     778            for(j=0;j<(polyOrder+2);j++) {
     779                A[i][j] = 0.0;
     780            }
     781        }
     782     
     783        for(k=1;k<(polyOrder+2);k++) {
     784            for (i=0;i<x->n;i++) {
     785                B[k]+= y->data.F32[i] * (pow(x->data.F32[i], k));
     786            }
     787        }
     788        for(k=1;k<(polyOrder+2);k++) {
     789            for(i=1;i<(polyOrder+2);i++) {
     790                for (i=0;i<x->n;i++) {
     791                    A[k][j]+= (pow(y->data.F32[i], k) * pow(x->data.F32[i], j));
     792                }
     793            }
     794        }
     795     
     796     
     797    */
    865798    return(NULL);
    866799}
    867 
    868 
    869 
    870 
    871 
    872 
Note: See TracChangeset for help on using the changeset viewer.