mailr23742 - /branches/disp_spin_speed/target_functions/relax_disp.py


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

Header


Content

Posted by tlinnet on June 08, 2014 - 22:22:
Author: tlinnet
Date: Sun Jun  8 22:22:26 2014
New Revision: 23742

URL: http://svn.gna.org/viewcvs/relax?rev=23742&view=rev
Log:
Created multi dimensional error and value numpy arrays.

This is to calculate the chi2 sum much faster.
Reordered the loop over missing data points, so it is only iniatiated if 
missing points is detected.

Task #7807 (https://gna.org/task/index.php?7807): Speed-up of dispersion 
models for Clustered analysis.

Modified:
    branches/disp_spin_speed/target_functions/relax_disp.py

Modified: branches/disp_spin_speed/target_functions/relax_disp.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/target_functions/relax_disp.py?rev=23742&r1=23741&r2=23742&view=diff
==============================================================================
--- branches/disp_spin_speed/target_functions/relax_disp.py     (original)
+++ branches/disp_spin_speed/target_functions/relax_disp.py     Sun Jun  8 
22:22:26 2014
@@ -417,6 +417,8 @@
             self.cpmg_frqs_a = np.ones(back_calc_shape + 
[self.max_num_disp_points])
             self.num_disp_points_a = np.ones(back_calc_shape + 
[self.max_num_disp_points])
             self.back_calc_a = np.ones(back_calc_shape + 
[self.max_num_disp_points])
+            self.errors_a = np.ones(back_calc_shape + 
[self.max_num_disp_points])
+            self.values_a = np.ones(back_calc_shape + 
[self.max_num_disp_points])
             self.has_missing = False
 
             # Loop over the experiment types.
@@ -539,30 +541,31 @@
                 self.pA_a[0][si][mi][0][:num_disp_points] = np.array( [pA] * 
num_disp_points, float64)
                 self.kex_a[0][si][mi][0][:num_disp_points] = np.array( [kex] 
* num_disp_points, float64)
 
+                # Extract the errors and values to numpy array.
+                self.errors_a[0][si][mi][0][:num_disp_points] = 
self.errors[0][si][mi][0]
+                self.values_a[0][si][mi][0][:num_disp_points] = 
self.values[0][si][mi][0]
+
         ## Back calculate the R2eff values.
         r2eff_CR72(r20a=self.R20A_a, r20b=self.R20B_a, pA=self.pA_a, 
dw=self.dw_frq_a, kex=self.kex_a, cpmg_frqs=self.cpmg_frqs_a, 
back_calc=self.back_calc_a, num_points=self.num_disp_points_a)
 
-        # Initialise.
-        chi2_sum = 0.0
-
-        # Now return the values back to the structure of self.back_calc 
object.
-        # Loop over the spins.
-        for si in range(self.num_spins):
-            # Loop over the spectrometer frequencies.
-            for mi in range(self.num_frq):
-                # Extract number of dispersion points.
-                num_disp_points = self.num_disp_points[0][si][mi][0]
-
-                self.back_calc[0][si][mi][0] = 
self.back_calc_a[0][si][mi][0][:num_disp_points]
-
-                ## 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.
-                if self.has_missing:
+
+        ## 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.
+        if self.has_missing:
+            # Loop over the spins.
+            for si in range(self.num_spins):
+                # Loop over the spectrometer frequencies.
+                for mi in range(self.num_frq):
+                    # Loop over the dispersion points.
                     for di in range(self.num_disp_points[0][si][mi][0]):
                         if self.missing[0][si][mi][0][di]:
-                            self.back_calc[0][si][mi][0][di] = 
self.values[0][si][mi][0][di]
-
-                ## Calculate and return the chi-squared value.
-                chi2_sum += chi2(self.values[0][si][mi][0], 
self.back_calc[0][si][mi][0], self.errors[0][si][mi][0])
+                            #self.back_calc[0][si][mi][0][di] = 
self.values[0][si][mi][0][di]
+                            self.back_calc_a[0][si][mi][0][di] = 
self.values[0][si][mi][0][di]
+
+                    ## Calculate and return the chi-squared value.
+                    #chi2_sum += chi2(self.values[0][si][mi][0], 
self.back_calc[0][si][mi][0], self.errors[0][si][mi][0])
+
+        ## Calculate the chi-squared statistic.
+        chi2_sum = np.sum((1.0 / self.errors_a * (self.values_a - 
self.back_calc_a))**2)
 
         # Return the total chi-squared value.
         return chi2_sum




Related Messages


Powered by MHonArc, Updated Sun Jun 08 23:00:03 2014