Author: tlinnet Date: Fri Jan 16 23:19:47 2015 New Revision: 27202 URL: http://svn.gna.org/viewcvs/relax?rev=27202&view=rev Log: Implemented target function for relaxation dispersion, which calculate the sum of squares of residuals and the standard deviation of these. Task #7882 (https://gna.org/task/?7882): Implement Monte-Carlo simulation, where errors are generated with width of standard deviation or residuals. Modified: trunk/target_functions/relax_disp.py Modified: trunk/target_functions/relax_disp.py URL: http://svn.gna.org/viewcvs/relax/trunk/target_functions/relax_disp.py?rev=27202&r1=27201&r2=27202&view=diff ============================================================================== --- trunk/target_functions/relax_disp.py (original) +++ trunk/target_functions/relax_disp.py Fri Jan 16 23:19:47 2015 @@ -26,7 +26,7 @@ # Python module imports. from copy import deepcopy -from numpy import all, arctan2, cos, dot, float64, int16, isfinite, max, multiply, ones, rollaxis, pi, sin, sum, version, zeros +from numpy import all, arctan2, cos, dot, float64, int16, isfinite, max, multiply, ones, rollaxis, pi, sin, sqrt, sum, version, zeros from numpy.ma import masked_equal # relax module imports. @@ -2193,3 +2193,26 @@ return back_calc_return + + def get_sum_of_squares(self): + """Class function to return sum of squares, the sum of residuals between fitted values and measured values. This is not taking weights into account. Also return the standard deviation of these values. + + @return: sum of squares of residual, standard deviation of sum of squares. + @rtype: float, float + """ + + # Get the measured values, and the fitted values. + measured = self.values + fitted = self.back_calc + + # Calculate the sum of squares between fitted and measured values. + sos = sum((measured-fitted)**2) + + # Calculate the degrees of freedom + dof = sum(self.disp_struct) - self.num_params + + # Calculate the standard deviation of the sum of squares. + std_sos = sqrt(sos / dof) + + return sos, std_sos +