mailRe: r23275 - in /branches/disp_speed: lib/dispersion/it99.py target_functions/relax_disp.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by Edward d'Auvergne on May 21, 2014 - 09:00:
Hi Troels,

Again the mixed API and math domain error checking commit is a problem
here.  The reason is because you do not need to always check that the
denominator is zero.  In many cases, it is impossible!  The
denominator here is:

1.0 + omega_a^2 * tex^2

There is no way that adding a positive number to 1.0 can ever be zero,
so the test here is not needed and only slows the code down.
Unfortunately reverting the commit will also discard the API change of
returning R2eff :S

Regards,

Edward



On 20 May 2014 22:29,  <tlinnet@xxxxxxxxxxxxx> wrote:
Author: tlinnet
Date: Tue May 20 22:29:49 2014
New Revision: 23275

URL: http://svn.gna.org/viewcvs/relax?rev=23275&view=rev
Log:
Math-domain catching for model IT99.

task #7793: (https://gna.org/task/?7793) Speed-up of dispersion models.

This is to implement catching of math domain errors, before they occur.
These can be found via the --numpy-raise function to the systemtests.

To make the code look clean, the class object "back_calc" is no longer
being updated per time point, but is updated in the relax_disp target 
function in
one go.

Modified:
    branches/disp_speed/lib/dispersion/it99.py
    branches/disp_speed/target_functions/relax_disp.py

Modified: branches/disp_speed/lib/dispersion/it99.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_speed/lib/dispersion/it99.py?rev=23275&r1=23274&r2=23275&view=diff
==============================================================================
--- branches/disp_speed/lib/dispersion/it99.py  (original)
+++ branches/disp_speed/lib/dispersion/it99.py  Tue May 20 22:29:49 2014
@@ -73,10 +73,10 @@
 """

 # Python module imports.
-from numpy import array, isfinite, sqrt, sum
+from numpy import abs, array, isfinite, min, sqrt, sum


-def r2eff_IT99(r20=None, pA=None, pB=None, dw=None, tex=None, 
cpmg_frqs=None, back_calc=None, num_points=None):
+def r2eff_IT99(r20=None, pA=None, pB=None, dw=None, tex=None, 
cpmg_frqs=None, num_points=None):
     """Calculate the R2eff values for the IT99 model.

     See the module docstring for details.
@@ -94,9 +94,7 @@
     @type tex:              float
     @keyword cpmg_frqs:     The CPMG nu1 frequencies.
     @type cpmg_frqs:        numpy rank-1 float array
-    @keyword back_calc:     The array for holding the back calculated 
R2eff values.  Each element corresponds to one of the CPMG nu1 frequencies.
-    @type back_calc:        numpy rank-1 float array
-    @keyword num_points:    The number of points on the dispersion curve, 
equal to the length of the cpmg_frqs and back_calc arguments.
+    @keyword num_points:    The number of points on the dispersion curve, 
equal to the length of the cpmg_frqs.
     @type num_points:       int
     """

@@ -116,6 +114,13 @@
     omega_a2 = sqrt(omega_1eff4 + pa2dw4)
     denom = 1.0 + omega_a2 * tex2

+    # Catch math domain error of dividing with 0.
+    # This is when denom=0.
+    if min(abs(denom)) == 0:
+        R2eff = array([1e100]*num_points)
+
+        return R2eff
+
     # R2eff calculation.
     R2eff = r20 + numer / denom

@@ -124,6 +129,4 @@
     if not isfinite(sum(R2eff)):
         R2eff = array([1e100]*num_points)

-    # Parse back the value to update the back_calc class object.
-    for i in range(num_points):
-        back_calc[i] = R2eff[i]
+    return R2eff

Modified: branches/disp_speed/target_functions/relax_disp.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_speed/target_functions/relax_disp.py?rev=23275&r1=23274&r2=23275&view=diff
==============================================================================
--- branches/disp_speed/target_functions/relax_disp.py  (original)
+++ branches/disp_speed/target_functions/relax_disp.py  Tue May 20 22:29:49 
2014
@@ -1015,7 +1015,7 @@
                 dw_frq = dw[si] * self.frqs[0][si][mi]

                 # Back calculate the R2eff values.
-                r2eff_IT99(r20=R20[r20_index], pA=pA, pB=pB, dw=dw_frq, 
tex=tex, cpmg_frqs=self.cpmg_frqs[0][mi][0], 
back_calc=self.back_calc[0][si][mi][0], 
num_points=self.num_disp_points[0][si][mi][0])
+                self.back_calc[0][si][mi][0] = 
r2eff_IT99(r20=R20[r20_index], pA=pA, pB=pB, dw=dw_frq, tex=tex, 
cpmg_frqs=self.cpmg_frqs[0][mi][0], 
num_points=self.num_disp_points[0][si][mi][0])

                 # For all missing data points, set the back-calculated 
value to the measured values so that it has no effect on the chi-squared 
value.
                 for di in range(self.num_disp_points[0][si][mi][0]):


_______________________________________________
relax (http://www.nmr-relax.com)

This is the relax-commits mailing list
relax-commits@xxxxxxx

To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-commits



Related Messages


Powered by MHonArc, Updated Wed May 21 10:00:15 2014