mailr9103 - /branches/frame_order/maths_fns/frame_order_models.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 - 16:07:
Author: bugman
Date: Fri Jun 19 16:07:41 2009
New Revision: 9103

URL: http://svn.gna.org/viewcvs/relax?rev=9103&view=rev
Log:
Preliminary support for optimisation against alignment tensors.

Added the func_iso_cone() and __init_iso_cone() methods.


Modified:
    branches/frame_order/maths_fns/frame_order_models.py

Modified: branches/frame_order/maths_fns/frame_order_models.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/frame_order/maths_fns/frame_order_models.py?rev=9103&r1=9102&r2=9103&view=diff
==============================================================================
--- branches/frame_order/maths_fns/frame_order_models.py (original)
+++ branches/frame_order/maths_fns/frame_order_models.py Fri Jun 19 16:07:41 
2009
@@ -24,24 +24,35 @@
 """Module containing the target functions of the Frame Order theories."""
 
 # Python module imports.
-from numpy import dot, float64, ones, transpose, zeros
+from copy import deepcopy
+from numpy import float64, ones, zeros
 
 # relax module imports.
 from maths_fns.chi2 import chi2
-from maths_fns.frame_order_matrix_ops import populate_2nd_eigenframe_iso_cone
-from maths_fns.kronecker_product import kron_prod, transpose_14
-from maths_fns.rotation_matrix import R_euler_zyz
+from maths_fns.frame_order_matrix_ops import compile_2nd_matrix_iso_cone
 from relax_errors import RelaxError
 
 
 class Frame_order:
     """Class containing the target function of the optimisation of Frame 
Order matrix components."""
 
