Hi,

This is a speed up, but there is a much better speed up.  Don't define
g_fact in the target function.  Define it in the lib.dispersion.b14
module, outside of the function (above the function).  Then it is not
calculated once for each target function call, but only once for the
entire time you run relax!  This completely eliminates the calculation
from the optimisation.

Regards,

Edward




On 6 May 2014 17:24,  <[email protected]> wrote:
> Author: tlinnet
> Date: Tue May  6 17:24:28 2014
> New Revision: 23010
>
> URL: http://svn.gna.org/viewcvs/relax?rev=23010&view=rev
> Log:
> Speed-up. Moved g_factor: g = 1/sqrt(2) outside library function to be 
> calculated once.
>
> sr #3154: (https://gna.org/support/?3154) Implementation of Baldwin (2014) 
> B14 model - 2-site exact solution model for all time scales.
>
> This follows the tutorial for adding relaxation dispersion models at:
> http://wiki.nmr-relax.com/Tutorial_for_adding_relaxation_dispersion_models_to_relax#Debugging
>
>
> Modified:
>     trunk/lib/dispersion/b14.py
>     trunk/target_functions/relax_disp.py
>
> Modified: trunk/lib/dispersion/b14.py
> URL: 
> http://svn.gna.org/viewcvs/relax/trunk/lib/dispersion/b14.py?rev=23010&r1=23009&r2=23010&view=diff
> ==============================================================================
> --- trunk/lib/dispersion/b14.py (original)
> +++ trunk/lib/dispersion/b14.py Tue May  6 17:24:28 2014
> @@ -102,7 +102,7 @@
>  from numpy import arccosh, cos, cosh, log, sin, sinh, sqrt, power
>
>
> -def r2eff_B14(r20a=None, r20b=None, deltaR2=None, alpha_m=None, pA=None, 
> pB=None, dw=None, zeta=None, Psi=None, kex=None, k_AB=None, k_BA=None, 
> ncyc=None, inv_tcpmg=None, tcp=None, back_calc=None, num_points=None):
> +def r2eff_B14(r20a=None, r20b=None, deltaR2=None, alpha_m=None, pA=None, 
> pB=None, dw=None, zeta=None, Psi=None, g_fact=None, kex=None, k_AB=None, 
> k_BA=None, ncyc=None, inv_tcpmg=None, tcp=None, back_calc=None, 
> num_points=None):
>      """Calculate the R2eff values for the CR72 model.
>
>      See the module docstring for details.
> @@ -126,6 +126,8 @@
>      @type zeta:             float
>      @keyword Psi:           The Carver and Richards (1972) Psi notation. Psi 
> =  alpha_m**2 + 4 * k_BA * k_AB - dw**2.
>      @type Psi:              float
> +    @keyword g_fact:        The factor g = 1/sqrt(2). This is calculated 
> outside library function, to only be calculated once.
> +    @type g_fact:           float
>      @keyword kex:           The kex parameter value (the exchange rate in 
> rad/s).
>      @type kex:              float
>      @keyword k_AB:          The rate of exchange from site A to B (rad/s).
> @@ -151,8 +153,8 @@
>      two_tcp = 2.0 * tcp
>
>      # Get the real and imaginary components of the exchange induced shift.
> -    g3 = 1/sqrt(2) * sqrt(Psi + sqrt(zeta2 + Psi2))
> -    g4 = 1/sqrt(2) * sqrt(-Psi + sqrt(zeta2 + Psi2))
> +    g3 = g_fact * sqrt(Psi + sqrt(zeta2 + Psi2))
> +    g4 = g_fact * sqrt(-Psi + sqrt(zeta2 + Psi2))
>
>      # Repetitive calculations (to speed up calculations).
>      g32 = g3**2
>
> Modified: trunk/target_functions/relax_disp.py
> URL: 
> http://svn.gna.org/viewcvs/relax/trunk/target_functions/relax_disp.py?rev=23010&r1=23009&r2=23010&view=diff
> ==============================================================================
> --- trunk/target_functions/relax_disp.py        (original)
> +++ trunk/target_functions/relax_disp.py        Tue May  6 17:24:28 2014
> @@ -27,7 +27,7 @@
>  # Python module imports.
>  from copy import deepcopy
>  from math import pi
> -from numpy import complex64, dot, float64, int16, zeros
> +from numpy import complex64, dot, float64, int16, sqrt, zeros
>
>  # relax module imports.
>  from lib.dispersion.b14 import r2eff_B14
> @@ -790,6 +790,7 @@
>          pB = 1.0 - pA
>          k_BA = pA * kex
>          k_AB = pB * kex
> +        g_fact = 1/sqrt(2)
>
>          # Initialise.
>          chi2_sum = 0.0
> @@ -823,7 +824,7 @@
>                      Psi = alpha_m**2 + 4 * k_BA * k_AB - aliased_dw**2
>
>                      # Back calculate the R2eff values.
> -                    r2eff_B14(r20a=r20a, r20b=r20b, deltaR2=deltaR2, 
> alpha_m=alpha_m, pA=pA, pB=pB, dw=dw_frq, zeta=zeta, Psi=Psi, kex=kex, 
> k_AB=k_AB, k_BA=k_BA, ncyc=self.power[ei][mi], 
> inv_tcpmg=self.inv_relax_times[ei][mi], tcp=self.tau_cpmg[ei][mi], 
> back_calc=self.back_calc[ei][si][mi][0], 
> num_points=self.num_disp_points[ei][si][mi][0])
> +                    r2eff_B14(r20a=r20a, r20b=r20b, deltaR2=deltaR2, 
> alpha_m=alpha_m, pA=pA, pB=pB, dw=dw_frq, zeta=zeta, Psi=Psi, g_fact=g_fact, 
> kex=kex, k_AB=k_AB, k_BA=k_BA, ncyc=self.power[ei][mi], 
> inv_tcpmg=self.inv_relax_times[ei][mi], tcp=self.tau_cpmg[ei][mi], 
> back_calc=self.back_calc[ei][si][mi][0], 
> num_points=self.num_disp_points[ei][si][mi][0])
>
>                      # For all missing data points, set the back-calculated 
> value to the measured values so that it has no effect on the chi-squared 
> value.
>                      for di in range(self.num_disp_points[ei][si][mi][0]):
>
>
> _______________________________________________
> relax (http://www.nmr-relax.com)
>
> This is the relax-commits mailing list
> [email protected]
>
> 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-commits

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

This is the relax-devel mailing list
[email protected]

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

Reply via email to