Hi Troels, Actually, a better name might be chi2_rankN(), as this is for multiple rank rather than multiple dimensions. The rank of A would be len(A.shape), whereas the dimensions for each rank would be A.shape[0], A.shape[1], etc. What do you think? Would you have an idea for a better name? Regards, Edward On 10 June 2014 18:54, <tlinnet@xxxxxxxxxxxxx> wrote:
Author: tlinnet Date: Tue Jun 10 18:54:28 2014 New Revision: 23799 URL: http://svn.gna.org/viewcvs/relax?rev=23799&view=rev Log: Added a multi-dimensional numpy array chi2 value calculation function. Task #7807 (https://gna.org/task/index.php?7807): Speed-up of dispersion models for Clustered analysis. Modified: branches/disp_spin_speed/target_functions/chi2.py Modified: branches/disp_spin_speed/target_functions/chi2.py URL: http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/target_functions/chi2.py?rev=23799&r1=23798&r2=23799&view=diff ============================================================================== --- branches/disp_spin_speed/target_functions/chi2.py (original) +++ branches/disp_spin_speed/target_functions/chi2.py Tue Jun 10 18:54:28 2014 @@ -63,6 +63,46 @@ # Calculate the chi-squared statistic. return sum((1.0 / errors * (data - back_calc_vals))**2, axis=0) + + +# Chi-squared value for multi-dimensional axis. +#################### + + +def chi2_ND(data, back_calc_vals, errors): + """Function to calculate the chi-squared value for multiple numpy array axis. + + The chi-squared equation + ======================== + + The equation is:: + + _n_ + \ (yi - yi(theta)) ** 2 + chi^2(theta) = > --------------------- + /__ sigma_i ** 2 + i=1 + + where + - i is the index over data sets. + - theta is the parameter vector. + - yi are the values of the measured data set. + - yi(theta) are the values of the back calculated data set. + - sigma_i are the values of the error set. + + + @param data: The multi dimensional vectors of yi values. + @type data: numpy multi dimensional array + @param back_calc_vals: The multi dimensional vectors of yi(theta) values. + @type back_calc_vals: numpy multi dimensional array + @param errors: The multi dimensional vectors of sigma_i values. + @type errors: numpy multi dimensional array + @return: The chi-squared value. + @rtype: float + """ + + # Calculate the chi-squared statistic. + return sum((1.0 / errors * (data - back_calc_vals))**2) # Chi-squared gradient. _______________________________________________ relax (http://www.nmr-relax.com) This is the relax-commits mailing list relax-commits@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-commits