Changeset ca6d914 in sasview for park_integration/ScipyFitting.py


Ignore:
Timestamp:
Sep 16, 2008 4:34:55 PM (16 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:
fadea71
Parents:
3b19ac9
Message:

some bugs fixed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • park_integration/ScipyFitting.py

    r48882d1 rca6d914  
    3535        Use a sans model 
    3636         
    37         Add data with a dictionnary of FitArrangeList where Uid is a key and data 
     37        Add data with a dictionnary of FitArrangeDict where Uid is a key and data 
    3838        is saved in FitArrange object. 
    3939        engine.set_data(data,Uid) 
     
    4545        engine.set_param( model,"M1", {'A':2,'B':4}) 
    4646         
    47         Add model with a dictionnary of FitArrangeList{} where Uid is a key and model 
     47        Add model with a dictionnary of FitArrangeDict{} where Uid is a key and model 
    4848        is save in FitArrange object. 
    4949        engine.set_model(model,Uid) 
     
    5454    def __init__(self): 
    5555        """ 
    56             Creates a dictionary (self.fitArrangeList={})of FitArrange elements 
     56            Creates a dictionary (self.fitArrangeDict={})of FitArrange elements 
    5757            with Uid as keys 
    5858        """ 
    59         self.fitArrangeList={} 
     59        self.fitArrangeDict={} 
    6060        self.paramList=[] 
    6161    def fit(self,qmin=None, qmax=None): 
    6262         # Protect against simultanous fitting attempts 
    63         if len(self.fitArrangeList)>1:  
     63        if len(self.fitArrangeDict)>1:  
    6464            raise RuntimeError, "Scipy can't fit more than a single fit problem at a time." 
    6565         
    6666        # fitproblem contains first fitArrange object(one model and a list of data) 
    67         fitproblem=self.fitArrangeList.values()[0] 
     67        fitproblem=self.fitArrangeDict.values()[0] 
    6868        listdata=[] 
    6969        model = fitproblem.get_model() 
     
    7777            qmax= max(data.x)  
    7878        functor= sansAssembly(model,data) 
    79         print "scipyfitting:param list",model.getParams(self.paramList) 
    80         print "scipyfitting:functor",functor(model.getParams(self.paramList)) 
    81      
     79        
    8280        out, cov_x, info, mesg, success = optimize.leastsq(functor,model.getParams(self.paramList), full_output=1, warning=True) 
    8381        chisqr = functor.chisq(out) 
     82        if cov_x is not None and numpy.isfinite(cov_x).all(): 
     83            stderr = numpy.sqrt(numpy.diag(cov_x)) 
    8484         
    85         print "scipyfitting: info",mesg 
    86         print"scipyfitting : success",success 
    87         print "scipyfitting: out", out 
    88         print "scipyfitting: cov_x", cov_x 
    89         print "scipyfitting: chisqr", chisqr 
    90          
    91         if not (numpy.isnan(out).any()): 
     85        if not (numpy.isnan(out).any()) or ( cov_x !=None) : 
    9286                result = fitresult() 
    9387                result.fitness = chisqr 
    94                 result.cov  = cov_x 
    95                  
     88                result.stderr  = stderr 
    9689                result.pvec = out 
    9790                result.success =success 
     
    9992                return result 
    10093        else:   
    101             raise ValueError, "SVD did not converge" 
     94            raise ValueError, "SVD did not converge"+str(success) 
    10295         
    10396        
Note: See TracChangeset for help on using the changeset viewer.