source: releases/mystic-0.2a1-patch2.diff @ 248

Revision 248, 6.3 KB checked in by mmckerns, 6 years ago (diff)

updated for patch2

  • mystic-0.2a1/mystic/tools.py

     
    132132        self._y = []    
    133133 
    134134    def __call__(self, x, y): 
     135        from numpy import ndarray 
     136        if isinstance(x,ndarray): x = list(x) 
    135137        self._x.append(x) 
    136138        self._y.append(y) 
    137139      
     
    153155    """ 
    154156    import numpy 
    155157    def __init__(self, interval = 10, xinterval = numpy.inf): 
    156         Sow.__init__(self) 
     158       #Sow.__init__(self) 
     159        super(VerboseSow,self).__init__() 
    157160        self._step = 0 
    158161        self._yinterval = interval 
    159162        self._xinterval = xinterval 
    160163        return 
    161164    def __call__(self, x, y): 
    162165        from numpy import ndarray 
    163         Sow.__call__(self, x, y) 
     166       #Sow.__call__(self, x, y) 
     167        super(VerboseSow,self).__call__(x, y) 
    164168        if isinstance(y,(list,ndarray)): 
    165169            y = y[0] #XXX: get the "best" fit... which should be in y[0] 
    166170        if isinstance(x[0],(list,ndarray)): #XXX: x should always be iterable 
     
    169173           #print "Generation %d has best Chi-Squared: %s" % (self._step, y) 
    170174            print "Generation %d has best Chi-Squared: %f" % (self._step, y) 
    171175        if int(self._step % self._xinterval) == 0: 
     176            if isinstance(x,ndarray): x = list(x) 
    172177            print "Generation %d has best fit parameters:\n %s" % (self._step, x) 
    173178        self._step += 1 
    174179        return 
     
    182187    import numpy 
    183188    def __init__(self, interval=1, filename='log.txt', new=False): 
    184189        import datetime 
    185         Sow.__init__(self) 
     190       #Sow.__init__(self) 
     191        super(LoggingSow,self).__init__() 
    186192        self._filename = filename 
    187193        self._step = 0 
    188194        self._yinterval = interval 
     
    197203    def __call__(self, x, y): 
    198204        self._file = open(self._filename,'a') 
    199205        from numpy import ndarray 
    200         Sow.__call__(self, x, y) 
     206       #Sow.__call__(self, x, y) 
     207        super(LoggingSow,self).__call__(x, y) 
    201208        if isinstance(y,(list,ndarray)): 
    202209            y = y[0] #XXX: get the "best" fit... which should be in y[0] 
    203210        if isinstance(x[0],(list,ndarray)): #XXX: x should always be iterable 
    204211            x = x[0] #XXX: get the "best" fit... which should be in x[0] 
    205212        if int(self._step % self._yinterval) == 0: 
     213            if isinstance(x,ndarray): x = list(x) 
    206214            self._file.write(" %d   %f   %s\n" % (self._step, y, x)) 
    207215        self._step += 1 
    208216        self._file.close() 
  • mystic-0.2a1/mystic/differential_evolution.py

     
    215215Further Inputs: 
    216216 
    217217    strategy -- the mutation strategy for generating new trial 
    218         solutions [default = Best1Exp] 
     218        solutions [default = Best1Bin] 
    219219    CrossProbability -- the probability of cross-parameter mutations 
    220         [default = 0.5] 
     220        [default = 0.9] 
    221221    ScalingFactor -- multiplier for the impact of mutations on the 
    222         trial solution [default = 0.7] 
     222        trial solution [default = 0.8] 
    223223    callback -- an optional user-supplied function to call after each 
    224224        iteration.  It is called as callback(xk), where xk is 
    225225        the current parameter vector.  [default = None] 
     
    227227 
    228228        """ 
    229229        #allow for inputs that don't conform to AbstractSolver interface 
    230         from mystic.strategy import Best1Exp 
    231         strategy=Best1Exp    #mutation strategy (see mystic.strategy) 
    232         CrossProbability=0.5 #potential for parameter cross-mutation 
    233         ScalingFactor=0.7    #multiplier for mutation impact 
     230        from mystic.strategy import Best1Bin 
     231        strategy=Best1Bin    #mutation strategy (see mystic.strategy) 
     232        CrossProbability=0.9 #potential for parameter cross-mutation 
     233        ScalingFactor=0.8    #multiplier for mutation impact 
    234234        callback=None        #user-supplied function, called after each step 
    235235        disp=0               #non-zero to print convergence messages 
    236236        if kwds.has_key('strategy'): strategy = kwds['strategy'] 
     
    399399Further Inputs: 
    400400 
    401401    strategy -- the mutation strategy for generating new trial 
    402         solutions [default = Best1Exp] 
     402        solutions [default = Best1Bin] 
    403403    CrossProbability -- the probability of cross-parameter mutations 
    404         [default = 0.5] 
     404        [default = 0.9] 
    405405    ScalingFactor -- multiplier for the impact of mutations on the 
    406         trial solution [default = 0.7] 
     406        trial solution [default = 0.8] 
    407407    callback -- an optional user-supplied function to call after each 
    408408        iteration.  It is called as callback(xk), where xk is 
    409409        the current parameter vector.  [default = None] 
     
    415415    disp -- non-zero to print convergence messages. 
    416416        """ 
    417417        #allow for inputs that don't conform to AbstractSolver interface 
    418         from mystic.strategy import Best1Exp 
    419         strategy=Best1Exp    #mutation strategy (see mystic.strategy) 
    420         CrossProbability=0.5 #potential for parameter cross-mutation 
    421         ScalingFactor=0.7    #multiplier for mutation impact 
     418        from mystic.strategy import Best1Bin 
     419        strategy=Best1Bin    #mutation strategy (see mystic.strategy) 
     420        CrossProbability=0.9 #potential for parameter cross-mutation 
     421        ScalingFactor=0.8    #multiplier for mutation impact 
    422422        callback=None        #user-supplied function, called after each step 
    423423        disp=0               #non-zero to print convergence messages 
    424424        if kwds.has_key('strategy'): strategy = kwds['strategy'] 
  • mystic-0.2a1/examples/test_mogi.py

     
    114114    # 
    115115    desol, dstepmon = de_solve() 
    116116    print "desol: ", desol 
    117     print "dstepmon 10: ", dstepmon.x[50] 
    118     print "dstepmon 20: ", dstepmon.x[100] 
     117    print "dstepmon 50: ", dstepmon.x[50] 
     118    print "dstepmon 100: ", dstepmon.x[100] 
    119119    # 
    120120    # this will try to use nelder_mean from a relatively "near by" point (very sensitive) 
    121121    point = [1234., -500., 10., 0.001] # both cg and nm does fine 
Note: See TracBrowser for help on using the repository browser.