Author: bugman Date: Thu May 22 00:02:56 2008 New Revision: 6228 URL: http://svn.gna.org/viewcvs/relax?rev=6228&view=rev Log: Updated the error_analysis() function to the new design. Modified: 1.3/generic_fns/monte_carlo.py Modified: 1.3/generic_fns/monte_carlo.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/monte_carlo.py?rev=6228&r1=6227&r2=6228&view=diff ============================================================================== --- 1.3/generic_fns/monte_carlo.py (original) +++ 1.3/generic_fns/monte_carlo.py Thu May 22 00:02:56 2008 @@ -104,33 +104,39 @@ pack_sim_data(spin, random) -def error_analysis(run=None, prune=0.0): +def error_analysis(prune=0.0): """Function for calculating errors from the Monte Carlo simulations. The standard deviation formula used to calculate the errors is the square root of the - bias-corrected variance, given by the formula: - - ____________________________ + bias-corrected variance, given by the formula:: + + __________________________ / 1 - sd = / ----- * sum({Xi - Xav}^2)] + sd = / ----- * sum({Xi - Xav}^2) \/ n - 1 - where: - n is the total number of simulations. - Xi is the parameter value for simulation i. - Xav is the mean parameter value for all simulations. + where + - n is the total number of simulations. + - Xi is the parameter value for simulation i. + - Xav is the mean parameter value for all simulations. + + + @keyword prune: The amount to prune the upper and lower tails the distribution. If set to + 0.0, no simulations will be pruned. If set to 1.0, all simulations will be + pruned. This argument should be set 0.0 to avoid meaningless statistics. + @type prune: float """ - # Arguments. - self.run = run - - # Test if the run exists. - if not self.run in relax_data_store.run_names: - raise RelaxNoPipeError, self.run - - # Test if simulations have been set up. - if not hasattr(relax_data_store, 'sim_state'): - raise RelaxError, "Monte Carlo simulations for the run " + `self.run` + " have not been set up." + # Test if the current data pipe exists. + if not relax_data_store.current_pipe: + raise RelaxNoPipeError + + # Alias the current data pipe. + cdp = relax_data_store[relax_data_store.current_pipe] + + # Test if simulations have been set up. + if not hasattr(cdp, 'sim_state'): + raise RelaxError, "Monte Carlo simulations have not been set up." # Specific number of instances, return simulation chi2 array, return selected simulation array, return simulation parameter array, and set error functions. count_num_instances = get_specific_fn('num_instances', cdp.pipe_type) @@ -141,20 +147,20 @@ set_error = get_specific_fn('set_error', cdp.pipe_type) # Count the number of instances. - num_instances = count_num_instances(self.run) + num_instances = count_num_instances() # Loop over the instances. for instance in xrange(num_instances): # Get the selected simulation array. - select_sim = return_selected_sim(self.run, instance) - - # Initialise an array of indecies to prune (an empty array means no prunning). + select_sim = return_selected_sim(instance) + + # Initialise an array of indecies to prune (an empty array means no pruning). indecies_to_skip = [] # Pruning. if prune > 0.0: # Get the array of simulation chi-squared values. - chi2_array = return_sim_chi2(self.run, instance) + chi2_array = return_sim_chi2(instance) # The total number of simulations. n = len(chi2_array) @@ -178,7 +184,7 @@ index = 0 while 1: # Get the array of simulation parameters for the index. - param_array = return_sim_param(self.run, instance, index) + param_array = return_sim_param(instance, index) # Break (no more parameters). if param_array == None: @@ -245,7 +251,7 @@ sd = None # Set the parameter error. - set_error(self.run, instance, index, sd) + set_error(instance, index, sd) # Increment the parameter index. index = index + 1