void do_pca(int nrm) { printf("Doing PCA\n"); n_remove=nrm; printf(" - Computing covariance\n"); compute_covariance(); printf(" - Diagonalizing covariance\n"); diagonalize_covariance(); printf(" - Computing foreground removal matrix\n"); compute_fg_removal(); printf(" - Removing foreground\n"); subtract_foregrounds(); printf("\n"); end_pca(); postprocess_clean_maps(); }
/* This routine computes standard and nonstandard earthquake location error estimates. standard error estimate returned is the covariance matrix of the predicted errors that can be used to derive standard error ellipses. The covariance that is returned is unscaled. It is the true covariance only when the weights are ideal 1/sigma weighting. (Note residual (robust) weighting does not really alter this as the goal of residual weighting is to downweight outliers and reshape the residual distribution to be closer to a normal disltribution. The nonstandard error that is returned is the "model error" defined in Pavlis (1986) BSSA, 76, 1699-1717. It would be preferable in some ways to split these into two modules, but it is more efficient to compute them together. Arguments: -input- h - hypocenter location of point to appraise errors from attbl- Associate array of Arrival structures utbl - associate array of slowness structures o- Location options structure -output- C - 4x4 covariance matrix. Assumed allocated externally and passed here. alloc with modified numerical recipes "matrix" routine. emodel - 4 vector of x,y,z model error estimates Both error estimates have 0 in positions where fix is set. Returns 0 if no problems are encountered. Nonzero return indicates a problem. +1 - Inverse matrix was singular to machine precision, error results are unreliable as svd truncation was need to stabilize calculations. Author: Gary L. Pavlis Written: June 25, 1998 */ void predicted_errors(Hypocenter h, Tbl *attbl, Tbl *utbl, Location_options o, double **C, float *emodel) { Arrival *atimes; Slowness_vector *slow; int natimes; int nslow; int npar, nused, ndata_feq; float **U, **V, s[4]; /* SVD of A = USVT */ float **Agi; /* holds computed generalized inverse */ float *b; /* weighted residual vector (rhs of Ax=b)*/ float *r,*w; /* r=raw residual and w= vector of total weights */ float *reswt; /* we store residual weights seperately to calculate effective degrees of freedom */ int m; /* total number of data points = natimes+2*nslow */ Robust_statistics statistics; int mode; int i,ii,j; /* because o is a dynamic variable, we force the plain pseudoinverse soltuion */ o.generalized_inverse = PSEUDOINVERSE; natimes = maxtbl(attbl); nslow = maxtbl(utbl); m = 2*nslow + natimes; for(i=0,npar=0;i<4;++i) if(!o.fix[i]) ++npar; Agi = matrix(0,3,0,m-1); U = matrix(0,m-1,0,3); V = matrix(0,3,0,3); b=(float *)calloc(m,sizeof(float)); r=(float *)calloc(m,sizeof(float)); w=(float *)calloc(m,sizeof(float)); reswt=(float *)calloc(m,sizeof(float)); if ( (b==NULL) || (r==NULL) || (w==NULL) || (reswt==NULL) ) elog_die(1,"Alloc errors in location error function\n"); statistics = form_equations(ALL, h, attbl,utbl, o, U, b, r, w, reswt,&ndata_feq); svdcmp(U,m,npar,s,V); /* This computes the generalized inverse as the pseudoinverse. This version forces this to be the true pseudoinverse no matter what the user selected as a location option. This is my (glp) prejudice that reporting anything else is a lie.*/ nused = pseudoinverse(U,s,V,m,npar,Agi); if(nused != npar ) { elog_log(0,"predicted_errors function found system of equations was singular, Errors estimates are unreliable\n"); } compute_covariance(Agi,m,npar,4,C,o.fix); /* Now we compute the emodel vector defined in Pavlis (1986) BSSA, 76, 1699-1717. A complication is that we need to do a complex rescan of the arrival and slowness data tables. This is necessary to allow different bounding terms for different phases and to obtain most easily the computed travel time to each stations. We just recompute the travel times and use an associated scale factor. For slowness we just enter a fixed value under and assumption slowness errors do not increase with distance as travel times tend to do. */ mode = RESIDUALS_ONLY; for(i=0;i<natimes;++i) { Travel_Time_Function_Output tto; atimes = (Arrival *) gettbl(attbl,i); tto = calculate_travel_time(*atimes, h,mode); if(tto.time == TIME_INVALID) b[i] = 0.0; else { b[i] = tto.time; b[i] *= w[i]*reswt[i]*atimes->phase->deltat_bound; } } for(i=0,j=natimes;i<nslow;++i,j+=2) { slow = (Slowness_vector *) gettbl(utbl,i); b[j] = slow->phase->deltau_bound; b[j+1]=b[j]; } /* we recycle w here blindly assuming m>n */ compute_emodel(Agi, m, npar, b, w); for(i=0,ii=0;i<4;++i) if(o.fix[i]) emodel[i] = 0.0; else { emodel[i] = b[ii]; ++ii; } free_matrix((char **)Agi,0,3,0); free_matrix((char **)U,0,m-1,0); free_matrix((char **)V,0,3,0); free(b); free(r); free(w); free(reswt); }