Changeset 1065


Ignore:
Timestamp:
Sep 25, 2013 1:04:46 PM (10 years ago)
Author:
vondreele
Message:

add MC refinement to MC/SA - works

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIImath.py

    r1064 r1065  
    20872087        self.T0 = (fmax-fmin)*1.5
    20882088        return best_state.x
     2089       
     2090    def set_range(self,x0,frac):
     2091        delrange = frac*(self.upper-self.lower)
     2092        self.upper = x0+delrange
     2093        self.lower = x0-delrange
    20892094
    20902095    def accept_test(self, dE):
     
    21922197           T0=None, Tf=1e-12, maxeval=None, maxaccept=None, maxiter=400,
    21932198           boltzmann=1.0, learn_rate=0.5, feps=1e-6, quench=1.0, m=1.0, n=1.0,
    2194            lower=-100, upper=100, dwell=50, slope=0.9,ranStart=True,dlg=None):
     2199           lower=-100, upper=100, dwell=50, slope=0.9,ranStart=False,
     2200           ranRange=0.10,autoRan=False,dlg=None):
    21952201    """Minimize a function using simulated annealing.
    21962202
     
    22352241    :param float slope:
    22362242        Parameter for log schedule
    2237     :param bool ranStart=True:
    2238         False for fixed point start
     2243    :param bool ranStart=False:
     2244        True for set 10% of ranges about x
    22392245
    22402246    :returns: (xmin, Jmin, T, feval, iters, accept, retval) where
     
    23212327
    23222328    current_state, last_state, best_state = _state(), _state(), _state()
     2329    if ranStart:
     2330        schedule.set_range(x0,ranRange)
    23232331    if T0 is None:
    23242332        x0 = schedule.getstart_temp(best_state)
    23252333    else:
    2326         if ranStart:
    2327             x0 = random.uniform(size=len(x0))*(upper-lower) + lower #comment to avoid random start
     2334        x0 = random.uniform(size=len(x0))*(upper-lower) + lower
    23282335        best_state.x = None
    23292336        best_state.cost = numpy.Inf
     
    23562363                    best_state.cost = last_state.cost
    23572364                    bestn = n
     2365                    if best_state.cost < 1.0 and autoRan:
     2366                        schedule.set_range(x0,best_state.cost/2.)                       
    23582367        if dlg:
    23592368            GoOn = dlg.Update(min(100.,best_state.cost*100),
     
    28082817        boltzmann=MCSA['boltzmann'], learn_rate=0.5, 
    28092818        quench=MCSA['fast parms'][0], m=MCSA['fast parms'][1], n=MCSA['fast parms'][2],
    2810         lower=lower, upper=upper, slope=MCSA['log slope'],ranStart=MCSA.get('ranStart',True),dlg=pgbar)
     2819        lower=lower, upper=upper, slope=MCSA['log slope'],ranStart=MCSA.get('ranStart',False),
     2820        ranRange=MCSA.get('ranRange',0.10),autoRan=MCSA.get('autoRan',False),dlg=pgbar)
    28112821    M = mcsaCalc(results[0],refs,rcov,ifInv,allFF,RBdata,varyList,parmDict)
    28122822#    for ref in refs.T:
     
    28972907    if d:
    28982908        V /= d
     2909        if not A:       #==0.
     2910            A = 2.*np.pi
    28992911        p = A/2.
    29002912        Q[0] = np.cos(p)
     
    29102922    Q = np.zeros(4)
    29112923    d = nl.norm(np.array(V))
     2924    if not A:       #== 0.!
     2925        A = 360.
    29122926    if d:
    29132927        V /= d
  • trunk/GSASIIphsGUI.py

    r1060 r1065  
    696696            def OnRanStart(event):
    697697                MCSAdata['ranStart'] = ranStart.GetValue()
     698               
     699            def OnAutoRan(event):
     700                MCSAdata['autoRan'] = autoRan.GetValue()
     701               
     702            def OnRanRange(event):
     703                try:
     704                    val = float(ranRange.GetValue())/100
     705                    if 0.01 <= val <= 0.99:
     706                        MCSAdata['ranRange'] = val
     707                except ValueError:
     708                    pass
     709                ranRange.SetValue('%.1f'%(MCSAdata['ranRange']*100.))
    698710           
    699711            def OnAnneal(event):
     
    745757            line2Sizer.Add(cycles,0,wx.ALIGN_CENTER_VERTICAL)
    746758            line2Sizer.Add((5,0),)
    747             ranStart = wx.CheckBox(General,-1,label=' Random start? (ignored if Start temp = None)')
     759            ranStart = wx.CheckBox(General,-1,label=' MC/SA Refine at ')
    748760            ranStart.Bind(wx.EVT_CHECKBOX, OnRanStart)
    749             ranStart.SetValue(MCSAdata.get('ranStart',True))
    750             line2Sizer.Add(ranStart,0,wx.ALIGN_CENTER_VERTICAL)           
     761            ranStart.SetValue(MCSAdata.get('ranStart',False))
     762            line2Sizer.Add(ranStart,0,wx.ALIGN_CENTER_VERTICAL)
     763            ranRange = wx.TextCtrl(General,-1,value='%.1f'%(MCSAdata.get('ranRange',0.10)*100),style=wx.TE_PROCESS_ENTER)
     764            ranRange.Bind(wx.EVT_TEXT_ENTER,OnRanRange)       
     765            ranRange.Bind(wx.EVT_KILL_FOCUS,OnRanRange)
     766            line2Sizer.Add(ranRange,0,wx.ALIGN_CENTER_VERTICAL)
     767            line2Sizer.Add(wx.StaticText(General,label='% of ranges. '),0,wx.ALIGN_CENTER_VERTICAL)
     768#            autoRan = wx.CheckBox(General,-1,label=' Do auto range reduction? ')
     769#            autoRan.Bind(wx.EVT_CHECKBOX, OnAutoRan)
     770#            autoRan.SetValue(MCSAdata.get('autoRan',False))
     771#            line2Sizer.Add(autoRan,0,wx.ALIGN_CENTER_VERTICAL)
    751772            mcsaSizer.Add(line2Sizer)
    752773            mcsaSizer.Add((5,5),)
     
    40664087                    try:
    40674088                        Anew = float(ObjA.GetValue())
     4089                        if not Anew:    #==0.0!
     4090                            Anew = 360.
    40684091                    except ValueError:
    40694092                        Anew = A
     
    40764099                else:
    40774100                    ObjA.SetValue('%.5f'%(A))
     4101                    ObjV.SetValue('%.3f %.3f %.3f'%(V[0],V[1],V[2]))
    40784102                G2plt.PlotStructure(G2frame,data)
    4079                 UpdateMCSA()
     4103#                UpdateMCSA()
    40804104
    40814105            def OnMolCent(event):
Note: See TracChangeset for help on using the changeset viewer.