Changeset 85f17f6 in sasview


Ignore:
Timestamp:
Apr 11, 2014 3:26:08 PM (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:
499639c
Parents:
042f065
Message:

put progress monitor on bumps

Location:
src/sans
Files:
2 edited

Legend:

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

    r042f065 r85f17f6  
    1111from sans.fit.AbstractFitEngine import FitEngine 
    1212from sans.fit.AbstractFitEngine import FResult 
     13 
     14class BumpsMonitor(object): 
     15    def __init__(self, handler, max_step=0): 
     16        self.handler = handler 
     17        self.max_step = max_step 
     18    def config_history(self, history): 
     19        history.requires(time=1, value=2, point=1, step=1) 
     20    def __call__(self, history): 
     21        self.handler.progress(history.step[0], self.max_step) 
     22        if len(history.step)>1 and history.step[1] > history.step[0]: 
     23            self.handler.improvement() 
     24        self.handler.update_fit() 
    1325 
    1426class SasProblem(object): 
     
    240252 
    241253        if True: # bumps 
    242             def abort_test(): 
    243                 try: curr_thread.isquit() 
    244                 except KeyboardInterrupt: 
    245                     if handler is not None: 
    246                         handler.stop("Fitting: Terminated!!!") 
    247                     return True 
    248                 return False 
    249  
    250254            problem = SasProblem(param_list=self.param_list, 
    251255                                 model=model.model, 
    252256                                 data=data) 
    253             run_bumps(problem, result, ftol, abort_test) 
     257            run_bumps(problem, result, ftol, 
     258                      handler, curr_thread, msg_q) 
    254259        else: 
    255260            problem = SasProblem(param_list=self.param_list, 
     
    263268 
    264269        if handler is not None: 
    265             handler.set_result(result=result) 
    266270            handler.update_fit(last=True) 
    267271        if q is not None: 
     
    272276        return [result] 
    273277 
    274 def run_bumps(problem, result, ftol, abort_test): 
     278def run_bumps(problem, result, ftol, handler, curr_thread, msg_q): 
     279    def abort_test(): 
     280        if curr_thread is None: return False 
     281        try: curr_thread.isquit() 
     282        except KeyboardInterrupt: 
     283            if handler is not None: 
     284                handler.stop("Fitting: Terminated!!!") 
     285            return True 
     286        return False 
     287 
    275288    fitopts = fitters.FIT_OPTIONS[fitters.FIT_DEFAULT] 
    276289    fitclass = fitopts.fitclass 
    277290    options = fitopts.options.copy() 
     291    max_steps = fitopts.options.get('steps', 0) + fitopts.options.get('burn', 0) 
     292    if 'monitors' not in options: 
     293        options['monitors'] = [BumpsMonitor(handler, max_steps)] 
    278294    options['ftol'] = ftol 
    279295    fitdriver = fitters.FitDriver(fitclass, problem=problem, 
     
    297313    result.theory = problem.theory 
    298314 
    299 def run_levenburg_marquardt(model, result, ftol): 
     315def run_levenburg_marquardt(problem, result, ftol): 
    300316    # This import must be here; otherwise it will be confused when more 
    301317    # than one thread exist. 
    302318    from scipy import optimize 
    303319 
    304     out, cov_x, _, mesg, success = optimize.leastsq(model.residuals, 
    305                                                     model.getp(), 
     320    out, cov_x, _, mesg, success = optimize.leastsq(problem.residuals, 
     321                                                    problem.getp(), 
    306322                                                    ftol=ftol, 
    307323                                                    full_output=1) 
     
    310326    else: 
    311327        stderr = [] 
    312     result.fitness = model.chisq() 
     328    result.fitness = problem.chisq() 
    313329    result.stderr  = stderr 
    314330    result.pvec = out 
    315331    result.success = success 
    316     result.theory = model.theory 
    317  
     332    result.theory = problem.theory 
     333 
  • src/sans/perspectives/fitting/console.py

    r6fe5100 r85f17f6  
    8787        Print result object 
    8888        """ 
    89         msg = " \n %s \n" % self.result.__str__() 
     89        msg = " \n %s \n" % str(self.result) 
    9090        wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    9191                      
     
    136136        self.fit_duration += self.elapsed_time 
    137137        str_time = time.strftime("%a, %d %b %Y %H:%M:%S ", time.localtime(t1)) 
    138         UPDATE_INTERVAL = 0.5 
     138        UPDATE_INTERVAL = 5.0 
    139139        u_flag = False 
    140140        if self.fit_duration >= UPDATE_INTERVAL: 
     
    171171                                              type="progress")) 
    172172      
    173     def starting_fit(self): 
     173    def _DEAD_starting_fit(self): 
    174174        """ 
    175175        """ 
Note: See TracChangeset for help on using the changeset viewer.