mailr19398 - in /branches/relax_disp: ./ specific_analyses/relax_fit.py target_functions/relax_fit.c


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

Header


Content

Posted by edward on April 05, 2013 - 19:29:
Author: bugman
Date: Fri Apr  5 19:29:31 2013
New Revision: 19398

URL: http://svn.gna.org/viewcvs/relax?rev=19398&view=rev
Log:
Merged revisions 19389-19397 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk

........
  r19389 | bugman | 2013-04-05 18:04:35 +0200 (Fri, 05 Apr 2013) | 6 lines
  
  The relaxation curve-fitting analysis parameters are now all lowercase.
  
  This is to match the other analysis types so that the parameter names are 
identical to the
  corresponding variable name.  This is assumed by some of the specific 
analysis API methods.
........
  r19390 | bugman | 2013-04-05 18:08:42 +0200 (Fri, 05 Apr 2013) | 7 lines
  
  Fix for the relaxation curve-fitting _assemble_scaling_matrix() method.
  
  The intensity scaling was never activated before due to a lower vs. 
uppercase parameter name
  mismatch.  This scaling is now correctly set up as the previous code 
assumed cdp.relax_times was a
  list whereas it has been a dictionary since the early 1.3 releases.
........
  r19391 | bugman | 2013-04-05 18:17:00 +0200 (Fri, 05 Apr 2013) | 6 lines
  
  The grid search bounds for the relaxation curve-fitting are no longer 
affected by scaling.
  
  The parameter scaling activated a few commits ago revealed a bug in the 
lower and upper data
  structures for the grid search in that these were continuously scaled down.
........
  r19392 | bugman | 2013-04-05 18:23:30 +0200 (Fri, 05 Apr 2013) | 3 lines
  
  Removal of junk code in the _assemble_scaling_matrix() relaxation 
curve-fitting method.
........
  r19393 | bugman | 2013-04-05 18:44:48 +0200 (Fri, 05 Apr 2013) | 5 lines
  
  Parameter scaling is now functional in the target_function.relax_fit.c code.
  
  Previously the scaling was not being used and the Python to C conversion 
was broken. 
........
  r19394 | bugman | 2013-04-05 18:45:34 +0200 (Fri, 05 Apr 2013) | 3 lines
  
  The scaling matrix is now converted into a usable list of diagonal elements 
for the relax_fit C module.
........
  r19395 | bugman | 2013-04-05 18:50:46 +0200 (Fri, 05 Apr 2013) | 3 lines
  
  Fix for the target_functions.relax_fit C module - the scaling was 
incorrectly performed.
........
  r19396 | bugman | 2013-04-05 19:13:55 +0200 (Fri, 05 Apr 2013) | 3 lines
  
  Simplified the code of the relax_fit C module.
........
  r19397 | bugman | 2013-04-05 19:28:34 +0200 (Fri, 05 Apr 2013) | 5 lines
  
  Fix for the relaxation curve-fitting _back_calc() method for the changes to 
the C module.
  
  The setup() method requires that the scaling matrix is converted to a list 
of the diagonal elements.
........

Modified:
    branches/relax_disp/   (props changed)
    branches/relax_disp/specific_analyses/relax_fit.py
    branches/relax_disp/target_functions/relax_fit.c

Propchange: branches/relax_disp/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Apr  5 19:29:31 2013
@@ -1,1 +1,1 @@
-/trunk:1-19374
+/trunk:1-19397

Modified: branches/relax_disp/specific_analyses/relax_fit.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/specific_analyses/relax_fit.py?rev=19398&r1=19397&r2=19398&view=diff
==============================================================================
--- branches/relax_disp/specific_analyses/relax_fit.py (original)
+++ branches/relax_disp/specific_analyses/relax_fit.py Fri Apr  5 19:29:31 
2013
@@ -96,7 +96,7 @@
         # Loop over the model parameters.
         for i in range(len(spin.params)):
             # Relaxation rate.
-            if spin.params[i] == 'Rx':
+            if spin.params[i] == 'rx':
                 if sim_index != None:
                     param_vector.append(spin.rx_sim[sim_index])
                 elif spin.rx == None:
@@ -105,7 +105,7 @@
                     param_vector.append(spin.rx)
 
             # Initial intensity.
-            elif spin.params[i] == 'I0':
+            elif spin.params[i] == 'i0':
                 if sim_index != None:
                     param_vector.append(spin.i0_sim[sim_index])
                 elif spin.i0 == None:
