IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 27, 2004, 1:41:42 PM (22 years ago)
Author:
gusciora
Message:

...

File:
1 edited

Legend:

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

    r1879 r1907  
    99 *  @author George Gusciora, MHPCC
    1010 *
    11  *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-09-24 20:08:22 $
     11 *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-09-27 23:41:42 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5353/* DEFINE STATEMENTS                                                         */
    5454/*****************************************************************************/
    55 
    56 /** Preprocessor macro to generate error on a NULL 1DPolynomial */
    57 #define PS_CHECK_NULL_1DPOLY(NAME)                                                          \
    58 if (NAME == NULL || NAME->coeff == NULL) {                                                         \
    59     psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME);                          \
    60 }
    61 
    62 /** Preprocessor macro to generate error on a NULL vector */
    63 #define PS_CHECK_NULL_VECTOR(NAME)                                                          \
    64 if (NAME == NULL || NAME->data.V == NULL) {                                                         \
    65     psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME);                          \
    66 }
    67 
    68 /** Preprocessor macro to generate error for zero length vector */
    69 #define PS_CHECK_EMPTY_VECTOR(NAME)                                                          \
    70 if (NAME->n < 1) {                                                                                  \
    71     psError(__func__,"Invalid operation: %s has zero n value.", #NAME);                             \
    72 }
    73 
    74 /** Preprocessor macro to generate error on differing size vectors */
    75 #define PS_CHECK_VECTOR_SIZE_EQUAL(VEC1, VEC2)                                                          \
    76 if (VEC1->n != VEC2->n) {               \
    77     psError(__func__,"Vector %s has size %d, Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \
    78 }
    79 
    80 /** Preprocessor macro to generate error on a NULL image */
    81 #define PS_CHECK_NULL_IMAGE(NAME)                                                           \
    82 if (NAME == NULL || NAME->data.V == NULL) {                                                         \
    83     psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME);                          \
    84 }
    85 
    86 /** Preprocessor macro to generate error for zero length rows or columns */
    87 #define PS_CHECK_EMPTY_IMAGE(NAME)                                                           \
    88 if (NAME->numCols < 1 || NAME->numRows < 1) {                                                       \
    89     psError(__func__,"Invalid operation: %s has zero rows or columns (%dx%d).", #NAME,              \
    90             NAME->numCols, NAME->numRows);                                                          \
    91 }
    9255
    9356/*****************************************************************************/
     
    692655}
    693656
     657
     658/*****************************************************************************
     659CreateChebyshevPolys(n): this routine takes as input the required order n,
     660and returns as output as a pointer to an array of n psPolynomial1D
     661structures, corresponding to the first n Chebyshev polynomials.
     662 
     663XXX: The output should be static since the Chebyshev polynomials might be
     664used frequently and the data structure created here does not contain the
     665outer coefficients of the Chebyshev polynomials.
     666 *****************************************************************************/
     667static psPolynomial1D **CreateChebyshevPolys(int maxChebyPoly)
     668{
     669    psPolynomial1D **chebPolys = NULL;
     670    int i = 0;
     671    int j = 0;
     672
     673    chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));
     674    for (i = 0; i < maxChebyPoly; i++) {
     675        chebPolys[i] = psPolynomial1DAlloc(i + 1, PS_POLYNOMIAL_ORD);
     676    }
     677
     678    // Create the Chebyshev polynomials.
     679    // Polynomial i has i-th order.
     680    chebPolys[0]->coeff[0] = 1;
     681    chebPolys[1]->coeff[1] = 1;
     682    for (i = 2; i < maxChebyPoly; i++) {
     683        for (j = 0; j < chebPolys[i - 1]->n; j++) {
     684            chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
     685        }
     686        for (j = 0; j < chebPolys[i - 2]->n; j++) {
     687            chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
     688        }
     689    }
     690
     691    return (chebPolys);
     692}
     693
     694
     695
     696psPolynomial1D* p_psVectorFitPolynomial1DCheby(psPolynomial1D* myPoly,
     697        const psVector* restrict x,
     698        const psVector* restrict y,
     699        const psVector* restrict yErr)
     700{
     701    int j;
     702    int k;
     703    int n = x->n;
     704    psPolynomial1D **chebPolys = CreateChebyshevPolys(myPoly->n);
     705    ;
     706    float fac;
     707    float sum;
     708    /*
     709        fac = 2.0/((float) n);
     710        for (j=0;j<n;j++) {
     711            sum = 0.0;
     712            for (k=0;k<n;k++) {
     713                sum+= y->data.F64[k] *
     714                      cos(M_PI * ((float) j) * (0.5 + ((float) k)) / ((float) n));
     715    //            sum+= y->data.F64[k] *
     716    //                  cos(M_PI * ((float) j) * (-0.5 + ((float) k)) / ((float) n)) *
     717    //                  cos(M_PI * (-0.5 + ((float) k)) / ((float) n));
     718     
     719            }
     720            myPoly->coeff[j] = fac * sum;
     721     
     722        }
     723        return(myPoly);
     724    */
     725
     726    fac = 2.0/((float) n);
     727    for (j=0;j<myPoly->n;j++) {
     728        sum = 0.0;
     729        for (k=1;k<n;k++) {
     730            sum+= (y->data.F64[k] *
     731                   psPolynomial1DEval((float) x->data.F64[k], chebPolys[j]));
     732        }
     733        myPoly->coeff[j] = fac * sum;
     734    }
     735    return(myPoly);
     736}
     737
    694738/******************************************************************************
    695739psVectorFitPolynomial1D():  This routine must fit a polynomial of degree
     
    704748 
    705749XXX: Must do: if yErr==NULL, set all errors equal.
     750 
     751XXX: type is currently ignored.  Must implement this for Chebyshev
     752polynomials.
    706753 *****************************************************************************/
    707754psPolynomial1D* psVectorFitPolynomial1D(psPolynomial1D* myPoly,
     
    710757                                        const psVector* restrict yErr)
    711758{
     759    // XXX: Create a p_psVectorFitPolynomial1DOrd() function.  Here, we
     760    // should only be calling that or the Cheby function.
     761
     762    if (myPoly->type == PS_POLYNOMIAL_CHEB) {
     763        return(p_psVectorFitPolynomial1DCheby(myPoly, x, y, yErr));
     764    }
     765
    712766    int polyOrder = myPoly->n;
    713767    psImage* A = NULL;
Note: See TracChangeset for help on using the changeset viewer.