mailr4634 - /branches/N_state_model/specific_fns/n_state_model.py


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

Header


Content

Posted by edward on January 11, 2008 - 11:40:
Author: bugman
Date: Fri Jan 11 11:40:43 2008
New Revision: 4634

URL: http://svn.gna.org/viewcvs/relax?rev=4634&view=rev
Log:
Implemented the N-state model linear_constraints() method.


Modified:
    branches/N_state_model/specific_fns/n_state_model.py

Modified: branches/N_state_model/specific_fns/n_state_model.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/N_state_model/specific_fns/n_state_model.py?rev=4634&r1=4633&r2=4634&view=diff
==============================================================================
--- branches/N_state_model/specific_fns/n_state_model.py (original)
+++ branches/N_state_model/specific_fns/n_state_model.py Fri Jan 11 11:40:43 
2008
@@ -75,6 +75,79 @@
 
         # Minimisation.
         self.minimise(min_algor='grid', constraints=constraints, 
verbosity=verbosity, sim_index=sim_index)
+
+
+    def linear_constraints(self):
+        """Function for setting up the linear constraint matrices A and b.
+
+        Standard notation
+        =================
+
+        The N-state model constraints are:
+
+            0 <= pc <= 1,
+
+        where p is the probability and c corresponds to state c.
+
+
+        Matrix notation
+        ===============
+
+        In the notation A.x >= b, where A is an matrix of coefficients, x is 
an array of parameter
+        values, and b is a vector of scalars, these inequality constraints 
are:
+
+            | 1  0  0 |                   |    0    |
+            |         |                   |         |
+            |-1  0  0 |                   |   -1    |
+            |         |     |  p0  |      |         |
+            | 0  1  0 |  .  |      |      |    0    |
+            |         |     |  p1  |  >=  |         |
+            | 0 -1  0 |     |      |      |   -1    |
+            |         |     |  p2  |      |         |
+            | 0  0  1 |                   |    0    |
+            |         |                   |         |
+            | 0  0 -1 |                   |   -1    |
+
+        This example is for a 3-state model.
+
+
+        @return:    The matrices A and b.
+        @rtype:     tuple of len 2 of a numpy matrix and numpy array
+        """
+
+        # Initialisation (0..j..m).
+        A = []
+        b = []
+        n = len(self.param_vector)
+        zero_array = zeros(n, float64)
+        i = 0
+        j = 0
+
+        # Alias the current data pipe.
+        cdp = relax_data_store[relax_data_store.current_pipe]
+
+        # Loop over the parameters.
+        for k in xrange(len(cdp.params)):
+            # Probabilities.
+            if data.params[k] == 'pc':
+                # 0 <= pc <= 1.
+                A.append(zero_array * 0.0)
+                A.append(zero_array * 0.0)
+                A[j][i] = 1.0
+                A[j+1][i] = -1.0
+                b.append(0.0)
+                b.append(-1.0)
+                j = j + 2
+
+            # Increment i.
+            i = i + 1
+
+        # Convert to numpy data structures.
+        A = array(A, float64)
+        b = array(b, float64)
+
+        # Return the contraint objects.
+        return A, b
 
 
     def overfit_deselect(self):
@@ -112,6 +185,10 @@
         # Create the initial parameter vector.
         param_vector = self.assemble_param_vector(sim_index=sim_index)
 
+        # Linear constraints.
+        if constraints:
+            A, b = self.linear_constraints(index=i)
+
         # Set up the class instance containing the target function.
         model = N_state_opt()
 




Related Messages


Powered by MHonArc, Updated Fri Jan 11 12:00:25 2008