Changeset ed4aef2 in sasview for src/sans/fit/BumpsFitting.py


Ignore:
Timestamp:
May 6, 2014 9:34:46 AM (10 years ago)
Author:
pkienzle
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
f121904
Parents:
644ca73
Message:

add panel for bumps results

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sans/fit/BumpsFitting.py

    r85f17f6 red4aef2  
    1616        self.handler = handler 
    1717        self.max_step = max_step 
     18 
    1819    def config_history(self, history): 
    1920        history.requires(time=1, value=2, point=1, step=1) 
     21 
    2022    def __call__(self, history): 
    2123        self.handler.progress(history.step[0], self.max_step) 
     
    2325            self.handler.improvement() 
    2426        self.handler.update_fit() 
     27 
     28class ConvergenceMonitor(object): 
     29    """ 
     30    ConvergenceMonitor contains population summary statistics to show progress 
     31    of the fit.  This is a list [ (best, 0%, 25%, 50%, 75%, 100%) ] or 
     32    just a list [ (best, ) ] if population size is 1. 
     33    """ 
     34    def __init__(self): 
     35        self.convergence = [] 
     36 
     37    def config_history(self, history): 
     38        history.requires(value=1, population_values=1) 
     39 
     40    def __call__(self, history): 
     41        best = history.value[0] 
     42        try: 
     43            p = history.population_values[0] 
     44            n,p = len(p), numpy.sort(p) 
     45            QI,Qmid, = int(0.2*n),int(0.5*n) 
     46            self.convergence.append((best, p[0],p[QI],p[Qmid],p[-1-QI],p[-1])) 
     47        except: 
     48            self.convergence.append((best, )) 
    2549 
    2650class SasProblem(object): 
     
    257281            run_bumps(problem, result, ftol, 
    258282                      handler, curr_thread, msg_q) 
    259         else: 
     283        else: # scipy levenburg marquardt 
    260284            problem = SasProblem(param_list=self.param_list, 
    261285                                 model=model.model, 
     
    292316    if 'monitors' not in options: 
    293317        options['monitors'] = [BumpsMonitor(handler, max_steps)] 
     318    options['monitors'] += [ ConvergenceMonitor() ] 
    294319    options['ftol'] = ftol 
    295320    fitdriver = fitters.FitDriver(fitclass, problem=problem, 
     
    312337    result.success = True 
    313338    result.theory = problem.theory 
     339    # For the convergence plot 
     340    pop = numpy.asarray(options['monitors'][-1].convergence) 
     341    result.convergence = 2*pop/problem.dof 
     342    # Bumps uncertainty state 
     343    try: result.uncertainty_state = fitdriver.fitter.state 
     344    except AttributeError: pass 
    314345 
    315346def run_levenburg_marquardt(problem, result, ftol): 
Note: See TracChangeset for help on using the changeset viewer.