-    def __init__(self, model=None, frame_order_2nd=None):
+    def __init__(self, model=None, init_params=None, full_tensors=None, 
red_tensors=None, red_errors=None, frame_order_2nd=None):
         """Set up the target functions for the Frame Order theories.
         
         @keyword model:             The name of the Frame Order model.
         @type model:                str
+        @keyword init_params:       The initial parameter values.
+        @type init_params:          numpy float64 array
+        @keyword full_tensors:      A list of the full alignment tensors in 
5D, rank-1 form of {Sxx,
+                                    Syy, Sxy, Sxz, Syz} values.
+        @type full_tensors:         list of 5D, rank-1 arrays
+        @keyword red_tensors:       An array of the {Sxx, Syy, Sxy, Sxz, 
Syz} values for all reduced
+                                    tensors.  The format is [Sxx1, Syy1, 
Sxy1, Sxz1, Syz1, Sxx2,
+                                    Syy2, Sxy2, Sxz2, Syz2, ..., Sxxn, Syyn, 
Sxyn, Sxzn, Syzn]
+        @type red_tensors:          numpy nx5D, rank-1 float64 array
+        @keyword red_errors:        An array of the {Sxx, Syy, Sxy, Sxz, 
Syz} errors for all reduced
+                                    tensors.  The array format is the same 
as for red_tensors.
+        @type red_errors:           numpy nx5D, rank-1 float64 array
         @keyword frame_order_2nd:   The numerical values of the 2nd degree 
Frame Order matrix.  If
                                     supplied, the target functions will 
optimise directly to these
                                     values.
@@ -52,11 +63,57 @@
         if not model:
             raise RelaxError, "The type of Frame Order model must be 
specified."
 
+        # Store the initial parameter (as a copy).
+        self.params = deepcopy(init_params)
+
         # Isotropic cone model.
         if model == 'iso cone':
+            # Mix up.
+            if full_tensors != None and frame_order_2nd != None:
+                raise RelaxError, "Tensors and Frame Order matrices cannot 
be supplied together."
+
+            # Tensor optimisation.
+            if full_tensors != None:
+                self.__init_iso_cone_elements(full_tensors, red_tensors, 
red_errors)
+
             # Optimisation to the 2nd degree Frame Order matrix components 
directly.
             if frame_order_2nd != None:
                 self.__init_iso_cone_elements(frame_order_2nd)
+
+
+    def __init_iso_cone(self, full_tensors, red_tensors, red_errors):
+        """Set up isotropic cone optimisation against the alignment tensor 
data.
+
+        @keyword full_tensors:      A list of the full alignment tensors in 
5D, rank-1 form of {Sxx,
+                                    Syy, Sxy, Sxz, Syz} values.
+        @type full_tensors:         list of 5D, rank-1 arrays
+        @keyword red_tensors:       An array of the {Sxx, Syy, Sxy, Sxz, 
Syz} values for all reduced
+                                    tensors.  The format is [Sxx1, Syy1, 
Sxy1, Sxz1, Syz1, Sxx2,
+                                    Syy2, Sxy2, Sxz2, Syz2, ..., Sxxn, Syyn, 
Sxyn, Sxzn, Syzn]
+        @type red_tensors:          numpy nx5D, rank-1 float64 array
+        @keyword red_errors:        An array of the {Sxx, Syy, Sxy, Sxz, 
Syz} errors for all reduced
+                                    tensors.  The array format is the same 
as for red_tensors.
+        @type red_errors:           numpy nx5D, rank-1 float64 array
+        """
+
+        # Checks.
+        if red_tensors != None:
+            raise RelaxError, "The reduced tensors have not been supplied."
+
+        # Tensor set up.
+        self.full_tensors = array(full_tensors, float64)
+        self.num_tensors = len(self.full_tensors)
+        self.red_tensors = red_tensors
+        self.red_errors = red_errors
+
+        # The rotation to the Frame Order eigenframe.
+        self.rot = zeros((3, 3), float64)
+
+        # Initialise the Frame Order matrices.
+        self.frame_order_2nd = zeros((9, 9), float64)
+
+        # Alias the target function.
+        self.func = self.func_iso_cone
 
 
     def __init_iso_cone_elements(self, frame_order_2nd):
@@ -84,12 +141,12 @@
         self.func = self.func_iso_cone_elements
 
 
-    def func_iso_cone_elements(self, params):
-        """Target function for isotropic cone model optimisation using the 
Frame Order matrix.
-
-        This function optimises by directly matching the elements of the 2nd 
degree Frame Order
-        super matrix.  The Frame Order eigenframe via the alpha, beta, and 
gamma Euler angles, and
-        the cone angle theta are the 4 parameters optimised in this model.
+    def func_iso_cone(self, params):
+        """Target function for isotropic cone model optimisation using the 
alignment tensors.
+
+        This function optimises against alignment tensors.  The Frame Order 
eigenframe via the
+        alpha, beta, and gamma Euler angles, and the cone angle theta are 
the 4 parameters optimised
+        in this model.
 
         @param params:  The vector of parameter values {alpha, beta, gamma, 
theta} where the first
                         three are the Euler angles for the Frame Order 
eigenframe and theta is the
@@ -102,25 +159,38 @@
         # Break up the parameters.
         alpha, beta, gamma, theta = params
 
-        # Populate the Frame Order matrix in the eigenframe.
-        populate_2nd_eigenframe_iso_cone(self.frame_order_2nd, theta)
-
-        # Generate the rotation matrix.
-        R_euler_zyz(self.rot, alpha, beta, gamma)
-
-        # The outer product of R.
-        R_kron = kron_prod(self.rot, self.rot)
-
-        # Perform the T14 transpose to obtain the Kronecker product matrix!
-        self.frame_order_2nd = transpose_14(self.frame_order_2nd)
-
-        # Rotate.
-        self.frame_order_2nd = dot(R_kron, dot(self.frame_order_2nd, 
transpose(R_kron)))
-
-        # Perform T14 again to return back.
-        self.frame_order_2nd = transpose_14(self.frame_order_2nd)
-
-        # Make the Frame Order contiguous.
+        # Generate the 2nd degree Frame Order super matrix.
+        compile_2nd_matrix_iso_cone(self.frame_order_2nd, self.rot, alpha, 
beta, gamma, theta)
+
+        # Get the chi-squared value.
+        val = chi2(self.data, self.frame_order_2nd, self.errors)
+
+        # Return the chi2 value.
+        return val
+
+
+    def func_iso_cone_elements(self, params):
+        """Target function for isotropic cone model optimisation using the 
Frame Order matrix.
+
+        This function optimises by directly matching the elements of the 2nd 
degree Frame Order
+        super matrix.  The Frame Order eigenframe via the alpha, beta, and 
gamma Euler angles, and
+        the cone angle theta are the 4 parameters optimised in this model.
+
+        @param params:  The vector of parameter values {alpha, beta, gamma, 
theta} where the first
+                        three are the Euler angles for the Frame Order 
eigenframe and theta is the
+                        isotropic cone angle.
+        @type params:   list of float
+        @return:        The chi-squared or SSE value.
+        @rtype:         float
+        """
+
+        # Break up the parameters.
+        alpha, beta, gamma, theta = params
+
+        # Generate the 2nd degree Frame Order super matrix.
+        compile_2nd_matrix_iso_cone(self.frame_order_2nd, self.rot, alpha, 
beta, gamma, theta)
+
+        # Make the Frame Order matrix contiguous.
         self.frame_order_2nd = self.frame_order_2nd.copy()
 
         # Reshape the numpy arrays for use in the chi2() function.




Related Messages


Powered by MHonArc, Updated Fri Jun 19 16:20:02 2009