Changeset 6d20b46 in sasview for park_integration/ScipyFitting.py


Ignore:
Timestamp:
Jan 20, 2010 3:54:52 PM (14 years ago)
Author:
Gervaise Alina <gervyh@…>
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:
662da312
Parents:
e6b9723
Message:

working on thread issues [incomplete]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • park_integration/ScipyFitting.py

    rfd6b789 r6d20b46  
    5656            with Uid as keys 
    5757        """ 
    58         self.fitArrangeDict={} 
    59         self.paramList=[] 
     58        self.fitArrangeDict = {} 
     59        self.paramList = [] 
    6060    #def fit(self, *args, **kw): 
    6161    #    return profile(self._fit, *args, **kw) 
    62  
    63     def fit(self ,q=None,handler=None,curr_thread= None): 
    64         
    65         fitproblem=[] 
    66         for id ,fproblem in self.fitArrangeDict.iteritems(): 
    67             if fproblem.get_to_fit()==1: 
    68                 fitproblem.append(fproblem) 
    69         if len(fitproblem)>1 :  
     62    def createFunctor(self): 
     63        fitproblem=None 
     64        fit_count = 0  
     65        #print " self.fitArrangeDict", self.fitArrangeDict 
     66        for id, fproblem in self.fitArrangeDict.iteritems(): 
     67            if fproblem.get_to_fit() == 1: 
     68                fitproblem = fproblem 
     69                fit_count += 1 
     70        if fit_count > 1 :  
    7071            raise RuntimeError, "Scipy can't fit more than a single fit problem at a time." 
    7172            return 
    72         elif len(fitproblem)==0 :  
     73        elif fit_count == 0 :  
    7374            raise RuntimeError, "No Assembly scheduled for Scipy fitting." 
    7475            return 
    7576     
    76         listdata=[] 
    77         model = fitproblem[0].get_model() 
    78         listdata = fitproblem[0].get_data() 
     77        listdata = [] 
     78        model = fitproblem.get_model().clone() 
     79        data = fitproblem.get_data() 
     80         
    7981        # Concatenate dList set (contains one or more data)before fitting 
    8082        #data=self._concatenateData( listdata) 
    81         data=listdata 
    82         self.curr_thread= curr_thread 
     83        #data = listdata 
     84        #self.curr_thread= curr_thread 
    8385 
    8486        #try: 
    85         functor= SansAssembly(self.paramList,model,data, curr_thread= self.curr_thread) 
    86         out, cov_x, info, mesg, success = optimize.leastsq(functor,model.getParams(self.paramList), full_output=1, warning=True) 
     87        functor = SansAssembly(self.paramList, model, data)#, curr_thread= curr_thread) 
     88        return functor , model 
     89 
     90    def fit(self, q=None, handler=None, curr_thread=None): 
     91         
     92        functor , model = self.createFunctor() 
     93         
     94        out, cov_x, info, mesg, success = optimize.leastsq(functor, 
     95                                                model.getParams(self.paramList),  
     96                                                full_output=1, warning=True) 
    8797         
    8898        chisqr = functor.chisq(out) 
     
    98108                result.pvec = out 
    99109                result.success = success 
    100                 if q !=None: 
     110                if q is not None: 
    101111                    print "went here" 
    102112                    q.put(result) 
     
    105115                return result 
    106116        else:   
    107             raise ValueError, "SVD did not converge"+str(success) 
     117            raise ValueError, "SVD did not converge" + str(success) 
    108118        #except FitAbort: 
    109119            ## fit engine is stop 
Note: See TracChangeset for help on using the changeset viewer.