Author: bugman Date: Fri Aug 8 11:26:18 2008 New Revision: 7118 URL: http://svn.gna.org/viewcvs/relax?rev=7118&view=rev Log: Shifted the __update_model() method for fixing the alphabetical ordering of methods. Modified: branches/rdc_analysis/specific_fns/n_state_model.py Modified: branches/rdc_analysis/specific_fns/n_state_model.py URL: http://svn.gna.org/viewcvs/relax/branches/rdc_analysis/specific_fns/n_state_model.py?rev=7118&r1=7117&r2=7118&view=diff ============================================================================== --- branches/rdc_analysis/specific_fns/n_state_model.py (original) +++ branches/rdc_analysis/specific_fns/n_state_model.py Fri Aug 8 11:26:18 2008 @@ -263,6 +263,90 @@ gamma[i] = param_vector[cdp.N-1 + 3*i + 2] + def __linear_constraints(self, data_types=None, scaling_matrix=None): + """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 4-state model, the last probability pn is not included as this + parameter does not exist (because the sum of pc is equal to 1). The Euler angle parameters + have been excluded here but will be included in the returned A and b objects. These + parameters simply add columns of zero to the A matrix and have no effect on b. + + + @keyword data_types: The base data types used in the optimisation. This list can + contain the elements 'rdc', 'pcs' or 'tensor'. + @type data_types: list of str + @keyword scaling_matrix: The diagonal scaling matrix. + @type scaling_matrx: numpy rank-2 square matrix + @return: The matrices A and b. + @rtype: tuple of len 2 of a numpy rank-2, size NxM matrix and numpy + rank-1, size N array + """ + + # Alias the current data pipe. + cdp = ds[ds.current_pipe] + + # Starting point of the populations. + pop_start = 0 + if 'rdc' in data_types or 'pcs' in data_types: + pop_start = pop_start + 5*len(cdp.align_tensors) + + # Initialisation (0..j..m). + A = [] + b = [] + zero_array = zeros(self.param_num(), float64) + i = pop_start + j = 0 + + # Loop over the prob parameters (N - 1, because the sum of pc is 1). + for k in xrange(cdp.N - 1): + # 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 __update_model(self): """Update the model parameters as necessary.""" @@ -334,90 +418,6 @@ # Initialise the tensor. if not exists: generic_fns.align_tensor.init(tensor=id, params=[0.0, 0.0, 0.0, 0.0, 0.0]) - - - def __linear_constraints(self, data_types=None, scaling_matrix=None): - """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 4-state model, the last probability pn is not included as this - parameter does not exist (because the sum of pc is equal to 1). The Euler angle parameters - have been excluded here but will be included in the returned A and b objects. These - parameters simply add columns of zero to the A matrix and have no effect on b. - - - @keyword data_types: The base data types used in the optimisation. This list can - contain the elements 'rdc', 'pcs' or 'tensor'. - @type data_types: list of str - @keyword scaling_matrix: The diagonal scaling matrix. - @type scaling_matrx: numpy rank-2 square matrix - @return: The matrices A and b. - @rtype: tuple of len 2 of a numpy rank-2, size NxM matrix and numpy - rank-1, size N array - """ - - # Alias the current data pipe. - cdp = ds[ds.current_pipe] - - # Starting point of the populations. - pop_start = 0 - if 'rdc' in data_types or 'pcs' in data_types: - pop_start = pop_start + 5*len(cdp.align_tensors) - - # Initialisation (0..j..m). - A = [] - b = [] - zero_array = zeros(self.param_num(), float64) - i = pop_start - j = 0 - - # Loop over the prob parameters (N - 1, because the sum of pc is 1). - for k in xrange(cdp.N - 1): - # 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 CoM(self, pivot_point=None, centre=None):