mailr23906 - /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 13, 2014 - 08:18:
Author: tlinnet
Date: Fri Jun 13 08:18:27 2014
New Revision: 23906

URL: http://svn.gna.org/viewcvs/relax?rev=23906&view=rev
Log:
Replaced target function for model TP02, to use higher dimensional numpy 
array structures.

That makes the model much faster.

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=23906&r1=23905&r2=23906&view=diff
==============================================================================
--- branches/disp_spin_speed/target_functions/relax_disp.py     (original)
+++ branches/disp_spin_speed/target_functions/relax_disp.py     Fri Jun 13 
08:18:27 2014
@@ -1952,62 +1952,14 @@
         # Once off parameter conversions.
         pB = 1.0 - pA
 
-        # Initialise.
-        chi2_sum = 0.0
-
-        # Loop over the spins.
-        for si in range(self.num_spins):
-            # Loop over the spectrometer frequencies.
-            for mi in range(self.num_frq):
-                # The R20 index.
-                r20_index = mi + si*self.num_frq
-
-                # Convert dw from ppm to rad/s.
-                dw_frq = dw[si] * self.frqs[0][si][mi]
-
-                # Loop over the offsets.
-                for oi in range(self.num_offsets[0][si][mi]):
-                    # Back calculate the R1rho values.
-                    r1rho_TP02(r1rho_prime=R20[r20_index], 
omega=self.chemical_shifts[0][si][mi], offset=self.offset[0][si][mi][oi], 
pA=pA, pB=pB, dw=dw_frq, kex=kex, R1=self.r1[si, mi], 
spin_lock_fields=self.spin_lock_omega1[0][mi][oi], 
spin_lock_fields2=self.spin_lock_omega1_squared[0][mi][oi], 
back_calc=self.back_calc[0][si][mi][oi], 
num_points=self.num_disp_points[0][si][mi][oi])
-
-                    # 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][oi]):
-                        if self.missing[0][si][mi][oi][di]:
-                            self.back_calc[0][si][mi][oi][di] = 
self.values[0][si][mi][oi][di]
-
-                    # Calculate and return the chi-squared value.
-                    chi2_sum += chi2(self.values[0][si][mi][oi], 
self.back_calc[0][si][mi][oi], self.errors[0][si][mi][oi])
-
-        # Return the total chi-squared value.
-        return chi2_sum
-
-
-    def func_TSMFK01(self, params):
-        """Target function for the the Tollinger et al. (2001) 2-site 
very-slow exchange model, range of microsecond to second time scale.
-
-        @param params:  The vector of parameter values.
-        @type params:   numpy rank-1 float array
-        @return:        The chi-squared value.
-        @rtype:         float
-        """
-
-        # Scaling.
-        if self.scaling_flag:
-            params = dot(params, self.scaling_matrix)
-
-        # Unpack the parameter values.
-        R20A = params[:self.end_index[0]]
-        dw = params[self.end_index[0]:self.end_index[1]]
-        k_AB = params[self.end_index[1]]
-
         # Convert dw from ppm to rad/s. Use the out argument, to pass 
directly to structure.
         multiply( multiply.outer( dw.reshape(self.NE, self.NS), 
self.nm_no_nd_struct ), self.frqs_struct, out=self.dw_struct )
 
-        # Reshape R20A and R20B to per experiment, spin and frequency.
-        self.r20a_struct[:] = multiply.outer( R20A.reshape(self.NE, self.NS, 
self.NM), self.no_nd_struct )
-
-        # Back calculate the R2eff values.
-        r2eff_TSMFK01(r20a=self.r20a_struct, dw=self.dw_struct, dw_orig=dw, 
k_AB=k_AB, tcp=self.tau_cpmg_a, back_calc=self.back_calc_a, 
num_points=self.num_disp_points_a)
+        # Reshape R20 to per experiment, spin and frequency.
+        self.r20_struct[:] = multiply.outer( R20.reshape(self.NE, self.NS, 
self.NM), self.no_nd_struct )
+
+        # Back calculate the R1rho values.
+        r1rho_TP02(r1rho_prime=self.r20_struct, 
omega=self.chemical_shifts_a, offset=self.offset_a, pA=pA, pB=pB, 
dw=self.dw_struct, kex=kex, R1=self.r1_a, 
spin_lock_fields=self.spin_lock_omega1_a, 
spin_lock_fields2=self.spin_lock_omega1_squared_a, 
back_calc=self.back_calc_a, num_points=self.num_disp_points_a)
 
         # Clean the data for all values, which is left over at the end of 
arrays.
         self.back_calc_a = self.back_calc_a*self.disp_struct
@@ -2019,3 +1971,43 @@
 
         # Return the total chi-squared value.
         return chi2_rankN(self.values_a, self.back_calc_a, self.errors_a)
+
+
+
+    def func_TSMFK01(self, params):
+        """Target function for the the Tollinger et al. (2001) 2-site 
very-slow exchange model, range of microsecond to second time scale.
+
+        @param params:  The vector of parameter values.
+        @type params:   numpy rank-1 float array
+        @return:        The chi-squared value.
+        @rtype:         float
+        """
+
+        # Scaling.
+        if self.scaling_flag:
+            params = dot(params, self.scaling_matrix)
+
+        # Unpack the parameter values.
+        R20A = params[:self.end_index[0]]
+        dw = params[self.end_index[0]:self.end_index[1]]
+        k_AB = params[self.end_index[1]]
+
+        # Convert dw from ppm to rad/s. Use the out argument, to pass 
directly to structure.
+        multiply( multiply.outer( dw.reshape(self.NE, self.NS), 
self.nm_no_nd_struct ), self.frqs_struct, out=self.dw_struct )
+
+        # Reshape R20A and R20B to per experiment, spin and frequency.
+        self.r20a_struct[:] = multiply.outer( R20A.reshape(self.NE, self.NS, 
self.NM), self.no_nd_struct )
+
+        # Back calculate the R2eff values.
+        r2eff_TSMFK01(r20a=self.r20a_struct, dw=self.dw_struct, dw_orig=dw, 
k_AB=k_AB, tcp=self.tau_cpmg_a, back_calc=self.back_calc_a, 
num_points=self.num_disp_points_a)
+
+        # Clean the data for all values, which is left over at the end of 
arrays.
+        self.back_calc_a = self.back_calc_a*self.disp_struct
+
+        ## 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:
+            # Replace with values.
+            self.back_calc_a[self.mask_replace_blank.mask] = 
self.values_a[self.mask_replace_blank.mask]
+
+        # Return the total chi-squared value.
+        return chi2_rankN(self.values_a, self.back_calc_a, self.errors_a)




Related Messages


Powered by MHonArc, Updated Fri Jun 13 08:40:02 2014