Changeset 32dffae4 in sasview for prview/perspectives


Ignore:
Timestamp:
May 8, 2008 7:20:22 PM (16 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
f71287f4
Parents:
4f63160
Message:

Added alpha estimator and help

Location:
prview/perspectives/pr
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • prview/perspectives/pr/inversion_panel.py

    rf3d51f6 r32dffae4  
    150150            self.osc_ctl.SetValue("%-5.2g" % value) 
    151151        elif name=='alpha_estimate': 
    152             self.alpha_estimate_ctl.SetValue("%-5.2g" % value) 
     152            self.alpha_estimate_ctl.SetValue("%-3.1g" % value) 
    153153        elif name=='plotname': 
    154154            self.plot_data.SetValue(str(value)) 
     
    226226        boxsizer2.SetMinSize((320,50)) 
    227227         
     228        explanation  = "P(r) is found by fitting a set of base functions to I(Q). " 
     229        explanation += "The minimization involves a regularization term to ensure " 
     230        explanation += "a smooth P(r). The alpha parameter gives the size of that "   
     231        explanation += "term. The suggested value is the value above which the" 
     232        explanation += "output P(r) will have only one peak." 
     233        label_explain = wx.StaticText(self, -1, explanation, size=(280,80)) 
     234        boxsizer2.Add(label_explain,  wx.LEFT|wx.BOTTOM, 5) 
     235         
     236         
     237         
    228238        label_nfunc = wx.StaticText(self, -1, "Number of terms") 
    229239        label_nfunc.SetMinSize((120,20)) 
     
    233243         
    234244        self.nfunc_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
     245        self.nfunc_ctl.SetToolTipString("Number of terms in the expansion.") 
    235246        self.alpha_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
     247        self.alpha_ctl.SetToolTipString("Control parameter for the size of the regularization term.") 
    236248        self.dmax_ctl  = wx.TextCtrl(self, -1, size=(60,20)) 
     249        self.dmax_ctl.SetToolTipString("Maximum distance between any two points in the system.") 
    237250        self.alpha_estimate_ctl  = wx.TextCtrl(self, -1, size=(60,20)) 
    238251        self.alpha_estimate_ctl.Enable(False) 
     252        self.alpha_estimate_ctl.SetToolTipString("Value of alpha below which P(r) may have multiple peaks.") 
    239253         
    240254        # EVT_TEXT would trigger an event for each character entered 
     
    247261 
    248262        iy = 0 
    249         sizer_params.Add(label_sugg, (iy,2), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    250         iy += 1 
    251         sizer_params.Add(label_nfunc, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    252         sizer_params.Add(self.nfunc_ctl,   (iy,1), (1,1), wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    253         iy += 1 
    254         sizer_params.Add(label_alpha, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    255         sizer_params.Add(self.alpha_ctl,   (iy,1), (1,1), wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    256         sizer_params.Add(self.alpha_estimate_ctl,   (iy,2), (1,1), wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    257         iy += 1 
    258         sizer_params.Add(label_dmax, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    259         sizer_params.Add(self.dmax_ctl,   (iy,1), (1,1), wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     263        sizer_params.Add(label_sugg,       (iy,2), (1,1), wx.LEFT, 15) 
     264        iy += 1 
     265        sizer_params.Add(label_nfunc,      (iy,0), (1,1), wx.LEFT, 15) 
     266        sizer_params.Add(self.nfunc_ctl,   (iy,1), (1,1), wx.RIGHT, 0) 
     267        iy += 1 
     268        sizer_params.Add(label_alpha,      (iy,0), (1,1), wx.LEFT, 15) 
     269        sizer_params.Add(self.alpha_ctl,   (iy,1), (1,1), wx.RIGHT, 0) 
     270        sizer_params.Add(self.alpha_estimate_ctl, (iy,2), (1,1), wx.LEFT, 15) 
     271        iy += 1 
     272        sizer_params.Add(label_dmax, (iy,0), (1,1), wx.LEFT, 15) 
     273        sizer_params.Add(self.dmax_ctl,   (iy,1), (1,1), wx.RIGHT, 0) 
    260274 
    261275        boxsizer2.Add(sizer_params, 0) 
     
    275289        self.time_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    276290        self.time_ctl.SetEditable(False) 
     291        self.time_ctl.SetToolTipString("Computation time for the last inversion, in seconds.") 
     292         
    277293        self.chi2_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    278294        self.chi2_ctl.SetEditable(False) 
     295        self.chi2_ctl.SetToolTipString("Chi^2 over degrees of freedom.") 
     296         
    279297        self.osc_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    280298        self.osc_ctl.SetEditable(False) 
     299        self.osc_ctl.SetToolTipString("Oscillation parameter. P(r) for a sphere has an oscillation parameter of 1.1.") 
    281300         
    282301        sizer_res = wx.GridBagSizer(5,5) 
     
    302321        id = wx.NewId() 
    303322        button_OK = wx.Button(self, id, "Compute") 
     323        button_OK.SetToolTipString("Perform P(r) inversion.") 
    304324        self.Bind(wx.EVT_BUTTON, self._on_invert, id = id)    
    305325        #button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 
  • prview/perspectives/pr/pr.py

    rf3d51f6 r32dffae4  
    291291        wx.PostEvent(self.parent, StatusEvent(status=error)) 
    292292     
    293     def _estimate_completed(self, alpha, elapsed): 
     293    def _estimate_completed(self, alpha, message, elapsed): 
    294294        """ 
    295295            Parameter estimation completed,  
     
    301301        self.elapsed = elapsed 
    302302        self.control_panel.alpha_estimate = alpha 
     303        if not message==None: 
     304            wx.PostEvent(self.parent, StatusEvent(status=str(message))) 
    303305     
    304306    def _completed(self, out, cov, pr, elapsed): 
     
    322324        self.control_panel.oscillation = pr.oscillations(out) 
    323325        #print "OSCILL", pr.oscillations(out) 
     326        print "PEAKS:", pr.get_peaks(out) 
    324327         
    325328        for i in range(len(out)): 
     
    428431         
    429432    def perform_estimate(self): 
    430         print "ESTIMATE" 
    431433        from pr_thread import EstimatePr 
    432434        from copy import deepcopy 
    433435         
     436        wx.PostEvent(self.parent, StatusEvent(status='')) 
    434437        # If a thread is already started, stop it 
    435438        if self.estimation_thread != None and self.estimation_thread.isrunning(): 
     
    548551            [Somehow openGL needs this call] 
    549552        """ 
    550         pass 
    551      
     553        self.parent.set_perspective(self.perspective) 
     554     
  • prview/perspectives/pr/pr_thread.py

    rf3d51f6 r32dffae4  
    7575        except KeyboardInterrupt: 
    7676            printEVT("P(r) calc interrupted") 
    77             raise KeyboardInterrupt 
     77            raise KeyboardInterrupt     
    7878         
    7979    def compute(self): 
    8080        import time 
    81         try: 
    82              
    83             print "Alpha  Oscill" 
    84              
     81        try:             
    8582            self.starttime = time.time() 
    8683            # If the current alpha is zero, try 
     
    8986                self.pr.alpha = 0.0001 
    9087                  
     88            # Perform inversion to find the largest alpha 
    9189            out, cov = self.pr.lstsq(self.nfunc) 
    9290            elapsed = time.time()-self.starttime 
    93              
     91            initial_alpha = self.pr.alpha 
     92            initial_peaks = self.pr.get_peaks(out) 
    9493 
    95             # Take the default and try to find  
    96             # a better value 
    97             best_alpha = self.pr.alpha 
    98             best_osc   = self.pr.oscillations(out)  
    99              
    100             print best_alpha, best_osc 
    101              
    102             alpha = self.pr.suggested_alpha 
    103             print "initial:", alpha 
     94            # Try the inversion with the estimated alpha 
     95            self.pr.alpha = self.pr.suggested_alpha 
     96            out, cov = self.pr.lstsq(self.nfunc) 
    10497 
    105             # Look at smaller values 
    106             for i in range(5): 
    107                 self.pr.alpha = (0.1)**(i)*alpha 
    108                 out, cov = self.pr.lstsq(self.nfunc) 
    109                 osc = self.pr.oscillations(out)  
    110                 print self.pr.alpha, osc 
    111                 if  osc < best_osc: 
    112                     best_osc = osc 
    113                     best_alpha = alpha 
    114              
    115             ## Look at larger values 
    116             #for i in range(4): 
    117             #    self.pr.alpha = (10.0)**(i+1)*alpha 
    118             #    out, cov = self.pr.lstsq(self.nfunc) 
    119             #    osc = self.pr.oscillations(out)  
    120             #    print self.pr.alpha, osc 
    121             #    if  osc < best_osc: 
    122             #        best_osc = osc 
    123             #        best_alpha = alpha 
    124              
    125              
    126             self.complete(alpha=best_alpha, elapsed=elapsed) 
    127              
    128              
    129              
    130              
     98            npeaks = self.pr.get_peaks(out) 
     99            # if more than one peak to start with 
     100            # just return the estimate 
     101            if npeaks>1: 
     102                message = "Your P(r) is not smooth, please check your inversion parameters" 
     103                self.complete(alpha=self.pr.suggested_alpha, message=message, elapsed=elapsed) 
     104            else: 
     105                 
     106                # Look at smaller values 
     107                # We assume that for the suggested alpha, we have 1 peak 
     108                # if not, send a message to change parameters 
     109                alpha = self.pr.suggested_alpha 
     110                best_alpha = self.pr.suggested_alpha 
     111                found = False 
     112                for i in range(10): 
     113                    self.pr.alpha = (0.33)**(i+1)*alpha 
     114                    out, cov = self.pr.lstsq(self.nfunc) 
     115                    #osc = self.pr.oscillations(out)  
     116                    #print self.pr.alpha, osc 
     117                     
     118                    peaks = self.pr.get_peaks(out) 
     119                    print self.pr.alpha, peaks 
     120                    if peaks>1: 
     121                        found = True 
     122                        break 
     123                    best_alpha = self.pr.alpha 
     124                     
     125                # If we didn't find a turning point for alpha and 
     126                # the initial alpha already had only one peak, 
     127                # just return that 
     128                if not found and initial_peaks==1 and initial_alpha<best_alpha: 
     129                    best_alpha = initial_alpha 
     130                     
     131                # Check whether the size makes sense 
     132                message=None 
     133                 
     134                if not found: 
     135                    message = "None" 
     136                elif best_alpha>=0.5*self.pr.suggested_alpha: 
     137                    # best alpha is too big, return a  
     138                    # reasonable value 
     139                    message  = "The estimated alpha for your system is too large. " 
     140                    message += "Try increasing your maximum distance." 
     141                 
     142                self.complete(alpha=best_alpha, message=None, elapsed=elapsed) 
     143 
    131144        except: 
    132145            if not self.error_func==None: 
  • prview/perspectives/pr/requirements.txt

    rf3d51f6 r32dffae4  
    181814. Clean up the InversionDialog 
    191915. Add online help for inputs and outputs (especially figures of merit) 
     2016. Add help text to the interface (description of what we are minimizing, to explain alpha and nfunc). 
Note: See TracChangeset for help on using the changeset viewer.