Changeset 1001


Ignore:
Timestamp:
Jul 18, 2013 3:19:58 PM (9 years ago)
Author:
vondreele
Message:

tweak MC/SA

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIImath.py

    r991 r1001  
    3131import GSASIIlattice as G2lat
    3232import GSASIIspc as G2spc
     33import GSASIIpwd as G2pwd
    3334import numpy.fft as fft
    3435import pypowder as pyd
     
    22022203           T0=None, Tf=1e-12, maxeval=None, maxaccept=None, maxiter=400,
    22032204           boltzmann=1.0, learn_rate=0.5, feps=1e-6, quench=1.0, m=1.0, n=1.0,
    2204            lower=-100, upper=100, dwell=50, slope=0.9,dlg=None):
     2205           lower=-100, upper=100, dwell=50, slope=0.9,ranStart=True,dlg=None):
    22052206    """Minimize a function using simulated annealing.
    22062207
     
    22452246    :param float slope:
    22462247        Parameter for log schedule
     2248    :param bool ranStart=True:
     2249        False for fixed point start
    22472250
    22482251    :returns: (xmin, Jmin, T, feval, iters, accept, retval) where
     
    23322335        x0 = schedule.getstart_temp(best_state)
    23332336    else:
    2334         x0 = random.uniform(size=len(x0))*(upper-lower) + lower #comment to avoid random start
     2337        if ranStart:
     2338            x0 = random.uniform(size=len(x0))*(upper-lower) + lower #comment to avoid random start
    23352339        best_state.x = None
    23362340        best_state.cost = numpy.Inf
     
    23452349    schedule.T = schedule.T0
    23462350    fqueue = [100, 300, 500, 700]
    2347     iters = 0
     2351    iters = 1
    23482352    keepGoing = True
    23492353    while keepGoing:
     
    24502454   
    24512455    '''
    2452     gamFW = lambda s,g: math.exp(math.log(s**5+2.69269*s**4*g+2.42843*s**3*g**2+4.47163*s**2*g**3+0.07842*s*g**4+g**5)/5.)
    24532456   
    24542457    twopi = 2.0*np.pi
     
    25862589        return Tdata,Xdata.T
    25872590   
    2588     def calcMDcorr(MDval,MDaxis,Uniq,G):
    2589         ''' Calls fortran routine'''
    2590         MDcorr = pyd.pymdcalc(MDval,MDaxis,len(Uniq),Uniq.flatten(),G)
    2591         return MDcorr
    2592        
    2593     def mcsaMDSFcalc(ifInv,Tdata,Mdata,Xdata,MDval,MDaxis,G,mul,FFs,Uniq,Phi):
    2594         ''' Calls fortran routine'''
    2595         Icalc = pyd.pymcsamdsfcalc(ifInv,len(Tdata),Tdata,Mdata,Xdata.flatten(),
    2596             MDval,MDaxis,G,mul,len(FFs),FFs,len(Uniq),Uniq.flatten(),Phi)
    2597         return Icalc
    2598 
    2599     def mcsaSFcalc(ifInv,Tdata,Mdata,Xdata,mul,FFs,Uniq,Phi):
    2600         ''' Calls fortran routine'''
    2601         Icalc = pyd.pymcsasfcalc(ifInv,len(Tdata),Tdata,Mdata,Xdata.flatten(),
    2602             mul,len(FFs),FFs,len(Uniq),Uniq.flatten(),Phi)
    2603         return Icalc
    26042591
    26052592    def mcsaCalc(values,refList,rcov,ifInv,RBdata,varyList,parmDict):
     
    26102597        puts result F^2 in each ref[8] in refList
    26112598        '''       
     2599        def mcsaMDSFcalc(mul,FFs,Uniq,Phi):
     2600            ''' Calls fortran routine'''
     2601            Icalc = pyd.pymcsamdsfcalc(ifInv,len(Tdata),Tdata,Mdata,Xdata.flatten(),
     2602                MDval,MDaxis,Gmat,mul,len(FFs),FFs,len(Uniq),Uniq.flatten(),Phi)
     2603            return Icalc
    26122604        global tsum
    26132605        parmDict.update(dict(zip(varyList,values)))
     
    26212613        for refl in refList:
    26222614            t0 = time.time()
    2623             refl[5] = mcsaMDSFcalc(ifInv,Tdata,Mdata,Xdata,MDval,MDaxis,Gmat,
    2624                 refl[3],refl[7],refl[8],refl[9])
    2625 #            refl[5] = mcsaSFcalc(ifInv,Tdata,Mdata,Xdata,refl[3],refl[7],refl[8],refl[9])
    2626 #            refl[5] *= calcMDcorr(MDval,MDaxis,refl[8],Gmat)
     2615            refl[5] = mcsaMDSFcalc(refl[3],refl[7],refl[8],refl[9])
    26272616            tsum += (time.time()-t0)
    26282617            sumFcsq += refl[5]
     
    26872676            h,k,l,m,d,pos,sig,gam,f = ref[:9]
    26882677            if d >= MCSA['dmin']:
    2689                 sig = gamFW(sig,gam)/sq8ln2        #--> sig from FWHM
     2678                sig = G2pwd.getgamFW(sig,gam)/sq8ln2        #--> sig from FWHM
    26902679                SQ = 0.25/d**2
    26912680                Uniq,phi = G2spc.GenHKLf([h,k,l],SGData)[2:]
     
    27632752        boltzmann=MCSA['boltzmann'], learn_rate=0.5, 
    27642753        quench=MCSA['fast parms'][0], m=MCSA['fast parms'][1], n=MCSA['fast parms'][2],
    2765         lower=lower, upper=upper, slope=MCSA['log slope'],dlg=pgbar)
     2754        lower=lower, upper=upper, slope=MCSA['log slope'],ranStart=MCSA.get('ranStart',True),dlg=pgbar)
    27662755    Result = [False,False,results[1],results[2],]+list(results[0])
    27672756    Result.append(varyList)
  • trunk/GSASIIphsGUI.py

    r1000 r1001  
    691691                    pass
    692692                Obj.SetValue("%.3f"%(MCSA[name][ind]))
     693               
     694            def OnRanStart(event):
     695                MCSA['ranStart'] = ranStart.GetValue()
    693696           
    694697            def OnAnneal(event):
     
    734737            line2Sizer = wx.BoxSizer(wx.HORIZONTAL)
    735738            line2Sizer.Add(wx.StaticText(General,label=' MC/SA runs: '),0,wx.ALIGN_CENTER_VERTICAL)
    736             Cchoice = ['1','2','3','4','8','12','20','32','64','128']
     739            Cchoice = ['1','2','3','6','10','20','30','60','100']
    737740            cycles = wx.ComboBox(General,-1,value=str(MCSA.get('Cycles',1)),choices=Cchoice,
    738741                style=wx.CB_READONLY|wx.CB_DROPDOWN)
    739742            cycles.Bind(wx.EVT_COMBOBOX,OnCycles)       
    740743            line2Sizer.Add(cycles,0,wx.ALIGN_CENTER_VERTICAL)
     744            line2Sizer.Add((5,0),)
     745            ranStart = wx.CheckBox(General,-1,label=' Random start? (ignored if Start temp = None)')
     746            ranStart.Bind(wx.EVT_CHECKBOX, OnRanStart)
     747            ranStart.SetValue(MCSA.get('ranStart',True))
     748            line2Sizer.Add(ranStart,0,wx.ALIGN_CENTER_VERTICAL)           
     749            mcsaSizer.Add(line2Sizer)
     750            mcsaSizer.Add((5,5),)
     751            line3Sizer = wx.BoxSizer(wx.HORIZONTAL)
    741752            Achoice = ['log','fast']                #these work
    742753#            Achoice = ['log','fast','cauchy','boltzmann','Tremayne']
    743             line2Sizer.Add(wx.StaticText(General,label=' MC/SA schedule: '),0,wx.ALIGN_CENTER_VERTICAL)
     754            line3Sizer.Add(wx.StaticText(General,label=' MC/SA schedule: '),0,wx.ALIGN_CENTER_VERTICAL)
    744755            Alist = wx.ComboBox(General,-1,value=MCSA['Algorithm'],choices=Achoice,
    745756                style=wx.CB_READONLY|wx.CB_DROPDOWN)
    746757            Alist.Bind(wx.EVT_COMBOBOX,OnAlist)
    747             line2Sizer.Add(Alist,0,wx.ALIGN_CENTER_VERTICAL)
     758            line3Sizer.Add(Alist,0,wx.ALIGN_CENTER_VERTICAL)
    748759            if MCSA['Algorithm'] in ['Tremayne','fast','boltzmann','cauchy']:
    749760                Names = [' A-jump: ',' B-jump: ']
     
    755766                    parms = 'fast parms'
    756767                for i,name in enumerate(Names):
    757                     line2Sizer.Add(wx.StaticText(General,label=name),0,wx.ALIGN_CENTER_VERTICAL)
     768                    line3Sizer.Add(wx.StaticText(General,label=name),0,wx.ALIGN_CENTER_VERTICAL)
    758769                    Ajump =  wx.TextCtrl(General,-1,value='%.3f'%(MCSA[parms][i]),style=wx.TE_PROCESS_ENTER)
    759770                    Ajump.Bind(wx.EVT_TEXT_ENTER,OnAjump)       
    760771                    Ajump.Bind(wx.EVT_KILL_FOCUS,OnAjump)
    761772                    Indx[Ajump.GetId()] = [parms,i]
    762                     line2Sizer.Add(Ajump,0,wx.ALIGN_CENTER_VERTICAL)
     773                    line3Sizer.Add(Ajump,0,wx.ALIGN_CENTER_VERTICAL)
    763774            elif 'log' in MCSA['Algorithm']:
    764                 line2Sizer.Add(wx.StaticText(General,label=' slope: '),0,wx.ALIGN_CENTER_VERTICAL)
     775                line3Sizer.Add(wx.StaticText(General,label=' slope: '),0,wx.ALIGN_CENTER_VERTICAL)
    765776                slope =  wx.TextCtrl(General,-1,value='%.3f'%(MCSA['log slope']),style=wx.TE_PROCESS_ENTER)
    766777                slope.Bind(wx.EVT_TEXT_ENTER,OnSlope)       
    767778                slope.Bind(wx.EVT_KILL_FOCUS,OnSlope)
    768                 line2Sizer.Add(slope,0,wx.ALIGN_CENTER_VERTICAL)
    769             mcsaSizer.Add(line2Sizer)
     779                line3Sizer.Add(slope,0,wx.ALIGN_CENTER_VERTICAL)
     780            mcsaSizer.Add(line3Sizer)
    770781            mcsaSizer.Add((5,5),)
    771782            line3Sizer = wx.BoxSizer(wx.HORIZONTAL)
Note: See TracChangeset for help on using the changeset viewer.