Thompson - Computing for Scientists and Engineers (523188), страница 38
Текст из файла (страница 38)
Show that another sufficient condition for reciprocity is that there be only one data point, N = 1. nThe first condition derived in part (c) of this exercise is not particularly relevant,since it implies that after normalization the Y fit and they data coincide at all datapoints, which is an unlikely situation. If this were true, then the only contributionsto the objective function (6.48) would come from discrepancies between the valuesof the xj and Xj. Both conditions for reciprocity are helpful, however, in checkingthe correctness of programs for the optimum normalization values. This observationindicates how results that are trivial in mathematics are sometimes useful when computing for scientists and engineers.In applications one uses data renormalization when, for a fixed instrumentationsetup, one can make a set of measurements for which the model is reliable but an instrument needs to be calibrated in terms of an overall normalization.
Then the onlysources of uncertainty are systematic and random errors in the data. The latter errorsshould be taken into account by appropriately choosing weights in (6.48).The alert reader will have noticed that I have slipped by a point that needs to bediscussed. Namely, the weights depend upon the data, as we acknowledge by writing them as wyj rather than wj. How does this affect the analysis? Why not findout yourself?Exercise 6.18(a) Show that formula (6.50) for the fitting-function value normalization, Nf, isunaffected by the dependence of the weights on the data values.(b) Prove that if the weights depend on the data as a single power of the data,and if the definition of the objective function is modified so that it includes division by the sum of all the weights, then formula (6.52) for Nd is unaltered.
nYou can see intuitively why the data normalization formula will be different ifdivision by total weight is not included, because if the weights depend on inversepowers of the data, then is reduced partly by scaling up the data values as theyappear in the weights. One good reason not to include the total weight as a divisorin the objective function is that when the weights are just inversely proportional tothe data,then we have Poisson statistics and is proportional to thestatistical chi-squared, for which many properties and interpretations are known. Ihave discussed elsewhere (Thompson, 1992) the particularly common weightingmodel with Poisson statistics. For consistency with the rest of our treatment, and6.4 LEAST-SQUARES NORMALIZATION FACTORS203with the works of others, the slightly wrong (but convenient) formula (6.52) for Ndwill be maintained as-is.
Alternatively, the formula for Nd becomes correct at theexpense of a different formula foras shown in Exercise 6.18 (b).For the X and x variables that appear in the objective function (6.48) the procedures for finding best-fit normalizations require only replacement of y and Y by xand X in (6.50) or (6.52). Indeed, by use of such formulas one may have any pairof renormalization factors drawn from (x,X), (Xx), (y,Y), or (Y,y), where the notation means that the first of the pair is normalized to the second of the pair. Theseoptions are available in the program Least Squares Normalization that we develop below.You may be wondering what has happened to the effects of correlations in thedata.
These are implicit in the weight factors, which certainly do have major effectson the values of normalization constants, as (6.50) and (6.52) indicate and as youcan verify by using the program with different weight factors.The best-fit objective functionThe final analysis topic in this section on least-squares normalization factors is to derive an expression for the minimized objective function,that is obtained afterrenormalization of either the fitting-function values or the data values.A brute-force numerical method would be to use the normalization factors to recompute the normalized values, then to insert these in expression (6.48) for the objective function.
If we do some algebra ahead of time, we can be accumulating thenecessary sums while performing the summations for the normalization factors, thusimproving computational efficiency and reducing the amount of code needed. Sowhy don’t you try some more algebra?Exercise 6.19Consider the case of normalizing the fitting function Y to the data y, for whichthe normalization factor is given by (6.50). In the objective function (6.48) expand the square of the differences of y values and expand this sum into threeseparate sums. Next, replace each Yj by the substitution (6.49) in terms of theunnormalized values. Finally, use the result for Nf given by (6.50) to eliminateone of the sums in order to obtain the minimum objective function(6.53)in which all the summations involve only values before normalization.
nBy appropriately relabeling variables, this formula is applicable to normalization of ydata, x data, or x fits. Indeed, by the use of function references in a program, eventhis is not necessary, as the next subsection shows.204LEAST-SQUARES ANALYSIS OF DATAFrom our example with the two independent variables x and y, you can see howto generalize the treatment from a bivariate system to a multivariate one. Those variables that are normalized, such as y or Y, get a reduced value of their contribution tothe objective function.
Those that are not normalized, such as x or X, make an unchanged contribution to . This simple extension arises from the assumed independence of the variables and their weightings.Program for normalizing factorsThe program Least Squares Normalization is designed to illustrate using theformulas derived earlier in this section for computing the normalization factor (6.50)and the resulting minimum objective function (6.53). Although the function NormObj that computes these is written in terms of normalizing the fit to the data, thevariable choice in the main program lets you use the same function to compute anyof the other three combinations of x or y quantities.PROGRAM 6.1 Least-squares normalization factors and their minimum objective functions.#include <stdio.h>#include <math.h>#define MAX 101/* Least Squares Normalization *//* to test function NormObj */double xd[MAX] ,xw[MAX],xf[MAX];double yd[MAX],yw[MAX],yf[MAX];double norm[4];doublexdin,xwin,xfin,ydin,ywin,yfin,omin;int N, j,choice;double NormObj();printf("Least Squares Normalization\n");N = 1;while(N>O){printf("\nHow many data, N (N=O to end)? "); scanf("%i",&N);if ( N == 0 ){printf("\nEnd Least Squares Normalization"); exit(O);}if(N>MAX-1)printf( "!! N=%i > array size %i\n",N,MAX-1);6.4 LEAST-SQUARES NORMALIZATION FACTORS205else{printf("\nInput j=l to %i sets as\n",N);printf("xdata,mweight,xfit,ydata,yweight,yfit");for ( j = 1; j <= N; j++ ){printf("\n%i: ",j);scanf("%lf%lf%lf",&xdin,&xwin,&xfin);scanf("%lf%lf%lf",&ydin,&ywin,&yfin);xd[j] = xdin; xw[j] = xwin; xf[j] = xfin;yd[j] = ydin; yw[j] = ywin; yf[j] = yfin;}choice = 1;while ( choice > 0 )printf("\n\nNorrmlization choice: (0 for new data set)\n");printf("1: xdata to xfit2: xfit to xdata\n");printf("3: ydata to yfit4: yfit to ydata\n");scanf("%i",&choice) ;if ( choice != 0 ){if ( choice <0 || choice > 4 )printf("\n !!choice=%i is out of range (1-4)\n",choice);else{switch(choice){case 1: norm[l] = NormObj(xw,xf,xd,yw,yd,yf,N,&omin);break;case 2: norm[2] = NormObj(xw,xd,xf,yw,yd,yf,N,&omin);break;case 3: norm[3] = NormObj (yw,yf,yd,xw,xd,xf,N,&omin);break;case 4: norm[4] = NormObj(yw,yd,yf,xw,xd,xf,N,&omin);break;}printf("Normalization[%i]=%le\n",choice,norm[choice]);printf("Minimum objective function=%le",omin) ;}}} /*end while choice loop */} /* end while N>O loop */206LEAST-SQUARES ANALYSIS OF DATAdoubleNormObj(yw,yd,yf,xw,xd,xf,N,omin)/* Least-squares best fit for normalizationand minimum objective function *//* Written as if normalizing yf(=yfit) to yd(=ydata) */doubleyw[],yd[],yf[],xw[],xd[],xf[];double *omin;int N;doubleint j;norm,ywyf,num,den,xdif,obj1;num = 0; den= 0; obj1 = 0;for ( j = 1; j <= N; j++ )/* loop over the N data */ywyf = yw[j]*yf[j];num = num+ywyf*yd[j];den = den+ywyf*yf[j];xdif = xd[j]-xf[j];obj1 = obj1+xw[j]*xdif*xdif+yw[j]*yd[j]*yd[j];norm = num/den; /* is normalization of yfit to ydata */*omin = obj1-norm*norm*den;/* minimum objective function */return norm;The over all structure of the program Least Squares Normalization is asfollows.
The outermost loop is controlled by the number of data points N, with program execution being terminated only if N is input as zero. If the usable array size,MAX - 1, where MAX is in a preprocessor definition, is exceeded by N, then a warning is issued and another value of N is requested. The subtraction of unity fromMAX is necessary because, in keeping with general practice in this book, the arraysstart at [1] (as is common in Fortran) rather than at [0] (as in C). Given that N iswithin limits, N sets of six data items each are to be input. The program is nowready to calculate normalization factors for various combinations of x and y data.There are four choices of normalization, as the program output describes. If thevalue of input variable choice is zero, then the loop of choices is terminated, and ifthe value input is negative or greater than 4, a warning message (!!) is issued.
For agiven choice, the function NormObj makes the appropriate normalization calculation, as presented in the preceding subsection, then the normalization and minimumobjective function, (6.53), are output. A new choice of normalization for the samedata is then requested.Function NormObj is a direct implementation of (6.50) and (6.53), coded as ifthe fitted y values are being normalized to the y data.
The normalization factor,norm, is returned as the value of the function, and the minimum objective function,omin, is passed back through the argument list of the function.6.4 LEAST-SQUARES NORMALIZATION FACTORS207The program Least Squares Normalization maybetestedforcorrectnessby running a single data point sample N = 1, as suggested below Exercise 6.17,and by checking that (for any number of data points) if the data and fit values are exactly proportional to each other then Nd and Nf are reciprocal, as derived in Exercise 6.17 (c). Further, under such proportionality there is no contribution tofrom the data-pair values that are normalized.As an example of using Least Squares Normalization, consider the six ydata with their weights in Table 6.2, which are also shown in Figure 6.5 as dataand errors.TABLE 6.2 Data (yj).