mailr9094 - /branches/frame_order/specific_fns/frame_order.py


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

Header


Content

Posted by edward on June 19, 2009 - 11:44:
Author: bugman
Date: Fri Jun 19 11:44:57 2009
New Revision: 9094

URL: http://svn.gna.org/viewcvs/relax?rev=9094&view=rev
Log:
Wrote the minimise() and __unpack_opt_results() methods.

The minimise() method is rudimentary and will not work.


Modified:
    branches/frame_order/specific_fns/frame_order.py

Modified: branches/frame_order/specific_fns/frame_order.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/frame_order/specific_fns/frame_order.py?rev=9094&r1=9093&r2=9094&view=diff
==============================================================================
--- branches/frame_order/specific_fns/frame_order.py (original)
+++ branches/frame_order/specific_fns/frame_order.py Fri Jun 19 11:44:57 2009
@@ -25,10 +25,14 @@
 
 # Python module imports.
 from math import pi
+from minfx.generic import generic_minimise
+from numpy import array, float64
 
 # relax module imports.
+from float import isNaN, isInf
 from generic_fns import pipes
-from relax_errors import RelaxNoModelError
+from maths_fns import frame_order_models
+from relax_errors import RelaxInfError, RelaxNaNError, RelaxNoModelError
 from specific_fns.base_class import Common_functions
 
 
@@ -59,6 +63,71 @@
             cdp.beta = None
             cdp.gamma = None
             cdp.theta = None
+
+
+    def __unpack_opt_results(self, results):
+        """Unpack and store the Frame Order optimisation results.
+
+        @param results: The results tuple returned by the minfx 
generic_minimise() function.
+        @type results:  tuple
+        """
+
+        # Alias the current data pipe.
+        cdp = pipes.get_pipe()
+
+        # Disassemble the results.
+        param_vector, chi2[i], iter_count, f_count, g_count, h_count, 
warning = results
+
+        # Catch infinite chi-squared values.
+        if isInf(func):
+            raise RelaxInfError, 'chi-squared'
+
+        # Catch chi-squared values of NaN.
+        if isNaN(func):
+            raise RelaxNaNError, 'chi-squared'
+
+        # Isotropic cone model.
+        if cdp.model == 'iso cone':
+            # Disassemble the parameter vector.
+            alpha, beta, gamma, theta = param_vector
+
+            # Wrap the cone angle to be between 0 and pi.
+            if theta < 0.0:
+                theta = -theta
+            if theta > pi:
+                theta = 2.0*pi - theta
+
+            # Monte Carlo simulation data structures.
+            if sim_index != None:
+                # Model parameters.
+                cdp.alpha_sim[sim_index] = alpha
+                cdp.beta_sim[sim_index] = beta
+                cdp.gamma_sim[sim_index] = gamma
+                cdp.theta_sim[sim_index] = theta
+
+                # Optimisation info.
+                cdp.chi2_sim[sim_index] = func
+                cdp.iter_sim[sim_index] = iter_count
+                cdp.f_count_sim[sim_index] = f_count
+                cdp.g_count_sim[sim_index] = g_count
+                cdp.h_count_sim[sim_index] = h_count
+                cdp.warning_sim[sim_index] = warning
+
+            # Normal data structures.
+            else:
+                # Model parameters.
+                cdp.alpha = alpha
+                cdp.beta = beta
+                cdp.gamma = gamma
+                cdp.theta = theta
+
+                # Optimisation info.
+                cdp.chi2 = func
+                cdp.iter = iter_count
+                cdp.f_count = f_count
+                cdp.g_count = g_count
+                cdp.h_count = h_count
+                cdp.warning = warning
 
 
     def grid_search(self, lower, upper, inc, constraints=False, verbosity=0, 
sim_index=None):
@@ -126,6 +195,52 @@
         self.minimise(min_algor='grid', min_options=grid_ops, 
constraints=constraints, verbosity=verbosity, sim_index=sim_index)
 
 
+    def minimise(self, min_algor=None, min_options=None, func_tol=None, 
grad_tol=None, max_iterations=None, constraints=False, scaling=True, 
verbosity=0, sim_index=None):
+        """Minimisation function.
+
+        @param min_algor:       The minimisation algorithm to use.
+        @type min_algor:        str
+        @param min_options:     An array of options to be used by the 
minimisation algorithm.
+        @type min_options:      array of str
+        @param func_tol:        The function tolerance which, when reached, 
terminates optimisation.
+                                Setting this to None turns of the check.
+        @type func_tol:         None or float
+        @param grad_tol:        The gradient tolerance which, when reached, 
terminates optimisation.
+                                Setting this to None turns of the check.
+        @type grad_tol:         None or float
+        @param max_iterations:  The maximum number of iterations for the 
algorithm.
+        @type max_iterations:   int
+        @param constraints:     If True, constraints are used during 
optimisation.
+        @type constraints:      bool
+        @param scaling:         If True, diagonal scaling is enabled during 
optimisation to allow
+                                the problem to be better conditioned.
+        @type scaling:          bool
+        @param verbosity:       A flag specifying the amount of information 
to print.  The higher
+                                the value, the greater the verbosity.
+        @type verbosity:        int
+        @param sim_index:       The index of the simulation to optimise.  
This should be None if
+                                normal optimisation is desired.
+        @type sim_index:        None or int
+        """
+
+        # Alias the current data pipe.
+        cdp = pipes.get_pipe()
+
+        # Isotropic cone model.
+        if cdp.model == 'iso cone':
+            # The initial parameter vector (the Euler angles and the cone 
angle).
+            param_vector = array([cdp.alpha, cdp.beta, cdp.gamma, 
cdp.theta], float64)
+
+            # Set up the optimisation function.
+            model = frame_order_models.Frame_order()
+
+        # Minimisation.
+        results = generic_minimise(func=model.func, args=(), 
x0=param_vector, min_algor=MIN_ALGOR, full_output=1, print_flag=1)
+
+        # Unpack the results.
+        self.__unpack_opt_results(results)
+
+
     def select_model(self, model=None):
         """Select the Frame Order model.
 




Related Messages


Powered by MHonArc, Updated Fri Jun 19 12:00:05 2009