Changeset 1065 for trunk/GSASIImath.py


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

add MC refinement to MC/SA - works

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.