@@ -114,7 +114,7 @@
                     param_vector.append(spin.i0)
 
             # Intensity at infinity.
-            elif spin.params[i] == 'Iinf':
+            elif spin.params[i] == 'iinf':
                 if sim_index != None:
                     param_vector.append(spin.iinf_sim[sim_index])
                 elif spin.iinf == None:
@@ -148,19 +148,12 @@
         # Loop over the parameters.
         for i in range(len(spin.params)):
             # Relaxation rate.
-            if spin.params[i] == 'Rx':
+            if spin.params[i] == 'rx':
                 pass
 
             # Intensity scaling.
             elif search('^i', spin.params[i]):
-                # Find the position of the first time point.
-                pos = cdp.relax_times.index(min(cdp.relax_times))
-
-                # Scaling.
-                scaling_matrix[i, i] = 1.0 / average(spin.intensities[pos])
-
-            # Increment i.
-            i = i + 1
+                scaling_matrix[i, i] = max(spin.intensities.values())
 
         # Return the scaling matrix.
         return scaling_matrix
@@ -195,8 +188,13 @@
             errors.append(spin.intensity_err[key])
             times.append(cdp.relax_times[key])
 
+        # The scaling matrix in a diagonalised list form.
+        scaling_list = []
+        for i in range(len(scaling_matrix)):
+            scaling_list.append(scaling_matrix[i, i])
+
         # Initialise the relaxation fit functions.
-        setup(num_params=len(spin.params), num_times=len(cdp.relax_times), 
values=values, sd=errors, relax_times=times, scaling_matrix=scaling_matrix)
+        setup(num_params=len(spin.params), num_times=len(cdp.relax_times), 
values=values, sd=errors, relax_times=times, scaling_matrix=scaling_list)
 
         # Make a single function call.  This will cause back calculation and 
the data will be stored in the C module.
         self._func(param_vector)
@@ -333,12 +331,12 @@
             # Loop over the parameters.
             for i in range(n):
                 # Relaxation rate (from 0 to 20 s^-1).
-                if spin.params[i] == 'Rx':
+                if spin.params[i] == 'rx':
                     lower.append(0.0)
                     upper.append(20.0)
 
                 # Intensity
-                elif search('^I', spin.params[i]):
+                elif search('^i', spin.params[i]):
                     # Find the ID of the first time point.
                     min_time = min(cdp.relax_times.values())
                     for key in list(cdp.relax_times.keys()):
@@ -350,12 +348,15 @@
                     lower.append(0.0)
                     upper.append(average(spin.intensities[id]))
 
-        # Parameter scaling.
+        # Diagonal scaling of minimisation options.
+        lower_new = []
+        upper_new = []
         for i in range(n):
-            lower[i] = lower[i] / scaling_matrix[i, i]
-            upper[i] = upper[i] / scaling_matrix[i, i]
-
-        return inc, lower, upper
+            lower_new.append(lower[i] / scaling_matrix[i, i])
+            upper_new.append(upper[i] / scaling_matrix[i, i])
+
+        # Return the minimisation options.
+        return inc, lower_new, upper_new
 
 
     def _linear_constraints(self, spin=None, scaling_matrix=None):
@@ -404,7 +405,7 @@
         # Loop over the parameters.
         for k in range(len(spin.params)):
             # Relaxation rate.
-            if spin.params[k] == 'Rx':
+            if spin.params[k] == 'rx':
                 # Rx >= 0.
                 A.append(zero_array * 0.0)
                 A[j][i] = 1.0
@@ -412,7 +413,7 @@
                 j = j + 1
 
             # Intensity parameter.
-            elif search('^I', spin.params[k]):
+            elif search('^i', spin.params[k]):
                 # I0, Iinf >= 0.
                 A.append(zero_array * 0.0)
                 A[j][i] = 1.0
@@ -498,12 +499,12 @@
         # Two parameter exponential fit.
         if model == 'exp':
             print("Two parameter exponential fit.")
-            params = ['Rx', 'I0']
+            params = ['rx', 'i0']
 
         # Three parameter inversion recovery fit.
         elif model == 'inv':
             print("Three parameter inversion recovery fit.")
-            params = ['Rx', 'I0', 'Iinf']
+            params = ['rx', 'i0', 'iinf']
 
         # Invalid model.
         else:
