diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compare_hkl.c | 10 | ||||
-rw-r--r-- | src/statistics.c | 105 | ||||
-rw-r--r-- | src/statistics.h | 10 |
3 files changed, 110 insertions, 15 deletions
diff --git a/src/compare_hkl.c b/src/compare_hkl.c index a332220b..5f8b79ce 100644 --- a/src/compare_hkl.c +++ b/src/compare_hkl.c @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) char *afile = NULL; char *bfile = NULL; char *sym = NULL; - double scale, R2, Rmerge, pearson; + double scale, R1, R2, Rdiff, Riso, pearson; int i, ncom; ReflItemList *i1, *i2, *icommon; @@ -143,10 +143,14 @@ int main(int argc, char *argv[]) STATUS("%i,%i reflections: %i in common\n", num_items(i1), num_items(i2), ncom); + R1 = stat_r1(ref1, ref2_transformed, icommon, &scale); + STATUS("R1 = %5.4f %% (scale=%5.2e)\n", R1*100.0, scale); R2 = stat_r2(ref1, ref2_transformed, icommon, &scale); STATUS("R2 = %5.4f %% (scale=%5.2e)\n", R2*100.0, scale); - Rmerge = stat_rmerge(ref1, ref2_transformed, icommon, &scale); - STATUS("Rmerge = %5.4f %% (scale=%5.2e)\n", Rmerge*100.0, scale); + Rdiff = stat_rdiff(ref1, ref2_transformed, icommon, &scale); + STATUS("Rdiff = %5.4f %% (scale=%5.2e)\n", Rdiff*100.0, scale); + Riso = stat_riso(ref1, ref2_transformed, icommon, &scale); + STATUS("Riso = %5.4f %% (scale=%5.2e)\n", Riso*100.0, scale); pearson = stat_pearson(ref1, ref2_transformed, icommon); STATUS("Pearson r = %5.4f\n", pearson); diff --git a/src/statistics.c b/src/statistics.c index e0a2e71a..27b5b8c5 100644 --- a/src/statistics.c +++ b/src/statistics.c @@ -32,8 +32,10 @@ struct r_params { }; enum { + R_1, R_2, - R_MERGE, + R_DIFF, + R_ISO }; @@ -106,6 +108,37 @@ static double stat_scale_sqrti(const double *ref1, const double *ref2, } +static double internal_r1(const double *ref1, const double *ref2, + ReflItemList *items, double scale) +{ + double top = 0.0; + double bot = 0.0; + int i; + + for ( i=0; i<num_items(items); i++ ) { + + double i1, f1, i2, f2; + struct refl_item *it; + signed int h, k, l; + + it = get_item(items, i); + h = it->h; k = it->k; l = it->l; + + i1 = lookup_intensity(ref1, h, k, l); + f1 = i1 > 0.0 ? sqrt(i1) : 0.0; + i2 = lookup_intensity(ref2, h, k, l); + f2 = i2 > 0.0 ? sqrt(i2) : 0.0; + f2 *= scale; + + top += fabs(f1 - f2); + bot += f1; + + } + + return top/bot; +} + + static double internal_r2(const double *ref1, const double *ref2, ReflItemList *items, double scale) { @@ -134,8 +167,8 @@ static double internal_r2(const double *ref1, const double *ref2, } -static double internal_rmerge(const double *ref1, const double *ref2, - ReflItemList *items, double scale) +static double internal_rdiff(const double *ref1, const double *ref2, + ReflItemList *items, double scale) { double top = 0.0; double bot = 0.0; @@ -165,15 +198,47 @@ static double internal_rmerge(const double *ref1, const double *ref2, } +static double internal_riso(const double *ref1, const double *ref2, + ReflItemList *items, double scale) +{ + double top = 0.0; + double bot = 0.0; + int i; + + for ( i=0; i<num_items(items); i++ ) { + + double i1, i2; + struct refl_item *it; + signed int h, k, l; + + it = get_item(items, i); + h = it->h; k = it->k; l = it->l; + + i1 = lookup_intensity(ref1, h, k, l); + i2 = lookup_intensity(ref2, h, k, l); + + top += fabs(i1 - i2); + bot += fabs(i1 + i2); + + } + + return 2.0*top/bot; +} + + static double calc_r(double scale, void *params) { struct r_params *rp = params; switch ( rp->fom) { - case R_MERGE : - return internal_rmerge(rp->ref1, rp->ref2, rp->items, scale); + case R_1 : + return internal_r1(rp->ref1, rp->ref2, rp->items, scale); case R_2 : return internal_r2(rp->ref1, rp->ref2, rp->items, scale); + case R_DIFF : + return internal_rdiff(rp->ref1, rp->ref2, rp->items, scale); + case R_ISO : + return internal_riso(rp->ref1, rp->ref2, rp->items, scale); } ERROR("No such FoM!\n"); @@ -203,14 +268,20 @@ static double r_minimised(const double *ref1, const double *ref2, /* Initial guess */ switch ( fom ) { - case R_MERGE : + case R_1 : scale = stat_scale_sqrti(ref1, ref2, items); break; case R_2 : scale = stat_scale_intensity(ref1, ref2, items); break; + case R_DIFF : + scale = stat_scale_sqrti(ref1, ref2, items); + break; + case R_ISO : + scale = stat_scale_intensity(ref1, ref2, items); + break; } - //STATUS("Initial scale factor estimate: %5.2e\n", scale); + STATUS("Initial scale factor estimate: %5.2e\n", scale); /* Probably within an order of magnitude either side */ gsl_min_fminimizer_set(s, &F, scale, scale/10.0, scale*10.0); @@ -246,10 +317,10 @@ static double r_minimised(const double *ref1, const double *ref2, } -double stat_rmerge(const double *ref1, const double *ref2, - ReflItemList *items, double *scalep) +double stat_r1(const double *ref1, const double *ref2, + ReflItemList *items, double *scalep) { - return r_minimised(ref1, ref2, items, scalep, R_MERGE); + return r_minimised(ref1, ref2, items, scalep, R_1); } @@ -260,6 +331,20 @@ double stat_r2(const double *ref1, const double *ref2, } +double stat_rdiff(const double *ref1, const double *ref2, + ReflItemList *items, double *scalep) +{ + return r_minimised(ref1, ref2, items, scalep, R_DIFF); +} + + +double stat_riso(const double *ref1, const double *ref2, + ReflItemList *items, double *scalep) +{ + return r_minimised(ref1, ref2, items, scalep, R_ISO); +} + + double stat_pearson(const double *ref1, const double *ref2, ReflItemList *items) { double *vec1, *vec2; diff --git a/src/statistics.h b/src/statistics.h index c6c2f09c..4a795090 100644 --- a/src/statistics.h +++ b/src/statistics.h @@ -22,12 +22,18 @@ extern double stat_scale_intensity(const double *ref1, const double *ref2, ReflItemList *items); -extern double stat_rmerge(const double *ref1, const double *ref2, - ReflItemList *items, double *scalep); +extern double stat_r1(const double *ref1, const double *ref2, + ReflItemList *items, double *scalep); extern double stat_r2(const double *ref1, const double *ref2, ReflItemList *items, double *scalep); +extern double stat_rdiff(const double *ref1, const double *ref2, + ReflItemList *items, double *scalep); + +extern double stat_riso(const double *ref1, const double *ref2, + ReflItemList *items, double *scalep); + extern double stat_pearson(const double *ref1, const double *ref2, ReflItemList *items); |