Changeset 4b5bd73 in sasview
- Timestamp:
- Mar 29, 2011 9:42:00 AM (14 years ago)
- 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:
- 852354c8
- Parents:
- ecc85443
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/AbstractFitEngine.py
r511c6810 r4b5bd73 8 8 from DataLoader.data_info import Data1D 9 9 from DataLoader.data_info import Data2D 10 11 10 import time 11 _SMALLVALUE = 1.0e-10 12 12 13 13 class SansParameter(park.Parameter): … … 423 423 self.fitresult = fitresult 424 424 self.res = [] 425 self.true_res = [] 425 426 self.func_name = "Functor" 426 427 … … 436 437 """ 437 438 sum = 0 438 for item in self. res:439 for item in self.true_res: 439 440 sum += item * item 440 if len(self. res) == 0:441 if len(self.true_res) == 0: 441 442 return None 442 return sum / len(self. res)443 return sum / len(self.true_res) 443 444 444 445 def __call__(self, params): … … 448 449 :param params: value of parameters to fit 449 450 450 """ 451 self.model.set_params(self.paramlist,params) 452 self.res = self.data.residuals(self.model.eval) 451 """ 452 #import thread 453 self.model.set_params(self.paramlist, params) 454 self.true_res = self.data.residuals(self.model.eval) 455 # check parameters range 456 if self.check_param_range(): 457 # if the param value is outside of the bound 458 # just silent return res = inf 459 return self.res 460 self.res = self.true_res 453 461 if self.fitresult is not None and self.handler is not None: 454 462 self.fitresult.set_model(model=self.model) 463 #fitness = self.chisq(params=params) 455 464 fitness = self.chisq() 456 465 self.fitresult.pvec = params 457 466 self.fitresult.set_fitness(fitness=fitness) 458 467 self.handler.set_result(result=self.fitresult) 459 #self.handler.update_fit() 468 self.handler.update_fit() 469 460 470 if self.curr_thread != None : 461 462 463 464 raise FitAbort,"stop leastsqr optimizer"471 try: 472 self.curr_thread.isquit() 473 except: 474 raise FitAbort,"stop leastsqr optimizer" 465 475 return self.res 476 477 def check_param_range(self): 478 """ 479 Check the lower and upper bound of the parameter value 480 and set res to the inf if the value is outside of the 481 range 482 :limitation: the initial values must be within range. 483 """ 484 485 time.sleep(0.01) 486 is_outofbound = False 487 # loop through the fit parameters 488 for p in self.model.parameterset: 489 param_name = p.get_name() 490 if param_name in self.paramlist: 491 492 # if the range was defined, check the range 493 if numpy.isfinite(p.range[0]): 494 if p.value == 0: 495 # This value works on Scipy 496 # Do not change numbers below 497 value = _SMALLVALUE 498 else: 499 value = p.value 500 # For leastsq, it needs a bit step back from the boundary 501 val = p.range[0] - value * _SMALLVALUE 502 if p.value < val: 503 self.res *= 1e+6 504 505 is_outofbound = True 506 break 507 if numpy.isfinite(p.range[1]): 508 # This value works on Scipy 509 # Do not change numbers below 510 if p.value == 0: 511 value = _SMALLVALUE 512 else: 513 value = p.value 514 # For leastsq, it needs a bit step back from the boundary 515 val = p.range[1] + value * _SMALLVALUE 516 if p.value > val: 517 self.res *= 1e+6 518 is_outofbound = True 519 break 520 521 return is_outofbound 522 466 523 467 524 class FitEngine:
Note: See TracChangeset
for help on using the changeset viewer.