Example #1
0
PPCA::PPCA(double** A, int r, int c, int k, int itr){

	this->data.setlength(r, c);

	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			data[i][j].x = A[i][j];
		    data[i][j].y = 0; }
		
	}
	////////////////
	center();
	////////////////
	//normalize(data);

	this->m=r;
	this->n=c;
	this->k=k;
	this->itr=itr;

	////////////////
	dtrans();
	////////////////
}
Example #2
0
/**
   Compute Von Karman covariance function at separations computed from the grid
   size nx and sampling dx, with Fried parameter of r0, and outerscale of L0.  
   ninit is the initial side size of the atm array to start with.
*/
static vkcov_t* vkcov_calc(double r0, double L0, double dx, long n, long ninit){
    if(L0>9000) L0=INFINITY;/*L0 bigger than 9000 is treated as infinity. */
    vkcov_t *node=vkcov_get(r0, L0, dx, n, ninit);
    if(node) return node;
    node=mycalloc(1,vkcov_t);
    node->r0=r0;
    node->L0=L0;
    node->dx=dx;
    node->n=n;
    node->ninit=ninit;
    long nroot=(long)round(log2((double)n-1));
    node->next=head;
    if(r0>=L0){
	error("Illegal parameter: r0=%g, L0=%g\n", r0, L0);
    }
    head=node;
    dmat *r=dnew(2, nroot+2);
    double sqrt2=sqrt(2);
    IND(r,0,0)=0;
    IND(r,1,0)=0;
    for(long i=0; i<=nroot; i++){
	long j=1<<i;
	IND(r,0,i+1)=j*dx;
	IND(r,1,i+1)=j*dx*sqrt2;
    }
    double D=(n-1)*dx;
    node->cov=turbcov(r, D*sqrt(2), r0, L0);
    dfree(r);
    dmat *rc0=dnew(ninit*ninit, ninit*ninit);
    dmat*  rc=rc0;
    double dx2=dx*(n-1)/(ninit-1);
    for(long j=0; j<ninit; j++){
	double y=dx2*j;
	for(long i=0; i<ninit; i++){
	    double x=dx2*i;
	    long k=i+j*ninit;
	    for(long j2=0; j2<ninit; j2++){
		double y2=dx2*j2;
		for(long i2=0; i2<ninit; i2++){
		    double x2=dx2*i2;
		    long k2=i2+j2*ninit;
		    IND(rc,k2,k)=sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
		}
	    }
	}
    }
    node->C=turbcov(rc0, D*sqrt(2), r0, L0);
    dfree(rc0);
    dmat *u=NULL, *s=NULL, *v=NULL;
    dsvd(&u, &s, &v, node->C);
    dcwpow(s, 1./2.);
    node->K=ddup(u);
    dmuldiag(node->K, s);

    dcwpow(s, -1);
    dmuldiag(u, s);
    node->KI=dtrans(u);
    dfree(u);
    dfree(v);
    dfree(s);
    /*we have: K*K'==C */
    return node;
}