Author: tlinnet Date: Sat Jan 17 17:25:16 2015 New Revision: 27217 URL: http://svn.gna.org/viewcvs/relax?rev=27217&view=rev Log: Adding to back-end of pipe_control.error_analysis(), to modify datapoint as error drawn from the reduced chi2 gauss distribution. Task #7882 (https://gna.org/task/?7882): Implement Monte-Carlo simulation, where errors are generated with width of standard deviation or residuals.): Implement Monte-Carlo simulation, where errors are generated with width of standard deviation or residuals. Modified: trunk/pipe_control/error_analysis.py Modified: trunk/pipe_control/error_analysis.py URL: http://svn.gna.org/viewcvs/relax/trunk/pipe_control/error_analysis.py?rev=27217&r1=27216&r2=27217&view=diff ============================================================================== --- trunk/pipe_control/error_analysis.py (original) +++ trunk/pipe_control/error_analysis.py Sat Jan 17 17:25:16 2015 @@ -72,11 +72,13 @@ index = index + 1 -def monte_carlo_create_data(method=None): +def monte_carlo_create_data(method=None, distribution=None): """Function for creating simulation data. - @keyword method: The type of Monte Carlo simulation to perform. - @type method: str + @keyword method: The type of Monte Carlo simulation to perform. + @type method: str + @keyword distribution: Which gauss distribution to draw errors from. + @type distribution: str """ # Test if the current data pipe exists. @@ -107,6 +109,10 @@ # No data, so skip. if data == None: continue + + # Possible get the errors from reduced chi2 distribution. + if distribution == 'red_chi2': + error_red_chi2 = api.return_error_red_chi2(data_index) # Get the errors. error = api.return_error(data_index) @@ -140,8 +146,21 @@ random[j][id] = None continue - # Gaussian randomisation. - random[j][id] = gauss(data[id], error[id]) + # If errors are drawn from the reduced chi2 distribution. + if distribution == 'red_chi2': + # Gaussian randomisation, centered at 0, with width of reduced chi2 distribution. + g_error = gauss(0.0, error_red_chi2[id]) + + # We need to scale the gauss error, before adding to datapoint. + new_point = data[id] + g_error * error[id] + + # If errors are drawn from measured values. + else: + # Gaussian randomisation, centered at data point, with width of measured error. + new_point = gauss(data[id], error[id]) + + # Assign datapoint the new value. + random[j][id] = new_point # Pack the simulation data. api.sim_pack_data(data_index, random)