mailRe: [bug #22146] Unpacking of R2A and R2B is performed wrong for clustered "full" dispersion models


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

Header


Content

Posted by Edward d'Auvergne on June 06, 2014 - 11:52:
Hi,

If this is where the problem is, then I would recommend a full system
test where you perform a grid search where the inc value for all
dimensions is 1 and the upper and lower bounds are equal and set to a
set of parameter values so that a single grid increment is performed,
and then the optimised parameter values matching the lower and upper
bound arguments are unpacked into the spin containers and can be
checked.

As for a separate function for unpacking R20A and R20B in the target
functions, this would normally be a good idea.  But as calling
functions has an overhead, for speed it might be better to leave this
as a two line change:

        # Unpack the parameter values.
        R20A = params[:self.end_index[0]]
        R20B = params[self.end_index[0]:self.end_index[1]]

to:

        # Unpack the parameter values.
        R20 = params[:self.end_index[1]]
        R20A, R20B = transpose(R20.reshape(self.num_spins, 2))

This will be sufficient.  It would be good to have a system test to
check the before and after implementation.  This system test could
then be replicated for all the different 'full' dispersion models.
Then this problem will never reappear.

Cheers,

Edward




On 6 June 2014 11:39, Troels Emtekær Linnet <tlinnet@xxxxxxxxxxxxx> wrote:
There is no doubt that it is the unpacking of the R20A and R20B in the
target function.

I was thinking of creating a function, which do the the unpacking.

This unpacking function could then be tested with a unit test?

What do you think?
Where should I position such a function?

Best
Troels



2014-06-06 11:26 GMT+02:00 Edward d'Auvergne <edward@xxxxxxxxxxxxx>:

Hi Troels,


The best way to handle this is to first create a unit test of the
specific_analyses.relax_disp.parameters.disassemble_param_vector()
where the problem is likely to be most easily found.  I don't
understand how this could be a problem as the assemble_param_vector()
and disassemble_param_vector() functions both call the same
loop_parameters() function for the ordering of the parameter values!
Maybe the problem is in the unpacking of the parameter vector in the
target functions themselves, for example in the full B14 model:


    def func_B14_full(self, params):
        """Target function for the Baldwin (2014) 2-site exact
solution model for all time scales.

        This assumes that pA > pB, and hence this must be implemented
as a constraint.


        @param params:  The vector of parameter values.
        @type params:   numpy rank-1 float array
        @return:        The chi-squared value.
        @rtype:         float
        """

        # Scaling.
        if self.scaling_flag:
            params = dot(params, self.scaling_matrix)

        # Unpack the parameter values.
        R20A = params[:self.end_index[0]]
        R20B = params[self.end_index[0]:self.end_index[1]]
        dw = params[self.end_index[1]:self.end_index[2]]
        pA = params[self.end_index[2]]
        kex = params[self.end_index[2]+1]

        # Calculate and return the chi-squared value.
        return self.calc_B14_chi2(R20A=R20A, R20B=R20B, dw=dw, pA=pA,
kex=kex)


This R20A and R20B unpacking might be the failure point as this may
not match the loop_parameters() function - which it must!  In any
case, having a unit or system test catch the problem would be very
useful for the stability of the dispersion analysis in relax.

A code example might be useful:

R20_params = array([1, 2, 3, 4])
R20A, R20B = transpose(R20_params.reshape(2, 2)
print(R20A)
print(R20B)

You should see that R20A is [1, 3], and R20B is [2, 4].  This is how
the parameters are handled in the loop_parameters() function which
defines the parameter vector in all parts of relax.  There might be a
quicker way to unpack the parameters, but such an idea could be used
for the target functions.

Cheers,

Edward

On 6 June 2014 11:08, Troels E. Linnet <NO-REPLY.INVALID-ADDRESS@xxxxxxx>
wrote:
URL:
  <http://gna.org/bugs/?22146>

                 Summary: Unpacking of R2A and R2B is performed wrong
for
clustered "full" dispersion models
                 Project: relax
            Submitted by: tlinnet
            Submitted on: Fri 06 Jun 2014 09:08:58 AM UTC
                Category: relax's source code
Specific analysis category: Relaxation dispersion
                Priority: 9 - Immediate
                Severity: 4 - Important
                  Status: None
             Assigned to: None
         Originator Name:
        Originator Email:
             Open/Closed: Open
                 Release: Repository: trunk
         Discussion Lock: Any
        Operating System: All systems

    _______________________________________________________

Details:

The unpacking of the R2A and R2B parameters in the "full" model is
performed
wrong.
This will happen performing a clustered analysis, using one of the
"full"
models.

This bug affect all analysis performed running with a "full" model, with
clustered residues.

The bug is located in the target function:
./target_functions/relax_disp.py

For all the "func_MODEL_full", the unpacking of:
R20A = params[:self.end_index[0]]
R20B = params[self.end_index[0]:self.end_index[1]]

This is wrong, since the "params" list, is ordered:
[spin, spin, spin, [dw], pA, kex], where spin = [nr_frq*r2a, nr_frq*r2b]

This ordering happens in:
./specific_analysis/relax_disp/parameters.py
in the loop_parameters.py

A possible solutions i shown below.
This alter the unpacking of the parameters.

An example of profiling_cr72.py is attached.
This can be downloaded, and run in base folder of relax:
./profiling_cr72.py .

This is with 3 frq, and 3 spins.

The current implementations would unpack:
('R20A', array([  2.,   2.,   2.,   4.,   4.,   4.,  12.,  12.,  12.]),
9)
('R20B', array([ 14.,  14.,  14.,  22.,  22.,  22.,  24.,  24.,  24.]),
9)

R2A is 2, 12, 22 for the spins 0-3
R2B is, 4, 14, 24 for the spins 0-3

The suggested unpacking loop, unpacks to:
('R20A', array([  2.,   2.,   2.,  12.,  12.,  12.,  22.,  22.,  22.]),
9)
('R20B', array([  4.,   4.,   4.,  14.,  14.,  14.,  24.,  24.,  24.]),
9)


-------
from numpy import array, concatenate, delete, index_exp
import numpy

p = array([  1.000000000000000e+01, 1.000000000000000e+01,
1.100000000000000e+01
, 1.100000000000000e+01, 1.000000000000000e+01, 1.000000000000000e+01
, 1.100000000000000e+01, 1.100000000000000e+01, 1.000000000000000e+00
, 1.000000000000000e+00, 9.000000000000000e-01, 1.000000000000000e+03])

e = [4, 8, 10]

# Now
r2a = p[:e[0]]
print r2a
r2b = p[e[0]:e[1]]
print r2b
dw = p[e[1]:e[2]]
print dw
pA = p[e[2]]
print pA
kex = p[e[2]+1]
print kex

print "new"
ns = 2
nf = 2

ml = p[:e[1]]

R20A = array([])
R20B = array([])
for i in range(0, ns):
    # Array sorted per [spin, spin, spin], where spin = [nr_frq*r2a,
nr_frq*r2b]
    spin_AB = ml[:nf*2]
    ml = delete(ml, numpy.s_[:nf*2])
    R20A = concatenate([R20A, spin_AB[:nf] ])
    R20B = concatenate([R20B, spin_AB[nf:] ])

print R20A
print R20B
print dw
print pA
print kex



    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Fri 06 Jun 2014 09:08:58 AM UTC  Name: profiling_cr72.py  Size:
17kB
By: tlinnet

<http://gna.org/bugs/download.php?file_id=20938>

    _______________________________________________________

Reply to this item at:

  <http://gna.org/bugs/?22146>

_______________________________________________
  Message sent via/by Gna!
  http://gna.org/


_______________________________________________
relax (http://www.nmr-relax.com)

This is the relax-devel mailing list
relax-devel@xxxxxxx

To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-devel





Related Messages


Powered by MHonArc, Updated Fri Jun 06 18:20:11 2014