Author: bugman Date: Wed Jul 19 10:06:58 2006 New Revision: 2516 URL: http://svn.gna.org/viewcvs/relax?rev=2516&view=rev Log: Finally, a real fix to bug #5746. The bug report is located at https://gna.org/bugs/?func=detailitem&item_id=5746 and is discussed in the thread starting at https://mail.gna.org/public/relax-devel/2006-04/msg00018.html. The fix follows from an idea in the post located at https://mail.gna.org/public/relax-devel/2006-04/msg00021.html. Firstly the model-free calculate() function was modified so that when self.param_set is equal to 'all' or 'diff' (global statistics) then the chi-squared value calculated is summed and placed in the global data structure self.relax.data.chi2 rather than the residue specific data structure. This change allowed the 'combined' flag to be eliminated from the self.model_statistics() function of 'specific_fns/model_free.py'. This flag was the source of all the problems and it's removal allowed chunks of obscure code to be axed. The statistics only need to refer to the self.param_set value to determine which stats should be returned. Modified: 1.2/generic_fns/model_selection.py 1.2/specific_fns/hybrid.py 1.2/specific_fns/model_free.py Modified: 1.2/generic_fns/model_selection.py URL: http://svn.gna.org/viewcvs/relax/1.2/generic_fns/model_selection.py?rev=2516&r1=2515&r2=2516&view=diff ============================================================================== --- 1.2/generic_fns/model_selection.py (original) +++ 1.2/generic_fns/model_selection.py Wed Jul 19 10:06:58 2006 @@ -185,7 +185,7 @@ continue # Get the model statistics. - k, n, chi2 = self.model_statistics[run](run=run, instance=i, min_instances=self.min_instances, num_instances=self.num_instances[j][k]) + k, n, chi2 = self.model_statistics[run](run=run, instance=i, min_instances=self.min_instances) # Missing data sets. if k == None or n == None or chi2 == None: @@ -207,7 +207,7 @@ continue # Get the model statistics. - k, n, chi2 = self.model_statistics[run](run=run, instance=i, min_instances=self.min_instances, num_instances=self.num_instances[j]) + k, n, chi2 = self.model_statistics[run](run=run, instance=i, min_instances=self.min_instances) # Missing data sets. if k == None or n == None or chi2 == None: Modified: 1.2/specific_fns/hybrid.py URL: http://svn.gna.org/viewcvs/relax/1.2/specific_fns/hybrid.py?rev=2516&r1=2515&r2=2516&view=diff ============================================================================== --- 1.2/specific_fns/hybrid.py (original) +++ 1.2/specific_fns/hybrid.py Wed Jul 19 10:06:58 2006 @@ -89,7 +89,7 @@ self.relax.data.hybrid_runs[hybrid] = runs - def model_statistics(self, run=None, instance=None, min_instances=None, num_instances=None): + def model_statistics(self, run=None, instance=None, min_instances=None): """Function for returning the values k, n, and chi2 of the hybrid. k - number of parameters. @@ -112,15 +112,11 @@ # Specific model statistics and number of instances functions. model_statistics = self.relax.specific_setup.setup('model_stats', function_type) - num_instances = self.relax.specific_setup.setup('num_instances', function_type) - - # Number of instances. - num = num_instances(run) # Loop over the instances. for i in xrange(num): # Get the statistics. - k, n, chi2 = model_statistics(run, instance=i, num_instances=num) + k, n, chi2 = model_statistics(run, instance=i) # Bad stats. if k == None or n == None or chi2 == None: Modified: 1.2/specific_fns/model_free.py URL: http://svn.gna.org/viewcvs/relax/1.2/specific_fns/model_free.py?rev=2516&r1=2515&r2=2516&view=diff ============================================================================== --- 1.2/specific_fns/model_free.py (original) +++ 1.2/specific_fns/model_free.py Wed Jul 19 10:06:58 2006 @@ -543,9 +543,15 @@ # Chi-squared calculation. try: - self.relax.data.res[self.run][i].chi2 = self.mf.func(self.param_vector) + chi2 = self.mf.func(self.param_vector) except OverflowError: - self.relax.data.res[self.run][i].chi2 = 1e200 + chi2 = 1e200 + + # Global chi-squared value. + if self.param_set == 'all' or self.param_set == 'diff': + self.relax.data.chi2[self.run] = self.relax.data.chi2[self.run] + chi2 + else: + self.relax.data.res[self.run][i].chi2 = chi2 def copy(self, run1=None, run2=None, sim=None): @@ -2487,7 +2493,7 @@ self.relax.data.res[run][i].params = params - def model_statistics(self, run=None, instance=None, min_instances=None, num_instances=None): + def model_statistics(self, run=None, instance=None, min_instances=None): """Function for returning k, n, and chi2. k - number of parameters. @@ -2497,11 +2503,6 @@ # Arguments. self.run = run - - # All residues. - combine = 0 - if min_instances == 1 and min_instances != num_instances: - combine = 1 # Determine if local or global statistics will be returned. global_stats = 1 @@ -2513,9 +2514,8 @@ # Determine the parameter set type. self.param_set = self.determine_param_set_type() - # Sequence specific data. # Statistics for a single residue. - if not global_stats and not combine: + if not global_stats: # Skip unselected residues. if not self.relax.data.res[self.run][instance].select: return None, None, None @@ -2534,34 +2534,7 @@ # The chi2 value. chi2 = self.relax.data.res[self.run][instance].chi2 - # Statistics for all residues combined. - elif not global_stats and combine: - # Initialise. - k = 0 - n = 0 - chi2 = 0 - - # Loop over the sequence. - for i in xrange(len(self.relax.data.res[self.run])): - # Skip unselected residues. - if not self.relax.data.res[self.run][i].select: - continue - - # Skip residues with no relaxation data. - if not hasattr(self.relax.data.res[self.run][i], 'relax_data') or not len(self.relax.data.res[self.run][i].relax_data): - continue - - # Count the number of parameters. - self.param_vector = self.assemble_param_vector(index=i) - k = k + len(self.param_vector) - - # Count the number of data points. - n = n + len(self.relax.data.res[self.run][i].relax_data) - - # The chi2 value. - chi2 = chi2 + self.relax.data.res[self.run][i].chi2 - - # Other data. + # Global stats. elif global_stats: # Count the number of parameters. self.param_vector = self.assemble_param_vector()