aboutsummaryrefslogtreecommitdiff
path: root/src/statistics.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-05-24 11:40:06 +0200
committerThomas White <taw@physics.org>2012-02-22 15:27:27 +0100
commit192b3acc937155a1851c7c8547d912dcdf5ff759 (patch)
treea910c2cdb2f6cdcb6b426ce3aeaac823155eee72 /src/statistics.c
parent2470a37e0a96dcfc5aa840512a783188c41d3ddd (diff)
compare_hkl: Fix appalling scaling behaviour
Diffstat (limited to 'src/statistics.c')
-rw-r--r--src/statistics.c149
1 files changed, 57 insertions, 92 deletions
diff --git a/src/statistics.c b/src/statistics.c
index 77e7919f..da9a06c6 100644
--- a/src/statistics.c
+++ b/src/statistics.c
@@ -26,7 +26,7 @@
struct r_params {
RefList *list1;
- RefList *list2;
+ double *arr2;
int fom; /* Which FoM to use (see the enum just below) */
};
@@ -42,10 +42,10 @@ enum {
/* Return the least squares optimal scaling factor when comparing intensities.
- * list1,list2 are the two intensity lists to compare. "items" is a ReflItemList
+ * list1,arr2 are the two intensity lists to compare. "items" is a ReflItemList
* containing the reflections which should be taken into account.
*/
-double stat_scale_intensity(RefList *list1, RefList *list2)
+double stat_scale_intensity(RefList *list1, double *arr2)
{
double top = 0.0;
double bot = 0.0;
@@ -58,14 +58,11 @@ double stat_scale_intensity(RefList *list1, RefList *list2)
double i1, i2;
signed int h, k, l;
- Reflection *refl2;
get_indices(refl1, &h, &k, &l);
- refl2 = find_refl(list2, h, k, l);
- if ( refl2 == NULL ) continue; /* No common reflection */
+ i2 = lookup_intensity(arr2, h, k, l);
i1 = get_intensity(refl1);
- i2 = get_intensity(refl2);
top += i1 * i2;
bot += i2 * i2;
@@ -79,11 +76,11 @@ double stat_scale_intensity(RefList *list1, RefList *list2)
/* Return the least squares optimal scaling factor when comparing the square
* roots of the intensities (i.e. one approximation to the structure factor
* moduli).
- * list1,list2 are the two intensity lists to compare (they contain intensities,
+ * list1,arr2 are the two intensity lists to compare (they contain intensities,
* not square rooted intensities). "items" is a ReflItemList containing the
* reflections which should be taken into account.
*/
-static double stat_scale_sqrti(RefList *list1, RefList *list2)
+static double stat_scale_sqrti(RefList *list1, double *arr2)
{
double top = 0.0;
double bot = 0.0;
@@ -97,14 +94,11 @@ static double stat_scale_sqrti(RefList *list1, RefList *list2)
double i1, i2;
double f1, f2;
signed int h, k, l;
- Reflection *refl2;
get_indices(refl1, &h, &k, &l);
- refl2 = find_refl(list2, h, k, l);
- if ( refl2 == NULL ) continue; /* No common reflection */
+ i2 = lookup_intensity(arr2, h, k, l);
i1 = get_intensity(refl1);
- i2 = get_intensity(refl2);
if ( i1 < 0.0 ) continue;
f1 = sqrt(i1);
@@ -121,7 +115,7 @@ static double stat_scale_sqrti(RefList *list1, RefList *list2)
}
-static double internal_r1_ignorenegs(RefList *list1, RefList *list2,
+static double internal_r1_ignorenegs(RefList *list1, double *arr2,
double scale)
{
double top = 0.0;
@@ -136,14 +130,11 @@ static double internal_r1_ignorenegs(RefList *list1, RefList *list2,
double i1, i2;
double f1, f2;
signed int h, k, l;
- Reflection *refl2;
get_indices(refl1, &h, &k, &l);
- refl2 = find_refl(list2, h, k, l);
- if ( refl2 == NULL ) continue; /* No common reflection */
+ i2 = lookup_intensity(arr2, h, k, l);
i1 = get_intensity(refl1);
- i2 = get_intensity(refl2);
if ( i1 < 0.0 ) continue;
f1 = sqrt(i1);
@@ -161,7 +152,7 @@ static double internal_r1_ignorenegs(RefList *list1, RefList *list2,
}
-static double internal_r1_negstozero(RefList *list1, RefList *list2,
+static double internal_r1_negstozero(RefList *list1, double *arr2,
double scale)
{
double top = 0.0;
@@ -176,14 +167,11 @@ static double internal_r1_negstozero(RefList *list1, RefList *list2,
double i1, i2;
double f1, f2;
signed int h, k, l;
- Reflection *refl2;
get_indices(refl1, &h, &k, &l);
- refl2 = find_refl(list2, h, k, l);
- if ( refl2 == NULL ) continue; /* No common reflection */
+ i2 = lookup_intensity(arr2, h, k, l);
i1 = get_intensity(refl1);
- i2 = get_intensity(refl2);
f1 = i1 > 0.0 ? sqrt(i1) : 0.0;
@@ -199,7 +187,7 @@ static double internal_r1_negstozero(RefList *list1, RefList *list2,
}
-static double internal_r2(RefList *list1, RefList *list2, double scale)
+static double internal_r2(RefList *list1, double *arr2, double scale)
{
double top = 0.0;
double bot = 0.0;
@@ -212,14 +200,12 @@ static double internal_r2(RefList *list1, RefList *list2, double scale)
double i1, i2;
signed int h, k, l;
- Reflection *refl2;
get_indices(refl1, &h, &k, &l);
- refl2 = find_refl(list2, h, k, l);
- if ( refl2 == NULL ) continue; /* No common reflection */
+ i2 = lookup_intensity(arr2, h, k, l);
i1 = get_intensity(refl1);
- i2 = scale * get_intensity(refl2);
+ i2 *= scale;
top += pow(i1 - i2, 2.0);
bot += pow(i1, 2.0);
@@ -230,7 +216,7 @@ static double internal_r2(RefList *list1, RefList *list2, double scale)
}
-static double internal_r_i(RefList *list1, RefList *list2, double scale)
+static double internal_r_i(RefList *list1, double *arr2, double scale)
{
double top = 0.0;
double bot = 0.0;
@@ -243,14 +229,12 @@ static double internal_r_i(RefList *list1, RefList *list2, double scale)
double i1, i2;
signed int h, k, l;
- Reflection *refl2;
get_indices(refl1, &h, &k, &l);
- refl2 = find_refl(list2, h, k, l);
- if ( refl2 == NULL ) continue; /* No common reflection */
+ i2 = lookup_intensity(arr2, h, k, l);
i1 = get_intensity(refl1);
- i2 = scale * get_intensity(refl2);
+ i2 *= scale;
top += fabs(i1-i2);
bot += fabs(i1);
@@ -261,7 +245,7 @@ static double internal_r_i(RefList *list1, RefList *list2, double scale)
}
-static double internal_rdiff_intensity(RefList *list1, RefList *list2,
+static double internal_rdiff_intensity(RefList *list1, double *arr2,
double scale)
{
double top = 0.0;
@@ -275,14 +259,11 @@ static double internal_rdiff_intensity(RefList *list1, RefList *list2,
double i1, i2;
signed int h, k, l;
- Reflection *refl2;
get_indices(refl1, &h, &k, &l);
- refl2 = find_refl(list2, h, k, l);
- if ( refl2 == NULL ) continue; /* No common reflection */
+ i2 = lookup_intensity(arr2, h, k, l);
i1 = get_intensity(refl1);
- i2 = get_intensity(refl2);
i2 *= scale;
@@ -295,7 +276,7 @@ static double internal_rdiff_intensity(RefList *list1, RefList *list2,
}
-static double internal_rdiff_negstozero(RefList *list1, RefList *list2,
+static double internal_rdiff_negstozero(RefList *list1, double *arr2,
double scale)
{
double top = 0.0;
@@ -310,14 +291,11 @@ static double internal_rdiff_negstozero(RefList *list1, RefList *list2,
double i1, i2;
double f1, f2;
signed int h, k, l;
- Reflection *refl2;
get_indices(refl1, &h, &k, &l);
- refl2 = find_refl(list2, h, k, l);
- if ( refl2 == NULL ) continue; /* No common reflection */
+ i2 = lookup_intensity(arr2, h, k, l);
i1 = get_intensity(refl1);
- i2 = get_intensity(refl2);
f1 = i1 > 0.0 ? sqrt(i1) : 0.0;
@@ -333,7 +311,7 @@ static double internal_rdiff_negstozero(RefList *list1, RefList *list2,
}
-static double internal_rdiff_ignorenegs(RefList *list1, RefList *list2,
+static double internal_rdiff_ignorenegs(RefList *list1, double *arr2,
double scale)
{
double top = 0.0;
@@ -348,14 +326,11 @@ static double internal_rdiff_ignorenegs(RefList *list1, RefList *list2,
double i1, i2;
double f1, f2;
signed int h, k, l;
- Reflection *refl2;
get_indices(refl1, &h, &k, &l);
- refl2 = find_refl(list2, h, k, l);
- if ( refl2 == NULL ) continue; /* No common reflection */
+ i2 = lookup_intensity(arr2, h, k, l);
i1 = get_intensity(refl1);
- i2 = get_intensity(refl2);
if ( i1 < 0.0 ) continue;
f1 = sqrt(i1);
@@ -379,21 +354,21 @@ static double calc_r(double scale, void *params)
switch ( rp->fom) {
case R_1_ZERO :
- return internal_r1_negstozero(rp->list1, rp->list2, scale);
+ return internal_r1_negstozero(rp->list1, rp->arr2, scale);
case R_1_IGNORE :
- return internal_r1_ignorenegs(rp->list1, rp->list2, scale);
+ return internal_r1_ignorenegs(rp->list1, rp->arr2, scale);
case R_2 :
- return internal_r2(rp->list1, rp->list2, scale);
+ return internal_r2(rp->list1, rp->arr2, scale);
case R_1_I :
- return internal_r_i(rp->list1, rp->list2, scale);
+ return internal_r_i(rp->list1, rp->arr2, scale);
case R_DIFF_ZERO :
- return internal_rdiff_negstozero(rp->list1, rp->list2,scale);
+ return internal_rdiff_negstozero(rp->list1, rp->arr2,scale);
case R_DIFF_IGNORE :
- return internal_rdiff_ignorenegs(rp->list1, rp->list2, scale);
+ return internal_rdiff_ignorenegs(rp->list1, rp->arr2, scale);
case R_DIFF_INTENSITY :
- return internal_rdiff_intensity(rp->list1, rp->list2, scale);
+ return internal_rdiff_intensity(rp->list1, rp->arr2, scale);
}
ERROR("No such FoM!\n");
@@ -401,8 +376,7 @@ static double calc_r(double scale, void *params)
}
-static double r_minimised(RefList *list1, RefList *list2,
- double *scalep, int fom)
+static double r_minimised(RefList *list1, double *arr2, double *scalep, int fom)
{
gsl_function F;
gsl_min_fminimizer *s;
@@ -412,7 +386,7 @@ static double r_minimised(RefList *list1, RefList *list2,
int iter = 0;
rp.list1 = list1;
- rp.list2 = list2;
+ rp.arr2 = arr2;
rp.fom = fom;
F.function = &calc_r;
@@ -426,12 +400,12 @@ static double r_minimised(RefList *list1, RefList *list2,
case R_1_IGNORE :
case R_DIFF_ZERO :
case R_DIFF_IGNORE :
- scale = stat_scale_sqrti(list1, list2);
+ scale = stat_scale_sqrti(list1, arr2);
break;
case R_2 :
case R_1_I :
case R_DIFF_INTENSITY :
- scale = stat_scale_intensity(list1, list2);
+ scale = stat_scale_intensity(list1, arr2);
break;
}
//STATUS("Initial scale factor estimate: %5.2e\n", scale);
@@ -470,52 +444,52 @@ static double r_minimised(RefList *list1, RefList *list2,
}
-double stat_r1_ignore(RefList *list1, RefList *list2, double *scalep)
+double stat_r1_ignore(RefList *list1, double *arr2, double *scalep)
{
- return r_minimised(list1, list2, scalep, R_1_IGNORE);
+ return r_minimised(list1, arr2, scalep, R_1_IGNORE);
}
-double stat_r1_zero(RefList *list1, RefList *list2, double *scalep)
+double stat_r1_zero(RefList *list1, double *arr2, double *scalep)
{
- return r_minimised(list1, list2, scalep, R_1_ZERO);
+ return r_minimised(list1, arr2, scalep, R_1_ZERO);
}
-double stat_r2(RefList *list1, RefList *list2, double *scalep)
+double stat_r2(RefList *list1, double *arr2, double *scalep)
{
- return r_minimised(list1, list2, scalep, R_2);
+ return r_minimised(list1, arr2, scalep, R_2);
}
-double stat_r1_i(RefList *list1, RefList *list2, double *scalep)
+double stat_r1_i(RefList *list1, double *arr2, double *scalep)
{
- return r_minimised(list1, list2, scalep, R_1_I);
+ return r_minimised(list1, arr2, scalep, R_1_I);
}
-double stat_rdiff_zero(RefList *list1, RefList *list2, double *scalep)
+double stat_rdiff_zero(RefList *list1, double *arr2, double *scalep)
{
- return r_minimised(list1, list2, scalep, R_DIFF_ZERO);
+ return r_minimised(list1, arr2, scalep, R_DIFF_ZERO);
}
-double stat_rdiff_ignore(RefList *list1, RefList *list2, double *scalep)
+double stat_rdiff_ignore(RefList *list1, double *arr2, double *scalep)
{
- return r_minimised(list1, list2, scalep, R_DIFF_IGNORE);
+ return r_minimised(list1, arr2, scalep, R_DIFF_IGNORE);
}
-double stat_rdiff_intensity(RefList *list1, RefList *list2, double *scalep)
+double stat_rdiff_intensity(RefList *list1, double *arr2, double *scalep)
{
- return r_minimised(list1, list2, scalep, R_DIFF_INTENSITY);
+ return r_minimised(list1, arr2, scalep, R_DIFF_INTENSITY);
}
-double stat_pearson_i(RefList *list1, RefList *list2)
+double stat_pearson_i(RefList *list1, double *arr2)
{
double *vec1, *vec2;
- int ni = num_reflections(list1) + num_reflections(list2);
+ int ni = num_reflections(list1);
double val;
int nacc = 0;
Reflection *refl1;
@@ -530,14 +504,11 @@ double stat_pearson_i(RefList *list1, RefList *list2)
double i1, i2;
signed int h, k, l;
- Reflection *refl2;
get_indices(refl1, &h, &k, &l);
- refl2 = find_refl(list2, h, k, l);
- if ( refl2 == NULL ) continue; /* No common reflection */
+ i2 = lookup_intensity(arr2, h, k, l);
i1 = get_intensity(refl1);
- i2 = get_intensity(refl2);
vec1[nacc] = i1;
vec2[nacc] = i2;
@@ -552,10 +523,10 @@ double stat_pearson_i(RefList *list1, RefList *list2)
}
-double stat_pearson_f_ignore(RefList *list1, RefList *list2)
+double stat_pearson_f_ignore(RefList *list1, double *arr2)
{
double *vec1, *vec2;
- int ni = num_reflections(list1) + num_reflections(list2);
+ int ni = num_reflections(list1);
double val;
int nacc = 0;
Reflection *refl1;
@@ -571,15 +542,12 @@ double stat_pearson_f_ignore(RefList *list1, RefList *list2)
double i1, i2;
double f1, f2;
signed int h, k, l;
- Reflection *refl2;
int ig = 0;
get_indices(refl1, &h, &k, &l);
- refl2 = find_refl(list2, h, k, l);
- if ( refl2 == NULL ) continue; /* No common reflection */
+ i2 = lookup_intensity(arr2, h, k, l);
i1 = get_intensity(refl1);
- i2 = get_intensity(refl2);
if ( i1 < 0.0 ) ig = 1;
f1 = sqrt(i1);
@@ -603,10 +571,10 @@ double stat_pearson_f_ignore(RefList *list1, RefList *list2)
}
-double stat_pearson_f_zero(RefList *list1, RefList *list2)
+double stat_pearson_f_zero(RefList *list1, double *arr2)
{
double *vec1, *vec2;
- int ni = num_reflections(list1) + num_reflections(list2);
+ int ni = num_reflections(list1);
double val;
int nacc = 0;
Reflection *refl1;
@@ -622,14 +590,11 @@ double stat_pearson_f_zero(RefList *list1, RefList *list2)
double i1, i2;
double f1, f2;
signed int h, k, l;
- Reflection *refl2;
get_indices(refl1, &h, &k, &l);
- refl2 = find_refl(list2, h, k, l);
- if ( refl2 == NULL ) continue; /* No common reflection */
+ i2 = lookup_intensity(arr2, h, k, l);
i1 = get_intensity(refl1);
- i2 = get_intensity(refl2);
f1 = i1 > 0.0 ? sqrt(i1) : 0.0;
f2 = i2 > 0.0 ? sqrt(i2) : 0.0;