Changeset 12289
- Timestamp:
- 05/25/12 15:23:23 (13 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 1 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified issm/trunk-jpl/src/c/Container/Observations.cpp ¶
r12282 r12289 162 162 163 163 /*Output and Intermediaries*/ 164 int nobs,i,j,k;165 double range;164 int i,j,k; 165 double distance; 166 166 Observation *observation1 = NULL; 167 167 Observation *observation2 = NULL; 168 int *indices = NULL;169 168 170 169 int *counter= (int*)xmalloc(n*sizeof(int)); … … 175 174 observation1=(Observation*)this->GetObjectByOffset(i); 176 175 177 for(j= 0;j<n;j++){178 range=x[j]; _assert_(range>=0.);176 for(j=i+1;j<this->Size();j++){ 177 observation2=(Observation*)this->GetObjectByOffset(j); 179 178 180 /*Find all observations that are in range*/181 this->quadtree->RangeSearch(&indices,&nobs,observation1->x,observation1->y,range);179 distance=sqrt(pow(observation1->x - observation2->x,2.) + pow(observation1->y - observation2->y,2.)); 180 if(distance>x[n-1]) continue; 182 181 183 for (k=0;k<nobs;k++){ 184 observation2 = (Observation*)this->GetObjectByOffset(indices[k]); 185 gamma[j] += 1./2.*pow(observation1->value - observation2->value,2.); 186 } 182 int index = int(distance/(x[1]-x[0])); 183 if(index>n-1) index = n-1; 184 if(index<0) index = 0; 187 185 188 counter[j] += nobs;189 xfree((void**)&indices);186 gamma[index] += 1./2.*pow(observation1->value - observation2->value,2.); 187 counter[index] += 1; 190 188 } 191 189 } 192 190 193 191 /*Normalize semivariogram*/ 194 for(j=0;j<n;j++){ 195 if(counter[j]) gamma[j] = gamma[j]/double(counter[j]); 192 gamma[0]=0; 193 for(k=0;k<n;k++){ 194 if(counter[k]) gamma[k] = gamma[k]/double(counter[k]); 196 195 } 197 196 -
TabularUnified issm/trunk-jpl/src/c/modules/Krigingx/Krigingx.cpp ¶
r12250 r12289 138 138 /*Get list of observations for current point*/ 139 139 observations->ObservationList(&x,&y,&obs,&n_obs,x_interp[idx],y_interp[idx],range); 140 if(n_obs==0){ 141 predictions[idx] = -999.; 142 error[idx] = -999.; 143 continue; 144 } 140 145 141 146 /*Allocate intermediary matrix and vectors*/ 147 142 148 Gamma = (double*)xmalloc(n_obs*n_obs*sizeof(double)); 143 149 gamma0 = (double*)xmalloc(n_obs*sizeof(double)); … … 147 153 for(i=0;i<n_obs;i++){ 148 154 for(j=0;j<=i;j++){ 149 Gamma[i*n_obs+j] = variogram->SemiVariogram(x[i]-x[j],y[i]-y[j]); 155 //Gamma[i*n_obs+j] = variogram->SemiVariogram(x[i]-x[j],y[i]-y[j]); 156 Gamma[i*n_obs+j] = variogram->Covariance(x[i]-x[j],y[i]-y[j]); 150 157 Gamma[j*n_obs+i] = Gamma[i*n_obs+j]; 151 158 } … … 154 161 155 162 /*Get semivariogram vector associated to this location*/ 156 for(i=0;i<n_obs;i++) gamma0[i] = variogram->SemiVariogram(x[i]-x_interp[idx],y[i]-y_interp[idx]); 163 //for(i=0;i<n_obs;i++) gamma0[i] = variogram->SemiVariogram(x[i]-x_interp[idx],y[i]-y_interp[idx]); 164 for(i=0;i<n_obs;i++) gamma0[i] = variogram->Covariance(x[i]-x_interp[idx],y[i]-y_interp[idx]); 157 165 158 166 /*Solve the three linear systems*/ -
TabularUnified issm/trunk-jpl/src/c/objects/Kriging/ExponentialVariogram.cpp ¶
r12200 r12289 59 59 60 60 /*Variogram function*/ 61 /*FUNCTION ExponentialVariogram::Covariance{{{1*/ 62 double ExponentialVariogram::Covariance(double deltax,double deltay){ 63 /*The covariance can be deduced from the variogram from the following 64 * relationship: 65 * 2 gamma = C(x,x) + C(y,y) -2 C(x,y) 66 * so 67 * C(h) = sill - gamma */ 68 double h,a,cova; 69 70 /*Calculate length*/ 71 h=sqrt(pow(deltax,2.)+pow(deltay,2.)); 72 73 /*return covariance*/ 74 a = 1./3.; 75 cova = (sill-nugget)*exp(-h/(a*range)); 76 return cova; 77 } 78 /*}}}*/ 61 79 /*FUNCTION ExponentialVariogram::SemiVariogram{{{1*/ 62 80 double ExponentialVariogram::SemiVariogram(double deltax,double deltay){ -
TabularUnified issm/trunk-jpl/src/c/objects/Kriging/ExponentialVariogram.h ¶
r12200 r12289 31 31 /*Variogram functions*/ 32 32 double SemiVariogram(double deltax,double deltay); 33 double Covariance(double deltax,double deltay); 33 34 }; 34 35 #endif /* _EXPONENTIALVARIOGRAM_H */ -
TabularUnified issm/trunk-jpl/src/c/objects/Kriging/GaussianVariogram.cpp ¶
r12282 r12289 59 59 60 60 /*Variogram function*/ 61 /*FUNCTION GaussianVariogram::Covariance{{{1*/ 62 double GaussianVariogram::Covariance(double deltax,double deltay){ 63 /*The covariance can be deduced from the variogram from the following 64 * relationship: 65 * 2 gamma = C(x,x) + C(y,y) -2 C(x,y) 66 * so 67 * C(h) = sill - gamma */ 68 double h2,a,cova; 69 70 /*Calculate length square*/ 71 h2=pow(deltax,2.)+pow(deltay,2.); 72 73 /*return covariance*/ 74 a = 1./3.; 75 cova = (sill-nugget)*exp(-h2/(a*range*range)); 76 77 //if(h2<0.0000001) cova = sill; 78 79 return cova; 80 } 81 /*}}}*/ 61 82 /*FUNCTION GaussianVariogram::SemiVariogram{{{1*/ 62 83 double GaussianVariogram::SemiVariogram(double deltax,double deltay){ … … 70 91 a = 1./3.; 71 92 gamma = (sill-nugget)*(1.-exp(-h2/(a*range*range))) + nugget; 93 94 //if(h2>1000*1000) printf("gamma = %g h= %g\n",gamma,sqrt(h2)); 95 printf("h = %g gamma = %g\n",sqrt(h2),gamma); 72 96 return gamma; 73 97 } -
TabularUnified issm/trunk-jpl/src/c/objects/Kriging/GaussianVariogram.h ¶
r12200 r12289 31 31 /*Variogram functions*/ 32 32 double SemiVariogram(double deltax,double deltay); 33 double Covariance(double deltax,double deltay); 33 34 }; 34 35 #endif /* _GAUSSIANVARIOGRAM_H */ -
TabularUnified issm/trunk-jpl/src/c/objects/Kriging/PowerVariogram.cpp ¶
r12230 r12289 60 60 61 61 /*Variogram function*/ 62 /*FUNCTION PowerVariogram::Covariance{{{1*/ 63 double PowerVariogram::Covariance(double deltax,double deltay){ 64 /*The covariance can be deduced from the variogram from the following 65 * relationship: 66 * 2 gamma = C(x,x) + C(y,y) -2 C(x,y) 67 * so 68 * C(h) = sill - gamma */ 69 double h,cova; 70 71 /*Calculate length square*/ 72 h=sqrt(pow(deltax,2.)+pow(deltay,2.)); 73 74 /*return covariance*/ 75 cova = 9999. - this->slope*pow(h,this->power); 76 77 return cova; 78 } 79 /*}}}*/ 62 80 /*FUNCTION PowerVariogram::SemiVariogram{{{1*/ 63 81 double PowerVariogram::SemiVariogram(double deltax,double deltay){ … … 71 89 gamma = this->nugget + this->slope*pow(h,this->power); 72 90 91 //if(h>1000) printf("gamma = %g h=%g\n",gamma,h); 73 92 return gamma; 74 93 } -
TabularUnified issm/trunk-jpl/src/c/objects/Kriging/PowerVariogram.h ¶
r12230 r12289 31 31 /*Variogram functions*/ 32 32 double SemiVariogram(double deltax,double deltay); 33 double Covariance(double deltax,double deltay); 33 34 }; 34 35 #endif /* _POWERVARIOGRAM_H */ -
TabularUnified issm/trunk-jpl/src/c/objects/Kriging/SphericalVariogram.cpp ¶
r12200 r12289 59 59 60 60 /*Variogram function*/ 61 /*FUNCTION SphericalVariogram::Covariance{{{1*/ 62 double SphericalVariogram::Covariance(double deltax,double deltay){ 63 /*The covariance can be deduced from the variogram from the following 64 * relationship: 65 * 2 gamma = C(x,x) + C(y,y) -2 C(x,y) 66 * so 67 * C(h) = sill - gamma */ 68 double h,cova; 69 70 /*Calculate length square*/ 71 h=sqrt(pow(deltax,2.)+pow(deltay,2.)); 72 73 /*return covariance*/ 74 if(h<=range) 75 cova = (sill-nugget)*(1 - (3*h)/(2*range) + pow(h,3.)/(2*pow(range,3.)) ); 76 else 77 cova = 0.; 78 79 return cova; 80 } 81 /*}}}*/ 61 82 /*FUNCTION SphericalVariogram::SemiVariogram{{{1*/ 62 83 double SphericalVariogram::SemiVariogram(double deltax,double deltay){ -
TabularUnified issm/trunk-jpl/src/c/objects/Kriging/SphericalVariogram.h ¶
r12200 r12289 31 31 /*Variogram functions*/ 32 32 double SemiVariogram(double deltax,double deltay); 33 double Covariance(double deltax,double deltay); 33 34 }; 34 35 #endif /* _SPHERICALVARIOGRAM_H */ -
TabularUnified issm/trunk-jpl/src/c/objects/Kriging/Variogram.h ¶
r12207 r12289 13 13 virtual ~Variogram(){}; 14 14 virtual double SemiVariogram(double deltax,double deltay)=0; 15 virtual double Covariance(double deltax,double deltay)=0; 15 16 16 17 }; -
TabularUnified issm/trunk-jpl/src/c/shared/Sorting/binary_search.cpp ¶
r9320 r12289 11 11 #include <stdio.h> 12 12 13 int binary_search(int* poffset,int target, 13 int binary_search(int* poffset,int target,int* sorted_integers,int num_integers){ 14 14 15 15 /*output: */ 16 16 int offset; //offset, if found 17 int found=0; 17 int found=0; //found=0 if target is not found, 1 otherwise. 18 18 19 19 /*intermediary: */ … … 64 64 return found; 65 65 } 66 -
TabularUnified issm/trunk-jpl/src/c/shared/Sorting/sorting.h ¶
r1 r12289 6 6 #define _SORTING_H_ 7 7 8 int binary_search(int* poffset,int target, int* sorted_integers,int num_integers); 9 8 int binary_search(int* poffset,int target,int* sorted_integers,int num_integers); 10 9 11 10 #endif //ifndef _SORTING_H_ 12
Note:
See TracChangeset
for help on using the changeset viewer.