@@ -661,7 +662,7 @@
 
             # Get the grid search minimisation options.
             if match('^[Gg]rid', min_algor):
-                inc, lower, upper = self._grid_search_setup(spin=spin, 
param_vector=param_vector, lower=lower, upper=upper, inc=inc, 
scaling_matrix=scaling_matrix)
+                inc, lower_new, upper_new = 
self._grid_search_setup(spin=spin, param_vector=param_vector, lower=lower, 
upper=upper, inc=inc, scaling_matrix=scaling_matrix)
 
             # Linear constraints.
             if constraints:
@@ -706,7 +707,12 @@
                 # The relaxation times.
                 times.append(cdp.relax_times[key])
 
-            setup(num_params=len(spin.params), num_times=len(values), 
values=values, sd=errors, relax_times=times, 
scaling_matrix=scaling_matrix.tolist())
+            # The scaling matrix in a diagonalised list form.
+            scaling_list = []
+            for i in range(len(scaling_matrix)):
+                scaling_list.append(scaling_matrix[i, i])
+
+            setup(num_params=len(spin.params), num_times=len(values), 
values=values, sd=errors, relax_times=times, scaling_matrix=scaling_list)
 
 
             # Setup the minimisation algorithm when constraints are present.
@@ -737,7 +743,7 @@
 
             # Grid search.
             if search('^[Gg]rid', min_algor):
-                results = grid(func=self._func, args=(), num_incs=inc, 
lower=lower, upper=upper, A=A, b=b, verbosity=verbosity)
+                results = grid(func=self._func, args=(), num_incs=inc, 
lower=lower_new, upper=upper_new, A=A, b=b, verbosity=verbosity)
 
                 # Unpack the results.
                 param_vector, chi2, iter_count, warning = results

Modified: branches/relax_disp/target_functions/relax_fit.c
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/target_functions/relax_fit.c?rev=19398&r1=19397&r2=19398&view=diff
==============================================================================
--- branches/relax_disp/target_functions/relax_fit.c (original)
+++ branches/relax_disp/target_functions/relax_fit.c Fri Apr  5 19:29:31 2013
@@ -53,40 +53,26 @@
     relax_times = (double *) malloc(sizeof(double)*num_times);
     scaling_matrix = (double *) malloc(sizeof(double)*num_params);
 
-    /* Place the value elements into the C array */
+    /* Place the parameter related arguments into C arrays */
+    for (i = 0; i < num_params; i++) {
+        /* The diagonalised scaling matrix list argument element */
+        element = PySequence_GetItem(scaling_matrix_arg, i);
+        scaling_matrix[i] = PyFloat_AsDouble(element);
+    }
+
+    /* Place the time related arguments into C arrays */
     for (i = 0; i < num_times; i++) {
-        /* Get the element */
+        /* The value argument element */
         element = PySequence_GetItem(values_arg, i);
-
-        /* Convert to a C double */
         values[i] = PyFloat_AsDouble(element);
-    }
-
-    /* Place the sd elements into the C array */
-    for (i = 0; i < num_times; i++) {
-        /* Get the element */
+
+        /* The sd argument element */
         element = PySequence_GetItem(sd_arg, i);
-
-        /* Convert to a C double */
         sd[i] = PyFloat_AsDouble(element);
-    }
-
-    /* Place the relax_times elements into the C array */
-    for (i = 0; i < num_times; i++) {
-        /* Get the element */
+
+        /* The relax_times argument element */
         element = PySequence_GetItem(relax_times_arg, i);
-
-        /* Convert to a C double */
         relax_times[i] = PyFloat_AsDouble(element);
-    }
-
-    /* Place the scaling matrix elements into the C array */
-    for (i = 0; i < num_params; i++) {
-        /* Get the element */
-        element = PySequence_GetItem(values_arg, i);
-
-        /* Convert to a C double */
-        scaling_matrix[i] = PyFloat_AsDouble(element);
     }
 
     /* Return nothing */
@@ -119,6 +105,9 @@
 
         /* Convert to a C double */
         params[i] = PyFloat_AsDouble(element);
+
+        /* Scale the parameter */
+        params[i] = params[i] * scaling_matrix[i];
     }
 
     /* Back calculated the peak intensities */




Related Messages


Powered by MHonArc, Updated Fri Apr 05 20:00:02 2013