Author: tlinnet Date: Sun Jun 8 13:14:36 2014 New Revision: 23729 URL: http://svn.gna.org/viewcvs/relax?rev=23729&view=rev Log: Removing looping over exp and offset indicies in calc_chi2. They are always 0 anyway. This brings a little speed. Task #7807 (https://gna.org/task/index.php?7807): Speed-up of dispersion models for Clustered analysis. ---- Profiling. 1000 iterations 100 spins 3 sfrq ('sfrq: ', 600000000.0, 'number of cpmg frq', 15, array([ 2., 6., 10., 14., 18., 22., 26., 30., 34., 38., 42., 46., 50., 54., 58.])) ('sfrq: ', 800000000.0, 'number of cpmg frq', 20, array([ 2., 6., 10., 14., 18., 22., 26., 30., 34., 38., 42., 46., 50., 54., 58., 62., 66., 70., 74., 78.])) ('sfrq: ', 900000000.0, 'number of cpmg frq', 22, array([ 2., 6., 10., 14., 18., 22., 26., 30., 34., 38., 42., 46., 50., 54., 58., 62., 66., 70., 74., 78., 82., 86.])) ('chi2 cluster:', 0.0) TRUNK ncalls tottime percall cumtime percall filename:lineno(function) 1000 5.221 0.005 53.578 0.054 relax_disp.py:456(calc_CR72_chi2) BEFORE ncalls tottime percall cumtime percall filename:lineno(function) 1000 14.871 0.015 43.084 0.043 relax_disp.py:494(calc_CR72_chi2) AFTER removing looping over exp and offset indicies. They are always 0. ncalls tottime percall cumtime percall filename:lineno(function) 1000 12.831 0.013 38.248 0.038 relax_disp.py:494(calc_CR72_chi2) Modified: branches/disp_spin_speed/target_functions/relax_disp.py Modified: branches/disp_spin_speed/target_functions/relax_disp.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/target_functions/relax_disp.py?rev=23729&r1=23728&r2=23729&view=diff ============================================================================== --- branches/disp_spin_speed/target_functions/relax_disp.py (original) +++ branches/disp_spin_speed/target_functions/relax_disp.py Sun Jun 8 13:14:36 2014 @@ -508,33 +508,29 @@ @rtype: float """ - # Loop over the experiment types. - for ei in range(self.num_exp): - # Loop over the spins. - for si in range(self.num_spins): - # Loop over the spectrometer frequencies. - for mi in range(self.num_frq): - # Loop over the offsets. - for oi in range(self.num_offsets[ei][si][mi]): - # Extract number of dispersion points. - num_disp_points = self.num_disp_points[ei][si][mi][oi] - - # The R20 index. - r20_index = mi + si*self.num_frq - - # Store r20a and r20b values per disp point. - self.R20A_a[ei][si][mi][oi] = np.array( [R20A[r20_index]] * self.max_num_disp_points, float64) - self.R20B_a[ei][si][mi][oi] = np.array( [R20B[r20_index]] * self.max_num_disp_points, float64) - - # Convert dw from ppm to rad/s. - dw_frq = dw[si] * self.frqs[ei][si][mi] - - # Store dw_frq per disp point. - self.dw_frq_a[ei][si][mi][oi] = np.array( [dw_frq] * self.max_num_disp_points, float64) - - # Store pA and kex per disp point. - self.pA_a[ei][si][mi][oi] = np.array( [pA] * self.max_num_disp_points, float64) - self.kex_a[ei][si][mi][oi] = np.array( [kex] * self.max_num_disp_points, float64) + # Loop over the spins. + for si in range(self.num_spins): + # Loop over the spectrometer frequencies. + for mi in range(self.num_frq): + # Extract number of dispersion points. + num_disp_points = self.num_disp_points[0][si][mi][0] + + # The R20 index. + r20_index = mi + si*self.num_frq + + # Store r20a and r20b values per disp point. + self.R20A_a[0][si][mi][0] = np.array( [R20A[r20_index]] * self.max_num_disp_points, float64) + self.R20B_a[0][si][mi][0] = np.array( [R20B[r20_index]] * self.max_num_disp_points, float64) + + # Convert dw from ppm to rad/s. + dw_frq = dw[si] * self.frqs[0][si][mi] + + # Store dw_frq per disp point. + self.dw_frq_a[0][si][mi][0] = np.array( [dw_frq] * self.max_num_disp_points, float64) + + # Store pA and kex per disp point. + self.pA_a[0][si][mi][0] = np.array( [pA] * self.max_num_disp_points, float64) + self.kex_a[0][si][mi][0] = np.array( [kex] * self.max_num_disp_points, float64) ## Back calculate the R2eff values. r2eff_CR72(r20a=self.R20A_a, r20b=self.R20B_a, pA=self.pA_a, dw=self.dw_frq_a, kex=self.kex_a, cpmg_frqs=self.cpmg_frqs_a, back_calc=self.back_calc_a, num_points=self.num_disp_points_a) @@ -544,26 +540,22 @@ # Now return the values back to the structure of self.back_calc object. ## 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. - # Loop over the experiment types. - for ei in range(self.num_exp): - # Loop over the spins. - for si in range(self.num_spins): - # Loop over the spectrometer frequencies. - for mi in range(self.num_frq): - # Loop over the offsets. - for oi in range(self.num_offsets[ei][si][mi]): - # Extract number of dispersion points. - num_disp_points = self.num_disp_points[ei][si][mi][oi] - - self.back_calc[ei][si][mi][oi] = self.back_calc_a[ei][si][mi][oi][:num_disp_points] - - - for di in range(self.num_disp_points[ei][si][mi][oi]): - if self.missing[ei][si][mi][oi][di]: - self.back_calc[ei][si][mi][oi][di] = self.values[ei][si][mi][oi][di] - - ## Calculate and return the chi-squared value. - chi2_sum += chi2(self.values[ei][si][mi][oi], self.back_calc[ei][si][mi][oi], self.errors[ei][si][mi][oi]) + # Loop over the spins. + for si in range(self.num_spins): + # Loop over the spectrometer frequencies. + for mi in range(self.num_frq): + # Extract number of dispersion points. + num_disp_points = self.num_disp_points[0][si][mi][0] + + self.back_calc[0][si][mi][0] = self.back_calc_a[0][si][mi][0][:num_disp_points] + + + for di in range(self.num_disp_points[0][si][mi][0]): + if self.missing[0][si][mi][0][di]: + self.back_calc[0][si][mi][0][di] = self.values[0][si][mi][0][di] + + ## Calculate and return the chi-squared value. + chi2_sum += chi2(self.values[0][si][mi][0], self.back_calc[0][si][mi][0], self.errors[0][si][mi][0]) # Return the total chi-squared value. return chi2_sum