Changeset b2f25dc5 in sasview for park_integration
- Timestamp:
- Oct 20, 2010 6:53:49 PM (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:
- 67e258c
- Parents:
- d2539aa
- Location:
- park_integration
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
park_integration/AbstractFitEngine.py
r89f3b66 rb2f25dc5 9 9 from DataLoader.data_info import Data2D 10 10 11 12 11 13 class SansParameter(park.Parameter): 12 14 """ … … 62 64 63 65 return lo, hi 66 67 def get_name(self): 68 """ 69 """ 70 return self._getname() 64 71 65 72 def _setrange(self, r): … … 446 453 """ 447 454 #List of parameter names to fit 448 self.param List=[]455 self.param_list = [] 449 456 #Dictionnary of fitArrange element (fit problems) 450 self.fit ArrangeDict={}457 self.fit_arrange_dict = {} 451 458 452 459 def _concatenateData(self, listdata=[]): … … 550 557 if item in new_model.model.getParamList(): 551 558 temp.append(item) 552 self.param List.append(item)559 self.param_list.append(item) 553 560 else: 554 561 … … 560 567 561 568 #A fitArrange is already created but contains dList only at Uid 562 if self.fit ArrangeDict.has_key(Uid):563 self.fit ArrangeDict[Uid].set_model(new_model)564 self.fit ArrangeDict[Uid].pars = pars569 if self.fit_arrange_dict.has_key(Uid): 570 self.fit_arrange_dict[Uid].set_model(new_model) 571 self.fit_arrange_dict[Uid].pars = pars 565 572 else: 566 573 #no fitArrange object has been create with this Uid … … 568 575 fitproblem.set_model(new_model) 569 576 fitproblem.pars = pars 570 self.fit ArrangeDict[Uid] = fitproblem577 self.fit_arrange_dict[Uid] = fitproblem 571 578 572 579 else: … … 592 599 fitdata.setFitRange(qmin=qmin, qmax=qmax) 593 600 #A fitArrange is already created but contains model only at Uid 594 if self.fit ArrangeDict.has_key(Uid):595 self.fit ArrangeDict[Uid].add_data(fitdata)601 if self.fit_arrange_dict.has_key(Uid): 602 self.fit_arrange_dict[Uid].add_data(fitdata) 596 603 else: 597 604 #no fitArrange object has been create with this Uid 598 605 fitproblem = FitArrange() 599 606 fitproblem.add_data(fitdata) 600 self.fit ArrangeDict[Uid] = fitproblem607 self.fit_arrange_dict[Uid] = fitproblem 601 608 602 609 def get_model(self, Uid): … … 609 616 610 617 """ 611 if self.fit ArrangeDict.has_key(Uid):612 return self.fit ArrangeDict[Uid].get_model()618 if self.fit_arrange_dict.has_key(Uid): 619 return self.fit_arrange_dict[Uid].get_model() 613 620 else: 614 621 return None … … 616 623 def remove_Fit_Problem(self, Uid): 617 624 """remove fitarrange in Uid""" 618 if self.fit ArrangeDict.has_key(Uid):619 del self.fit ArrangeDict[Uid]625 if self.fit_arrange_dict.has_key(Uid): 626 del self.fit_arrange_dict[Uid] 620 627 621 628 def select_problem_for_fit(self, Uid, value): … … 628 635 629 636 """ 630 if self.fit ArrangeDict.has_key(Uid):631 self.fit ArrangeDict[Uid].set_to_fit(value)637 if self.fit_arrange_dict.has_key(Uid): 638 self.fit_arrange_dict[Uid].set_to_fit(value) 632 639 633 640 def get_problem_to_fit(self, Uid): … … 638 645 639 646 """ 640 if self.fit ArrangeDict.has_key(Uid):641 self.fit ArrangeDict[Uid].get_to_fit()647 if self.fit_arrange_dict.has_key(Uid): 648 self.fit_arrange_dict[Uid].get_to_fit() 642 649 643 650 class FitArrange: -
park_integration/ParkFitting.py
r89f3b66 rb2f25dc5 4 4 """ 5 5 ParkFitting module contains SansParameter,Model,Data 6 FitArrange, ParkFit,Parameter classes.All listed classes work together to perform a7 simple fit with park optimizer.6 FitArrange, ParkFit,Parameter classes.All listed classes work together 7 to perform a simple fit with park optimizer. 8 8 """ 9 9 #import time 10 10 #import numpy 11 import park 12 from park import fit, fitresult 13 from park import assembly 14 from park.fitmc import FitSimplex, FitMC 11 #import park 12 from park import fit 13 from park import fitresult 14 from park.assembly import Assembly 15 from park.fitmc import FitSimplex 16 from park.fitmc import FitMC 15 17 16 18 #from Loader import Load 17 from AbstractFitEngine import FitEngine19 from sans.fit.AbstractFitEngine import FitEngine 18 20 19 21 … … 36 38 engine.set_param( model,"M1", {'A':2,'B':4}) 37 39 38 Add model with a dictionnary of FitArrangeList{} where Uid is a key and model 40 Add model with a dictionnary of FitArrangeList{} where Uid is a key 41 and model 39 42 is save in FitArrange object. 40 43 engine.set_model(model,Uid) … … 52 55 with Uid as keys 53 56 """ 54 self.fitArrangeDict = {} 55 self.paramList = [] 57 FitEngine.__init__(self) 58 self.fit_arrange_dict = {} 59 self.param_list = [] 56 60 57 def create Assembly(self):61 def create_assembly(self): 58 62 """ 59 Extract sansmodel and sansdata from self.FitArrangelist ={Uid:FitArrange} 60 Create parkmodel and park data ,form a list couple of parkmodel and parkdata 63 Extract sansmodel and sansdata from 64 self.FitArrangelist ={Uid:FitArrange} 65 Create parkmodel and park data ,form a list couple of parkmodel 66 and parkdata 61 67 create an assembly self.problem= park.Assembly([(parkmodel,parkdata)]) 62 68 """ 63 69 mylist = [] 64 listmodel = []65 i = 070 #listmodel = [] 71 #i = 0 66 72 fitproblems = [] 67 for id,fproblem in self.fitArrangeDict.iteritems():73 for fproblem in self.fit_arrange_dict.itervalues(): 68 74 if fproblem.get_to_fit() == 1: 69 75 fitproblems.append(fproblem) … … 76 82 ## does not allow status change for constraint parameters 77 83 if p.status != 'computed': 78 if p._getname()in item.pars: 79 ## make parameters selected for fit will be between boundaries 84 if p.get_name()in item.pars: 85 ## make parameters selected for 86 #fit will be between boundaries 80 87 p.set(p.range) 81 88 else: 82 89 p.status = 'fixed' 83 i += 184 Ldata= item.get_data()90 #i += 1 91 data_list = item.get_data() 85 92 #parkdata=self._concatenateData(Ldata) 86 parkdata = Ldata93 parkdata = data_list 87 94 fitness = (parkmodel, parkdata) 88 95 mylist.append(fitness) 89 self.problem = park.Assembly(mylist)96 self.problem = Assembly(mylist) 90 97 91 98 def fit(self, q=None, handler=None, curr_thread=None): … … 93 100 Performs fit with park.fit module.It can perform fit with one model 94 101 and a set of data, more than two fit of one model and sets of data or 95 fit with more than two model associated with their set of data and constraints 102 fit with more than two model associated with their set of data and 103 constraints 96 104 97 :param pars: Dictionary of parameter names for the model and their values. 105 :param pars: Dictionary of parameter names for the model and their 106 values. 98 107 :param qmin: The minimum value of data's range to be fit 99 108 :param qmax: The maximum value of data's range to be fit 100 109 101 :note: all parameter are ignored most of the time.Are just there to keep ScipyFit102 and ParkFit interface the same.110 :note: all parameter are ignored most of the time.Are just there 111 to keep ScipyFit and ParkFit interface the same. 103 112 104 113 :return: result.fitness Value of the goodness of fit metric 105 :return: result.pvec list of parameter with the best value found during fitting 114 :return: result.pvec list of parameter with the best value 115 found during fitting 106 116 :return: result.cov Covariance matrix 107 117 108 118 """ 109 self.create Assembly()119 self.create_assembly() 110 120 localfit = FitSimplex() 111 121 localfit.ftol = 1e-8 -
park_integration/ScipyFitting.py
r89f3b66 rb2f25dc5 10 10 from scipy import optimize 11 11 12 from AbstractFitEngine import FitEngine, SansAssembly, FitAbort 12 from sans.fit.AbstractFitEngine import FitEngine 13 from sans.fit.AbstractFitEngine import SansAssembly 14 from sans.fit.AbstractFitEngine import FitAbort 13 15 14 16 class fitresult(object): … … 28 30 self.parameters = None 29 31 self.model = model 30 self.param List = paramList32 self.param_list = paramList 31 33 32 34 def set_model(self, model): … … 43 45 """ 44 46 """ 45 if self.pvec == None and self.model is None and self.param List is None:47 if self.pvec == None and self.model is None and self.param_list is None: 46 48 return "No results" 47 49 n = len(self.model.parameterset) … … 49 51 result_param = zip(xrange(n), self.model.parameterset) 50 52 L = ["P%-3d %s......|.....%s"%(p[0], p[1], p[1].value)\ 51 for p in result_param if p[1].name in self.param List]53 for p in result_param if p[1].name in self.param_list] 52 54 L.append("=== goodness of fit: %s" % (str(self.fitness))) 53 55 return "\n".join(L) … … 87 89 def __init__(self): 88 90 """ 89 Creates a dictionary (self.fit ArrangeDict={})of FitArrange elements91 Creates a dictionary (self.fit_arrange_dict={})of FitArrange elements 90 92 with Uid as keys 91 93 """ 92 self.fitArrangeDict = {} 93 self.paramList = [] 94 FitEngine.__init__(self) 95 self.fit_arrange_dict = {} 96 self.param_list = [] 94 97 #def fit(self, *args, **kw): 95 98 # return profile(self._fit, *args, **kw) … … 99 102 """ 100 103 fitproblem = [] 101 for id, fproblem in self.fit ArrangeDict.iteritems():104 for id, fproblem in self.fit_arrange_dict.iteritems(): 102 105 if fproblem.get_to_fit() == 1: 103 106 fitproblem.append(fproblem) … … 116 119 data = listdata 117 120 self.curr_thread = curr_thread 118 result = fitresult(model=model, paramList=self.param List)121 result = fitresult(model=model, paramList=self.param_list) 119 122 if handler is not None: 120 123 handler.set_result(result=result) 121 124 #try: 122 functor = SansAssembly(self.param List, model, data, handler=handler,125 functor = SansAssembly(self.param_list, model, data, handler=handler, 123 126 fitresult=result, curr_thread= self.curr_thread) 124 127 125 128 126 129 out, cov_x, info, mesg, success = optimize.leastsq(functor, 127 model.getParams(self.param List),130 model.getParams(self.param_list), 128 131 full_output=1, warning=True) 129 132
Note: See TracChangeset
for help on using the changeset viewer.