mailr25334 - in /trunk: auto_analyses/ specific_analyses/relax_disp/


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

Header


Content

Posted by tlinnet on August 27, 2014 - 13:22:
Author: tlinnet
Date: Wed Aug 27 13:22:45 2014
New Revision: 25334

URL: http://svn.gna.org/viewcvs/relax?rev=25334&view=rev
Log:
Implemented the use of "Newton" as minimisation algorithm for R2eff curve 
fitting instead of simplex.

Running the test script:
test_suite/shared_data/dispersion/Kjaergaard_et_al_2013/2_pre_run_r2eff.py

For 50 Monte-Carlo simulations, the time drop from:
3 minutes and 13 s, to 1 min an 5 seconds.

task #7822(https://gna.org/task/index.php?7822): Implement user function to 
estimate R2eff and associated errors for exponential curve fitting.

Modified:
    trunk/auto_analyses/relax_disp.py
    trunk/specific_analyses/relax_disp/api.py
    trunk/specific_analyses/relax_disp/optimisation.py

Modified: trunk/auto_analyses/relax_disp.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/auto_analyses/relax_disp.py?rev=25334&r1=25333&r2=25334&view=diff
==============================================================================
--- trunk/auto_analyses/relax_disp.py   (original)
+++ trunk/auto_analyses/relax_disp.py   Wed Aug 27 13:22:45 2014
@@ -426,6 +426,10 @@
             # The constraints flag.
             constraints = False
 
+            # The minimisation algorithm to use.
+            # Both the Jacobian and Hessian matrix has been specified for 
exponential curve-fitting, allowing for the much faster algorithms to be used.
+            min_algor = 'Newton'
+
             # Check if all spins contains 'r2eff and it associated error.
             has_r2eff = False
 
@@ -454,10 +458,12 @@
         else:
             do_minimise = True
             constraints = True
+            # The minimisation algorithm to use. If the Jacobian and Hessian 
matrix have not been specified for fitting, 'simplex' should be used.
+            min_algor = 'simplex'
 
         # Do the minimisation.
         if do_minimise:
-            self.interpreter.minimise.execute('simplex', 
func_tol=self.opt_func_tol, max_iter=self.opt_max_iterations, 
constraints=constraints)
+            self.interpreter.minimise.execute(min_algor=min_algor, 
func_tol=self.opt_func_tol, max_iter=self.opt_max_iterations, 
constraints=constraints)
 
         # Model elimination.
         if self.eliminate:
@@ -469,6 +475,9 @@
             # The constraints flag.
             constraints = False
 
+            # Both the Jacobian and Hessian matrix has been specified for 
exponential curve-fitting, allowing for the much faster algorithms to be used.
+            min_algor = 'Newton'
+
             # Skip optimisation, if 'r2eff' + 'r2eff_err' is present and 
flag for forcing optimisation is not raised.
             if has_r2eff and not self.optimise_r2eff:
                 pass
@@ -482,9 +491,11 @@
                 do_monte_carlo = True
 
         elif self.mc_sim_all_models or len(self.models) < 2:
+            do_monte_carlo = True
             # The constraints flag.
             constraints = True
-            do_monte_carlo = True
+            # The minimisation algorithm to use. If the Jacobian and Hessian 
matrix have not been specified for fitting, 'simplex' should be used.
+            min_algor = 'simplex'
 
         # Do Monte Carlo simulations.
         if do_monte_carlo:
@@ -494,7 +505,7 @@
                 self.interpreter.monte_carlo.setup(number=self.mc_sim_num)
             self.interpreter.monte_carlo.create_data()
             self.interpreter.monte_carlo.initial_values()
-            self.interpreter.minimise.execute('simplex', 
func_tol=self.opt_func_tol, max_iter=self.opt_max_iterations, 
constraints=constraints)
+            self.interpreter.minimise.execute(min_algor=min_algor, 
func_tol=self.opt_func_tol, max_iter=self.opt_max_iterations, 
constraints=constraints)
             if self.eliminate:
                 self.interpreter.eliminate()
             self.interpreter.monte_carlo.error_analysis()

Modified: trunk/specific_analyses/relax_disp/api.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/specific_analyses/relax_disp/api.py?rev=25334&r1=25333&r2=25334&view=diff
==============================================================================
--- trunk/specific_analyses/relax_disp/api.py   (original)
+++ trunk/specific_analyses/relax_disp/api.py   Wed Aug 27 13:22:45 2014
@@ -26,7 +26,7 @@
 
 # Python module imports.
 from copy import deepcopy
-from re import search
+from re import match, search
 import sys
 from types import MethodType
 
@@ -573,9 +573,44 @@
         algor = min_algor
         if min_algor == 'Log barrier':
             algor = min_options[0]
-        allowed = ['grid', 'simplex']
-        if algor not in allowed:
-            raise RelaxError("Only the 'simplex' minimisation algorithm is 
supported for the relaxation dispersion analysis as function gradients are 
not implemented.")
+
+        allow = False
+        # Check the model type.
+        if hasattr(cdp, 'model_type'):
+            # Set the model type:
+            model_type = cdp.model_type
+
+            if model_type == MODEL_R2EFF:
+                if match('^[Gg]rid$', algor):
+                    allow = True
+
+                elif match('^[Ss]implex$', algor):
+                    allow = True
+
+                # Quasi-Newton BFGS minimisation.
+                elif match('^[Bb][Ff][Gg][Ss]$', algor):
+                    allow = True
+
+                # Newton minimisation.
+                elif match('^[Nn]ewton$', algor):
+                    allow = True
+
+            # If the Jacobian and Hessian matrix have not been specified for 
fitting, 'simplex' should be used.
+            else:
+                if match('^[Gg]rid$', algor):
+                    allow = True
+
+                elif match('^[Ss]implex$', algor):
+                    allow = True
+
+        # Do not allow, if no model has been specified.
+        else:
+            model_type = 'None'
+            # Do not allow.
+            allow = False
+
+        if not allow:
+            raise RelaxError("Minimisation algorithm '%s' is not allowed, 
since function gradients for model '%s' is not implemented.  Only the 
'simplex' minimisation algorithm is supported for the relaxation dispersion 
analysis of this model."%(algor, model_type))
 
         # Initialise some empty data pipe structures so that the target 
function set up does not fail.
         if not hasattr(cdp, 'cpmg_frqs_list'):

Modified: trunk/specific_analyses/relax_disp/optimisation.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/specific_analyses/relax_disp/optimisation.py?rev=25334&r1=25333&r2=25334&view=diff
==============================================================================
--- trunk/specific_analyses/relax_disp/optimisation.py  (original)
+++ trunk/specific_analyses/relax_disp/optimisation.py  Wed Aug 27 13:22:45 
2014
@@ -47,7 +47,12 @@
 
 # C modules.
 if C_module_exp_fn:
-    from target_functions.relax_fit import setup, func, dfunc, d2func, 
back_calc_I
+    from specific_analyses.relax_fit.optimisation import func_wrapper, 
dfunc_wrapper, d2func_wrapper
+    from target_functions.relax_fit import setup, back_calc_I
+    # Call the python wrapper function to help with list to numpy array 
conversion.
+    func = func_wrapper
+    dfunc = dfunc_wrapper
+    d2func = d2func_wrapper
 
 
 def back_calc_peak_intensities(spin=None, exp_type=None, frq=None, 
offset=None, point=None):




Related Messages


Powered by MHonArc, Updated Wed Aug 27 13:40:02 2014