From f8de3ad3f3410b95180f569d99b9b1f9bd9523ab Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 8 Mar 2013 10:31:29 +0100 Subject: pr_gradient_check: Look for correlations, not individual values --- tests/pr_gradient_check.c | 103 ++++++++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 39 deletions(-) diff --git a/tests/pr_gradient_check.c b/tests/pr_gradient_check.c index 2631b1bb..cf11d18c 100644 --- a/tests/pr_gradient_check.c +++ b/tests/pr_gradient_check.c @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -230,9 +231,14 @@ static double test_gradients(Crystal *cr, double incr_val, int refine, int nref; int n_good, n_invalid, n_small, n_nan, n_bad; RefList *reflections; - //FILE *fh; + FILE *fh; int ntot = 0; double total = 0.0; + char tmp[32]; + double *vec1; + double *vec2; + int n_line; + double cc; reflections = find_intersections(crystal_get_image(cr), cr); crystal_set_reflections(cr, reflections); @@ -240,7 +246,7 @@ static double test_gradients(Crystal *cr, double incr_val, int refine, nref = num_reflections(reflections); if ( nref < 10 ) { ERROR("Too few reflections found. Failing test by default.\n"); - return -1; + return 0.0; } vals[0] = malloc(nref*sizeof(long double)); @@ -248,13 +254,13 @@ static double test_gradients(Crystal *cr, double incr_val, int refine, vals[2] = malloc(nref*sizeof(long double)); if ( (vals[0] == NULL) || (vals[1] == NULL) || (vals[2] == NULL) ) { ERROR("Couldn't allocate memory.\n"); - return -1; + return 0.0; } valid = malloc(nref*sizeof(int)); if ( valid == NULL ) { ERROR("Couldn't allocate memory.\n"); - return -1; + return 0.0; } for ( i=0; iindexed_cell, h, k, l), - //rad2deg(tt), - // cgrad, - // fabs((grad-cgrad)/grad)); - } i++; @@ -342,10 +355,11 @@ static double test_gradients(Crystal *cr, double incr_val, int refine, STATUS("%3s: %3i within 5%%, %3i outside, %3i nan, %3i invalid, " "%3i small. ", str, n_good, n_bad, n_nan, n_invalid, n_small); - //fclose(fh); + fclose(fh); - STATUS("Fractional error = %f %%\n", 100.0*total/ntot); - return total / ntot; + cc = gsl_stats_correlation(vec1, 1, vec2, 1, n_line); + STATUS("CC = %+f\n", cc); + return cc; } @@ -362,7 +376,7 @@ int main(int argc, char *argv[]) struct quaternion orientation; int i; const PartialityModel pmodel = PMODEL_SPHERE; - double tot = 0.0; + int fail = 0; image.width = 1024; image.height = 1024; @@ -393,6 +407,7 @@ int main(int argc, char *argv[]) for ( i=0; i<1; i++ ) { UnitCell *rot; + double val; orientation = random_quaternion(); rot = cell_rotate(cell, orientation); @@ -403,34 +418,44 @@ int main(int argc, char *argv[]) &bz, &cx, &cy, &cz); incr_val = incr_frac * image.div; - tot += test_gradients(cr, incr_val, REF_DIV, "div", pmodel); + val = test_gradients(cr, incr_val, REF_DIV, "div", pmodel); + if ( val > 0.1 ) fail = 1; incr_val = incr_frac * crystal_get_profile_radius(cr); - tot += test_gradients(cr, incr_val, REF_R, "R", pmodel); + val = test_gradients(cr, incr_val, REF_R, "R", pmodel); + if ( val > 0.1 ) fail = 1; incr_val = incr_frac * ax; - tot += test_gradients(cr, incr_val, REF_ASX, "ax*", pmodel); + val = test_gradients(cr, incr_val, REF_ASX, "ax*", pmodel); + if ( val > 0.1 ) fail = 1; incr_val = incr_frac * ay; - tot += test_gradients(cr, incr_val, REF_ASY, "ay*", pmodel); + val = test_gradients(cr, incr_val, REF_ASY, "ay*", pmodel); + if ( val > 0.1 ) fail = 1; incr_val = incr_frac * az; - tot += test_gradients(cr, incr_val, REF_ASZ, "az*", pmodel); + val = test_gradients(cr, incr_val, REF_ASZ, "az*", pmodel); + if ( val > 0.1 ) fail = 1; incr_val = incr_frac * bx; - tot += test_gradients(cr, incr_val, REF_BSX, "bx*", pmodel); + val = test_gradients(cr, incr_val, REF_BSX, "bx*", pmodel); + if ( val > 0.1 ) fail = 1; incr_val = incr_frac * by; - tot += test_gradients(cr, incr_val, REF_BSY, "by*", pmodel); + val = test_gradients(cr, incr_val, REF_BSY, "by*", pmodel); + if ( val > 0.1 ) fail = 1; incr_val = incr_frac * bz; - tot += test_gradients(cr, incr_val, REF_BSZ, "bz*", pmodel); + val = test_gradients(cr, incr_val, REF_BSZ, "bz*", pmodel); + if ( val > 0.1 ) fail = 1; incr_val = incr_frac * cx; - tot += test_gradients(cr, incr_val, REF_CSX, "cx*", pmodel); + val = test_gradients(cr, incr_val, REF_CSX, "cx*", pmodel); + if ( val > 0.1 ) fail = 1; incr_val = incr_frac * cy; - tot += test_gradients(cr, incr_val, REF_CSY, "cy*", pmodel); + val = test_gradients(cr, incr_val, REF_CSY, "cy*", pmodel); + if ( val > 0.1 ) fail = 1; incr_val = incr_frac * cz; - tot += test_gradients(cr, incr_val, REF_CSZ, "cz*", pmodel); + val = test_gradients(cr, incr_val, REF_CSZ, "cz*", pmodel); + if ( val > 0.1 ) fail = 1; } - STATUS("Mean fractional error = %f %%\n", 100.0*tot/10.0); - return 0; + return fail; } -- cgit v1.2.3