Changeset 751


Ignore:
Timestamp:
09/23/14 18:22:45 (20 months ago)
Author:
mmckerns
Message:

added functions: sphere, peaks, venkat91, schwefel, ellipsoid, rastrigin
added functions: powers, ackley, michal, branins, easom, goldstein
added function documentation; function were instances now are instance.methods
fosc3d moved to trott; changed default bounds for model plotter

Location:
mystic
Files:
3 added
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • mystic/models/__init__.py

    r713 r751  
    1616the function API found in `mystic.models.abstract_model`. These standard 
    1717functions are provided:: 
     18    sphere     -- De Jong's spherical function 
    1819    rosen      -- Rosenbrock's function 
    1920    step       -- De Jong's step function 
     
    2122    shekel     -- Shekel's function 
    2223    corana     -- Corana's function 
    23     fosc3d     -- the fOsc3D Mathematica function 
     24    fosc3d     -- Trott's fOsc3D function 
    2425    griewangk  -- Griewangk's function 
    2526    zimmermann -- Zimmermann's function 
     27    peaks      -- NAG's peaks function 
     28    venkat91   -- Venkataraman's sinc function 
     29    schwefel   -- Schwefel's function 
     30    ellipsoid  -- Pohlheim's rotated hyper-ellipsoid function 
     31    rastrigin  -- Rastrigin's function 
     32    powers     -- Pohlheim's sum of different powers function 
     33    ackley     -- Ackley's path function 
     34    michal     -- Michalewicz's function 
     35    branins    -- Branins's rcos function 
     36    easom      -- Easom's function 
     37    goldstein  -- Goldstein-Price's function 
    2638    wavy1      -- a simple sine-based multi-minima function 
    2739    wavy2      -- another simple sine-based multi-minima function 
     
    6173 
    6274# functions 
    63 from dejong import rosen, step, quartic, shekel 
     75from dejong import sphere, rosen, step, quartic, shekel 
    6476from corana import corana 
    65 from fosc3d import fosc3d 
     77from trott import fosc3d 
    6678from griewangk import griewangk 
    6779from zimmermann import zimmermann 
     80from nag import peaks 
     81from venkataraman import venkat91 
    6882from wavy import wavy1, wavy2 
     83from pohlheim import schwefel, ellipsoid, rastrigin, powers, ackley 
     84from pohlheim import michal, branins, easom, goldstein 
    6985 
    7086#shortcuts 
     
    7288#from br8 import data as br8data 
    7389#from br8 import cost as br8cost 
    74 #from corana import corana1d, corana2d, corana3d 
    7590#from lorentzian import gendata, histogram 
    7691 
  • mystic/models/abstract_model.py

    r750 r751  
    2323 
    2424For example, if function is overwritten with the Rosenbrock function: 
    25     >>> rosen = Rosenbrock() 
    26     >>> rosen(1,1,1) 
     25    >>> rosen = Rosenbrock(ndim=3) 
     26    >>> rosen([1,1,1]) 
    2727    0. 
    2828   """ 
    2929 
    30     def __init__(self): 
     30    def __init__(self, ndim=None): 
    3131        """ 
    3232Provides a base class for mystic functions. 
    3333 
    34 Takes no inputs. 
     34Takes optional input 'ndim' (number of dimensions). 
    3535        """ 
     36        if self.minimizers is None: 
     37            self.minimizers = [] 
     38           #raise NotImplementedError('minimizers have not been provided') 
     39        nmin = len(self.minimizers) 
     40 
     41        # set the number of dimensions 
     42        try: # fixed dimension 
     43            self.ndim = len(self.minimizers[0] if nmin else None) 
     44            fixed = True 
     45            if ndim is None: ndim = self.ndim 
     46        except TypeError: # not fixed 
     47            self.ndim = ndim 
     48            fixed = False 
     49        if fixed and ndim != self.ndim: 
     50            raise ValueError('number of dimensions is fixed (ndim=%d)' % self.ndim) 
     51        elif not fixed and ndim is None: 
     52            raise ValueError('number of dimensions must be set (ndim=None)') 
     53 
     54        # set the minimizer (and adjust minimizers if not fixed) 
     55        if not nmin: 
     56            self.minimizers = list(self.minimizers) 
     57            self.minimizer = None 
     58        elif not fixed: #XXX: should be array instead of tuple? 
     59            self.minimizers = [tuple([m]*ndim) for m in self.minimizers] 
     60            self.minimizer = self.minimizers[0] # global *must* be first 
     61        else: 
     62            self.minimizers = list(self.minimizers) 
     63            self.minimizer = self.minimizers[0] # global *must* be first 
     64 
     65        # get the mimima 
     66        self.minima = map(self.function, self.minimizers) 
     67        self.minimum = min(self.minima) if self.minima else None 
     68        if self.minima and self.minima.index(self.minimum): 
     69            raise ValueError('global minimum must be at index = 0') 
    3670        return 
    3771 
    3872    def __call__(self,*args,**kwds): 
     73        coeffs = kwds.get('coeffs', args[0] if len(args) else []) 
     74        if len(coeffs) != self.ndim: 
     75            raise ValueError('input length does not match ndim (ndim=%d)' % self.ndim) 
    3976        return self.function(*args,**kwds) 
    4077 
    4178    def function(self,coeffs): 
    4279        """takes a list of coefficients x, returns f(x)""" 
    43         raise NotImplementedError, "overwrite for each derived class" 
     80        raise NotImplementedError, "overwrite function for each derived class" 
    4481 
    4582#   def forward(self,pts): 
    4683#       """takes points p=(x,y,...), returns f(xi,yi,...)""" 
    4784#       pts = asarray(pts) #XXX: converting to numpy.array slows by 10x 
    48 #       return [self.function(i) for i in pts.transpose()] #FIXME: requires pts is a numpy.array 
     85#       return [self.function(i) for i in pts.transpose()] 
     86 
     87    minimizers = None # not given; *must* set to 'list' or 'list of tuples' 
     88    # - None          => not set / not known / no minimizers 
     89    # - [1,5]         => global and local; input dimensions are not fixed 
     90    # - [(1,2),(5,3)] => global and local; input dimensions are fixed 
    4991    pass 
    5092 
  • mystic/models/corana.py

    r713 r751  
    66# License: 3-clause BSD.  The full license text is available at: 
    77#  - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE 
    8 """ 
    9 Corana's function 
     8__doc__ = _doc = """ 
     9This is part of Storn's "Differential Evolution" test suite, as defined 
     10in [2], with 'Corana' function definitions drawn from [3,4]. 
    1011 
    1112References:: 
    12     [1] Storn, R. and Price, K. Differential Evolution - A Simple and Efficient 
    13     Heuristic for Global Optimization over Continuous Spaces. Journal of Global 
    14     Optimization 11: 341-359, 1997. 
     13    [1] Storn, R. and Price, K. "Differential Evolution - A Simple and 
     14    Efficient Heuristic for Global Optimization over Continuous Spaces" 
     15    Journal of Global Optimization 11: 341-359, 1997. 
    1516 
    16     [2] Storn, R. and Price, K. 
    17     (Same title as above, but as a technical report.) 
    18     http://www.icsi.berkeley.edu/~storn/deshort1.ps 
     17    [2] Storn, R. and Price, K. "Differential Evolution - A Simple and 
     18    Efficient Heuristic for Global Optimization over Continuous Spaces" 
     19    TR-95-012, ICSI, 1995. http://www.icsi.berkeley.edu/~storn/TR-95-012.pdf 
     20 
     21    [3] Ingber, L. "Simulated Annealing: Practice Versus Theory" J. of 
     22    Mathematical and Computer Modeling 18(11), 29-57, 1993. 
     23 
     24    [4] Corana, A. and Marchesi, M. and Martini, C. and Ridella, S. 
     25    "Minimizing Multimodal Functions of Continuous Variables with the 
     26    'Simulated Annealing Algorithm'" ACM Transactions on Mathematical 
     27    Software, March, 272-280, 1987. 
    1928""" 
    2029from abstract_model import AbstractFunction 
     
    2534 
    2635class Corana(AbstractFunction): 
    27     """Corana's function: 
    28 a multi-minima function, Equation (22) of [2]""" 
     36    __doc__ = \ 
     37    """a Corana's parabola function generator 
    2938 
    30     def __init__(self): 
    31         AbstractFunction.__init__(self) 
     39Corana's parabola function [1,2,3,4] defines a paraboloid whose 
     40axes are parallel to the coordinate axes. This funciton has a 
     41large number of wells that increase in depth with proximity to 
     42the origin. The global minimum is a plateau around the origin. 
     43 
     44The generated function f(x) is a modified version of equation (22) 
     45of [2], where len(x) <= 4. 
     46    """ + _doc 
     47    def __init__(self, ndim=4): # is n-dimensional n=[1,4] (n=4 in ref) 
     48        AbstractFunction.__init__(self, ndim=ndim) 
    3249        return 
    3350 
    3451    def function(self,coeffs): 
    35         """evaluates the Corana function for a list of coeffs 
     52        """evaluates a 4-D Corana's parabola function for a list of coeffs 
    3653 
    37 minimum is f(x)=0.0 at xi=0.0""" 
     54f(x) = \sum_(i=0)^(3) f_0(x) 
     55 
     56Where for \abs(x_i - z_i) < 0.05: 
     57f_0(x) = 0.15*(z_i - 0.05*\sign(z_i))^(2) * d_i 
     58and otherwise: 
     59f_0(x) = d_i * x_(i)^(2), 
     60with z_i = \floor(\abs(x_i/0.2)+0.49999)*\sign(x_i)*0.2 
     61and d_i = 1,1000,10,100. 
     62 
     63For len(x) == 1, x = x_0,0,0,0; 
     64for len(x) == 2, x = x_0,0,x_1,0; 
     65for len(x) == 3, x = x_0,0,x_1,x_2; 
     66for len(x) >= 4, x = x_0,x_1,x_2,x_3. 
     67 
     68Inspect with mystic_model_plotter using:: 
     69    mystic.models.corana -b "-1:1:.01, -1:1:.01" -d -x 1 
     70 
     71The minimum is f(x)=0 for \abs(x_i) < 0.05 for all i.""" 
    3872        d = [1., 1000., 10., 100.] 
     73        _d = [0, 3, 1, 2]   # ordering for lower dimensions 
    3974       #x = asarray(coeffs) #XXX: converting to numpy.array slows by 10x 
    40         x = coeffs 
     75        x = [0.]*4 # ensure that there are 4 coefficients 
     76        if len(coeffs) < 4: 
     77            _x = x[:] 
     78            _x[:len(coeffs)]=coeffs 
     79            for i in range(4): 
     80                x[_d.index(i)] = _x[i] 
     81        else: 
     82            x = coeffs 
    4183        r = 0 
    4284        for j in range(4): 
     
    4890        return r 
    4991 
    50 #   def forward(self,pts): 
    51 #       """n-dimensional Corana; returns f(xi) for each xi in pts""" 
    52 #       return AbstractFunction.forward(self,pts) 
    53  
     92    minimizers = None #FIXME: degenerate minimum... (-0.05, 0.05) 
     93                      # minimum is f(x)=0 for \abs(x_i) < 0.05 for all i.""" 
    5494    pass 
    5595 
     96# cleanup 
     97del _doc 
    5698 
    5799# prepared instances 
    58 corana = Corana() 
    59  
    60 def corana1d(x): 
    61     """Corana in 1D; coeffs = (x,0,0,0)""" 
    62     return corana([x[0], 0, 0, 0]) 
    63  
    64 def corana2d(x): 
    65     """Corana in 2D; coeffs = (x,0,y,0)""" 
    66     return corana([x[0], 0, x[1], 0]) 
    67  
    68 def corana3d(x): 
    69     """Corana in 3D; coeffs = (x,0,y,z)""" 
    70     return corana([x[0], 0, x[1], x[2]]) 
     100corana = Corana().function 
    71101 
    72102# End of file 
  • mystic/models/dejong.py

    r713 r751  
    66# License: 3-clause BSD.  The full license text is available at: 
    77#  - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE 
    8 """ 
    9 Rosenbrock's function, De Jong's step function, De Jong's quartic function, 
    10 and Shekel's function 
     8__doc__ = _doc = """ 
     9This is part of Storn's "Differential Evolution" test suite, as defined 
     10in [2], with 'De Jong' function definitions drawn from [3]. 
    1111 
    1212References:: 
    13     [1] Storn, R. and Price, K. Differential Evolution - A Simple and Efficient 
    14     Heuristic for Global Optimization over Continuous Spaces. Journal of Global 
    15     Optimization 11: 341-359, 1997. 
    16  
    17     [2] Storn, R. and Price, K. 
    18     (Same title as above, but as a technical report.) 
    19     http://www.icsi.berkeley.edu/~storn/deshort1.ps 
     13    [1] Storn, R. and Price, K. "Differential Evolution - A Simple and 
     14    Efficient Heuristic for Global Optimization over Continuous Spaces" 
     15    Journal of Global Optimization 11: 341-359, 1997. 
     16 
     17    [2] Storn, R. and Price, K. "Differential Evolution - A Simple and 
     18    Efficient Heuristic for Global Optimization over Continuous Spaces" 
     19    TR-95-012, ICSI, 1995. http://www.icsi.berkeley.edu/~storn/TR-95-012.pdf 
     20 
     21    [3] Ingber, L. and Rosen, B. "Genetic Algorithms and Very Fast 
     22    Simulated Reannealing: A Comparison" J. of Mathematical and Computer 
     23    Modeling 16(11), 87-100, 1992. 
    2024""" 
    2125from abstract_model import AbstractFunction 
    2226 
    2327from numpy import sum as numpysum 
    24 from numpy import asarray, transpose 
     28from numpy import asarray, transpose, inf 
    2529from numpy import zeros_like, diag, zeros, atleast_1d 
    2630from math import floor 
    2731import random 
    2832from math import pow 
     33from mystic.tools import permutations 
     34 
     35class Sphere(AbstractFunction): 
     36    __doc__ = \ 
     37    """a De Jong spherical function generator 
     38 
     39De Jong's spherical function [1,2,3] is considered to be a simple 
     40task for every serious minimization method. The minimum is located 
     41at the center of the N-dimensional spehere.  There are no local 
     42minima. 
     43 
     44The generated function f(x) is identical to equation (17) of [2], 
     45where len(x) >= 0. 
     46    """ + _doc 
     47    def __init__(self, ndim=3): # is n-dimensional (n=3 in ref) 
     48        AbstractFunction.__init__(self, ndim=ndim) 
     49        return 
     50 
     51    def function(self,coeffs): 
     52        """evaluates an N-dimensional spherical function for a list of coeffs 
     53 
     54f(x) = \sum_(i=0)^(N-1) x_(i)^2 
     55 
     56Inspect with mystic_model_plotter using:: 
     57    mystic.models.sphere -b "-5:5:.1, -5:5:.1" -d 
     58 
     59The minimum is f(x)=0.0 at x_i=0.0 for all i""" 
     60        f = 0. 
     61        for c in coeffs: 
     62            f += c*c 
     63        return f 
     64 
     65    minimizers = [0.] 
     66    pass 
     67 
    2968 
    3069class Rosenbrock(AbstractFunction): 
    31     """Rosenbrock function: 
    32 A modified second De Jong function, Equation (18) of [2]""" 
    33  
    34     def __init__(self): 
    35         AbstractFunction.__init__(self) 
    36         return 
    37  
    38     def function(self,coeffs): 
    39         """evaluates n-dimensional Rosenbrock function for a list of coeffs 
    40  
    41 minimum is f(x)=0.0 at xi=1.0""" 
     70    __doc__ = \ 
     71    """a Rosenbrock's Saddle function generator 
     72 
     73Rosenbrock's Saddle function [1,2,3] has the reputation of being 
     74a difficult minimization problem. In two dimensions, the function 
     75is a saddle with an inverted basin, where the global minimum 
     76occurs along the rim of the inverted basin. 
     77 
     78The generated function f(x) is a modified version of equation (18) 
     79of [2], where len(x) >= 0. 
     80    """ + _doc 
     81    def __init__(self, ndim=2): # is n-dimensional (n=2 in ref) 
     82        AbstractFunction.__init__(self, ndim=ndim) 
     83        return 
     84 
     85    def function(self,coeffs): 
     86        """evaluates an N-dimensional Rosenbrock saddle for a list of coeffs 
     87 
     88f(x) = \sum_(i=0)^(N-2) 100*(x_(i+1) - x_(i)^(2))^(2) + (1 - x_(i))^(2) 
     89 
     90Inspect with mystic_model_plotter using:: 
     91    mystic.models.rosen -b "-3:3:.1, -1:5:.1, 1" -d -x 1 
     92 
     93The minimum is f(x)=0.0 at x_i=1.0 for all i""" 
    4294        x = [1]*2 # ensure that there are 2 coefficients 
    4395        x[:len(coeffs)]=coeffs 
     
    4597        return numpysum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0)#,axis=0) 
    4698 
    47     #def forward(self,pts): 
    48     #    """n-dimensional Rosenbrock; returns f(xi,yi,...) for pts=(x,y,...)""" 
    49     #    return AbstractFunction.forward(self,pts) 
    50  
    5199    def derivative(self,coeffs): 
    52         """evaluates n-dimensional Rosenbrock derivative for a list of coeffs 
    53  
    54 minimum is f'(x)=[0.0]*n at x=[1.0]*n;  x must have len >= 2""" 
     100        """evaluates an N-dimensional Rosenbrock derivative for a list of coeffs 
     101 
     102The minimum is f'(x)=[0.0]*n at x=[1.0]*n, where len(x) >= 2.""" 
    55103        l = len(coeffs) 
    56104        x = [0]*l #XXX: ensure that there are 2 coefficients ? 
     
    67115 
    68116    def hessian(self, coeffs): 
    69         """evaluates n-dimensional Rosenbrock hessian for the given coeffs 
    70  
    71 coeffs must have len >= 2""" 
     117        """evaluates an N-dimensional Rosenbrock hessian for the given coeffs 
     118 
     119The function f''(x) requires len(x) >= 2.""" 
    72120        x = atleast_1d(coeffs) 
    73121        H = diag(-400*x[:-1],1) - diag(400*x[:-1],-1) 
     
    80128 
    81129    def hessian_product(self, coeffs, p): 
    82         """evaluates n-dimensional Rosenbrock hessian product for the given coeffs 
    83  
    84 both p and coeffs must have len >= 2""" 
     130        """evaluates an N-dimensional Rosenbrock hessian product 
     131for p and the given coeffs 
     132 
     133The hessian product requires both p and coeffs to have len >= 2.""" 
    85134        #XXX: not well-tested 
    86135        p = atleast_1d(p) 
     
    93142        return Hp 
    94143 
     144    minimizers = [1.] #NOTE: minima in lower dimensions occur along the ridge 
    95145    pass 
    96146  
    97147 
    98148class Step(AbstractFunction): 
    99     """De Jong's step function: 
    100 The third De Jong function, Equation (19) of [2]""" 
    101  
    102     def __init__(self): 
    103         AbstractFunction.__init__(self) 
    104         return 
    105  
    106     def function(self,coeffs): 
    107         """evaluates n-dimensional De Jong step function for a list of coeffs 
    108  
    109 minimum is f(x)=0.0 at xi=-5-n where n=[0.0,0.12]""" 
     149    __doc__ = \ 
     150    """a De Jong step function generator 
     151 
     152De Jong's step function [1,2,3] has several plateaus, which pose 
     153difficulty for many optimization algorithms. Degenerate global 
     154minima occur for all x_i on the lowest plateau, with degenerate 
     155local minima on all other plateaus. 
     156 
     157The generated function f(x) is a modified version of equation (19) 
     158of [2], where len(x) >= 0. 
     159    """ + _doc 
     160    def __init__(self, ndim=5): # is n-dimensional (n=5 in ref) 
     161        AbstractFunction.__init__(self, ndim=ndim) 
     162        return 
     163 
     164    def function(self,coeffs): 
     165        """evaluates an N-dimensional step function for a list of coeffs 
     166 
     167f(x) = f_0(x) + p_i(x), with i=0,1 
     168 
     169Where for abs(x_i) <= 5.12: 
     170f_0(x) = 30 + \sum_(i=0)^(N-1) \floor x_i 
     171and for x_i > 5.12: 
     172p_0(x) = 30 * (1 + (x_i - 5.12)) 
     173and for x_i < 5.12: 
     174p_1(x) = 30 * (1 + (5.12 - x_i)) 
     175Otherwise, f_0(x) = 0 and p_i(x)=0 for i=0,1. 
     176 
     177Inspect with mystic_model_plotter using:: 
     178    mystic.models.step -b "-10:10:.2, -10:10:.2" -d -x 1 
     179 
     180The minimum is f(x)=(30 - 6*N) for all x_i=[-5.12,-5)""" 
    110181        f = 30. 
    111182        for c in coeffs: 
     
    118189        return f 
    119190 
    120 #   def forward(self,pts): 
    121 #       """n-dimensional De Jong step; returns f(xi,yi,...) for pts=(x,y,...)""" 
    122 #       return AbstractFunction.forward(self,pts) 
    123  
     191    minimizers = None #FIXME: degenerate minimum... [-5.00000001]to[-5.12000000] 
     192                 # minimum is f(x)=(30 - 6*N) for all x_i=[-5.12,-5.00000001]""" 
    124193    pass 
    125194 
    126195 
    127196class Quartic(AbstractFunction): 
    128     """De Jong's quartic function: 
    129 The modified fourth De Jong function, Equation (20) of [2]""" 
    130  
    131     def __init__(self): 
    132         AbstractFunction.__init__(self) 
    133         return 
    134  
    135     def function(self,coeffs): 
    136         """evaluates n-dimensional De Jong quartic function for a list of coeffs 
    137  
    138 minimum is f(x)=random, but statistically at xi=0""" 
     197    __doc__ = \ 
     198    """a De Jong quartic function generator 
     199 
     200De Jong's quartic function [1,2,3] is designed to test the 
     201behavior of minimizers in the presence of noise. The function's 
     202global minumum depends on the expectation value of a random 
     203variable, and also includes several randomly distributed local 
     204minima. 
     205 
     206The generated function f(x) is a modified version of equation (20) 
     207of [2], where len(x) >= 0. 
     208    """ + _doc 
     209    def __init__(self, ndim=30): # is n-dimensional (n=30 in ref) 
     210        AbstractFunction.__init__(self, ndim=ndim) 
     211        return 
     212 
     213    def function(self,coeffs): 
     214        """evaluates an N-dimensional quartic function for a list of coeffs 
     215 
     216f(x) = \sum_(i=0)^(N-1) (x_(i)^4 * (i+1) + k_i) 
     217  
     218Where k_i is a random variable with uniform distribution bounded by [0,1). 
     219 
     220Inspect with mystic_model_plotter using:: 
     221    mystic.models.quartic -b "-3:3:.1, -3:3:.1" -d -x 1 
     222 
     223The minimum is f(x)=N*E[k] for x_i=0.0, where E[k] is the expectation 
     224of k, and thus E[k]=0.5 for a uniform distribution bounded by [0,1).""" 
    139225        f = 0. 
    140226        for j, c in enumerate(coeffs): 
     
    142228        return f 
    143229 
    144 #   def forward(self,pts): 
    145 #       """n-dimensional De Jong quartic; returns f(xi,yi,...) for pts=(x,y,...)""" 
    146 #       return AbstractFunction.forward(self,pts) 
    147  
     230    minimizers = None #FIXME: statistical minimum... of f(x) <= N*0.5 
    148231    pass 
    149232 
    150233 
    151234class Shekel(AbstractFunction): 
    152     """Shekel's function: 
    153 The modified fifth De Jong function, Equation (21) of [2]""" 
    154  
    155     def __init__(self): 
    156         AbstractFunction.__init__(self) 
    157         return 
    158  
    159     def function(self,coeffs): 
    160         """evaluates 2-D Shekel's function at (x,y) 
    161  
    162 minimum is f(x)=0.0 at x(-32,-32)""" 
     235    __doc__ = \ 
     236    """a Shekel's Foxholes function generator 
     237 
     238Shekel's Foxholes function [1,2,3] has a generally flat surface 
     239with several narrow wells. The function's global minimum is at 
     240(-32, -32), with local minima at (i,j) in (-32, -16, 0, 16, 32). 
     241 
     242The generated function f(x) is a modified version of equation (21) 
     243of [2], where len(x) == 2. 
     244    """ + _doc 
     245    def __init__(self, ndim=2): 
     246        AbstractFunction.__init__(self, ndim=ndim) 
     247        return 
     248 
     249    def function(self,coeffs): 
     250        """evaluates a 2-D Shekel's Foxholes function for a list of coeffs 
     251 
     252f(x) = 1 / (0.002 + f_0(x)) 
     253 
     254Where: 
     255f_0(x) = \sum_(i=0)^(24) 1 / (i + \sum_(j=0)^(1) (x_j - a_ij)^(6)) 
     256with a_ij=(-32,-16,0,16,32). 
     257for j=0 and i=(0,1,2,3,4), a_i0=a_k0 with k=i \mod 5 
     258also j=1 and i=(0,5,10,15,20), a_i1=a_k1 with k=i+k' and k'=(1,2,3,4). 
     259 
     260Inspect with mystic_model_plotter using:: 
     261    mystic.models.shekel -b "-50:50:1, -50:50:1" -d -x 1 
     262 
     263The minimum is f(x)=0 for x=(-32,-32)""" 
    163264        A = [-32., -16., 0., 16., 32.] 
    164265        a1 = A * 5 
     
    168269        r = 0.0 
    169270        for i in range(25): 
    170             r += 1.0/ (1.0*i + pow(x-a1[i],6) + pow(y-a2[i],6) + 1e-15) 
     271#           r += 1.0/ (1.0*i + pow(x-a1[i],6) + pow(y-a2[i],6) + 1e-15) 
     272            z = 1.0*i + pow(x-a1[i],6) + pow(y-a2[i],6) 
     273            if z: r += 1.0/z 
     274            else: r += inf 
    171275        return 1.0/(0.002 + r) 
    172276 
    173 #   def forward(self,pts): 
    174 #       """2-D Shekel; returns f(xi,yi) for pts=(x,y)""" 
    175 #       return AbstractFunction.forward(self,pts) 
    176  
    177     pass 
     277    minimizers = [(j,i) for (i,j) in sorted(list(permutations(range(-32,33,16),2))+[(i,i) for i in range(-32,33,16)])] 
     278    pass 
     279 
     280# cleanup 
     281del _doc 
    178282 
    179283# prepared instances 
    180 rosen = Rosenbrock() 
    181 step = Step() 
    182 quartic = Quartic() 
    183 shekel = Shekel() 
     284sphere = Sphere().function 
     285rosen = Rosenbrock().function 
     286step = Step().function 
     287quartic = Quartic().function 
     288shekel = Shekel().function 
    184289 
    185290# End of file 
  • mystic/models/griewangk.py

    r713 r751  
    66# License: 3-clause BSD.  The full license text is available at: 
    77#  - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE 
    8 """ 
    9 Griewangk's function 
     8__doc__ = _doc = """ 
     9This is part of Storn's "Differential Evolution" test suite, as defined 
     10in [2], with 'Griewangk' function definitions drawn from [3]. 
    1011 
    1112References:: 
    12     [1] Storn, R. and Price, K. Differential Evolution - A Simple and Efficient 
    13     Heuristic for Global Optimization over Continuous Spaces. Journal of Global 
    14     Optimization 11: 341-359, 1997. 
     13    [1] Storn, R. and Price, K. "Differential Evolution - A Simple and 
     14    Efficient Heuristic for Global Optimization over Continuous Spaces" 
     15    Journal of Global Optimization 11: 341-359, 1997. 
    1516 
    16     [2] Storn, R. and Price, K. 
    17     (Same title as above, but as a technical report.) 
    18     http://www.icsi.berkeley.edu/~storn/deshort1.ps 
     17    [2] Storn, R. and Price, K. "Differential Evolution - A Simple and 
     18    Efficient Heuristic for Global Optimization over Continuous Spaces" 
     19    TR-95-012, ICSI, 1995. http://www.icsi.berkeley.edu/~storn/TR-95-012.pdf 
     20 
     21    [3] Griewangk, A.O. "Generalized Descent for Global Optimization" 
     22    Journal of Optimization Theory and Applications 34: 11-39, 1981. 
    1923""" 
    2024from abstract_model import AbstractFunction 
     
    2428 
    2529class Griewangk(AbstractFunction): 
    26     """Griewangk function: 
    27 a multi-minima function, Equation (23) of [2]""" 
     30    __doc__ = \ 
     31    """a Griewangk's function generator 
    2832 
    29     def __init__(self): 
    30         AbstractFunction.__init__(self) 
     33Griewangk's function [1,2,3] is a multi-dimensional cosine 
     34function that provides several periodic local minima, with 
     35the global minimum at the origin. The local minima are  
     36fractionally more shallow than the global minimum, such that 
     37when viewed at a very coarse scale the function appears as 
     38a multi-dimensional parabola similar to De Jong's sphere. 
     39 
     40The generated function f(x) is a modified version of equation (23) 
     41of [2], where len(x) >= 0. 
     42    """ + _doc 
     43    def __init__(self, ndim=10): # is n-dimensional (n=10 in ref) 
     44        AbstractFunction.__init__(self, ndim=ndim) 
    3145        return 
    3246 
    3347    def function(self,coeffs): 
    34         """evaluates the Griewangk function for a list of coeffs 
     48        """evaluates an N-dimensional Griewangk's function for a list of coeffs 
    3549 
    36 minimum is f(x)=0.0 at xi=0.0""" 
    37         # ensure that there are 10 coefficients 
    38         x = [0]*10 
    39         x[:len(coeffs)]=coeffs 
     50f(x) = f_0(x) - f_1(x) + 1 
     51 
     52Where: 
     53f_0(x) = \sum_(i=0)^(N-1) x_(i)^(2) / 4000. 
     54and: 
     55f_1(x) = \prod_(i=0)^(N-1) \cos( x_i / (i+1)^(1/2) ) 
     56 
     57Inspect with mystic_model_plotter using:: 
     58    mystic.models.griewangk -b "-10:10:.1, -10:10:.1" -d -x 5 
     59 
     60The minimum is f(x)=0.0 for x_i=0.0""" 
    4061       #x = asarray(x) #XXX: converting to numpy.array slows by 10x 
    41  
    42         term1 = sum([c*c for c in x])/4000 
     62        term1 = sum([c*c for c in coeffs])/4000. 
    4363        term2 = 1 
    44         for i in range(10): 
    45             term2 = term2 * cos( x[i] / sqrt(i+1.0) ) 
     64        for i in range(len(coeffs)): 
     65            term2 = term2 * cos( coeffs[i] / sqrt(i+1.0) ) 
    4666        return term1 - term2 + 1 
    4767 
    4868 
    49 #   def forward(self,pts): 
    50 #       """10-D Griewangk; returns f(xi,yi,...) for pts=(x,y,...)""" 
    51 #       return AbstractFunction.forward(self,pts) 
    52  
     69    minimizers = [0.] #XXX: there are many periodic local minima 
    5370    pass 
    5471 
     72# cleanup 
     73del _doc 
    5574 
    5675# prepared instances 
    57 griewangk = Griewangk() 
     76griewangk = Griewangk().function 
    5877 
    5978# End of file 
  • mystic/models/poly.py

    r713 r751  
    1010 
    1111References:: 
    12     [1] Storn, R. and Price, K. Differential Evolution - A Simple and Efficient 
    13     Heuristic for Global Optimization over Continuous Spaces. Journal of Global 
    14     Optimization 11: 341-359, 1997. 
     12    [1] Storn, R. and Price, K. "Differential Evolution - A Simple and 
     13    Efficient Heuristic for Global Optimization over Continuous Spaces" 
     14    Journal of Global Optimization 11: 341-359, 1997. 
    1515 
    16     [2] Storn, R. and Price, K. 
    17     (Same title as above, but as a technical report.) 
    18     http://www.icsi.berkeley.edu/~storn/deshort1.ps 
     16    [2] Storn, R. and Price, K. "Differential Evolution - A Simple and 
     17    Efficient Heuristic for Global Optimization over Continuous Spaces" 
     18    TR-95-012, ICSI, 1995. http://www.icsi.berkeley.edu/~storn/TR-95-012.pdf 
     19 
     20    [3] Storn, R. "Constrained Optimization" Dr. Dobb's Journal, May, 
     21    119-123, 1995. 
    1922""" 
    2023from abstract_model import AbstractModel 
  • mystic/models/trott.py

    r713 r751  
    66# License: 3-clause BSD.  The full license text is available at: 
    77#  - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE 
    8 """ 
    9 the fOsc3D Mathematica function 
     8__doc__ = _doc = """ 
     9This is drawn from the Mathematica GuideBook's example suite, with the 
     10'fOsc3D' function definition found in [1]. 
    1011 
    1112References:: 
    12     [4] Mathematica guidebook 
     13    [1] Trott, M. "The Mathematica GuideBook for Numerics", Springer-Verlag, 
     14    New York, 2006. 
    1315""" 
    1416from abstract_model import AbstractFunction 
     
    1719 
    1820class fOsc3D(AbstractFunction): 
    19     """fOsc3D Mathematica function: 
    20 fOsc3D[x_,y_] := -4 Exp[(-x^2 - y^2)] + Sin[6 x] Sin[5 y]""" 
     21    __doc__ = \ 
     22    """a fOsc3D function generator 
    2123 
    22     def __init__(self): 
    23         AbstractFunction.__init__(self) 
     24A fOsc3D function [1] for positive x_1 values yields 
     25small sinusoidal oscillations on a flat plane, where 
     26a sinkhole containing the global minimum and a few local 
     27minima is found in a small region near the origin. 
     28For negative x_1 values, a parabolic penalty is applied 
     29that decreases as the x_1 appoaches zero. 
     30 
     31The generated function f(x) is identical to equation (75) 
     32of section 1.10 of [1], and requires len(x) == 2. 
     33    """ + _doc 
     34    def __init__(self, ndim=2): # is 2-dimensional 
     35        AbstractFunction.__init__(self, ndim=ndim) 
    2436        return 
    2537 
     
    2739        """evaluates the fOsc3D function for a list of coeffs 
    2840 
    29 minimum is f(x)=? at x=(?,?)""" 
     41f(x) = f_0(x) + p(x) 
     42 
     43Where: 
     44f_0(x) = -4 * \exp(-x_(0)^2 - x_(1)^2) + \sin(6*x_(0)) * \sin(5*x_(1)) 
     45with for x_1 < 0: 
     46p(x) = 100.*x_(1)^2 
     47and otherwise: 
     48p(x) = 0. 
     49 
     50Inspect with mystic_model_plotter using:: 
     51    mystic.models.fosc3d -b "-5:5:.1, 0:5:.1" -d 
     52 
     53The minimum is f(x)=-4.501069742528923 at x=(-0.215018, 0.240356)""" 
    3054        x,y = coeffs 
    3155        func =  -4. * exp( -x*x - y*y ) + sin(6. * x) * sin(5. *y) 
     
    3458        return func + penalty 
    3559 
    36 #   def forward(self,pts): 
    37 #       """2-D fOsc3D; returns f(xi,yi) for pts=(x,y)""" 
    38 #       return AbstractFunction.forward(self,pts) 
    39  
     60    minimizers = [(-0.215018, 0.240356)] #XXX: there are many local minima 
    4061    pass 
    4162 
     63# cleanup 
     64del _doc 
    4265 
    4366# prepared instances 
    44 fosc3d = fOsc3D() 
     67fosc3d = fOsc3D().function 
    4568 
    4669# End of file 
  • mystic/models/wavy.py

    r726 r751  
    66# License: 3-clause BSD.  The full license text is available at: 
    77#  - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE 
    8 """ 
    9 simple sine-based multi-minima functions 
     8__doc__ = _doc = """ 
     9Multi-minima example functions with vector outputs, which require 
     10a 'reducing' function to provide scalar return values. 
    1011 
    1112References:: 
     
    1819from numpy import sin, pi 
    1920 
    20 class Wavy1(AbstractFunction): 
    21     """Wavy function #1: 
    22 a simple multi-minima function""" 
     21class Wavy1(AbstractFunction): #XXX: not a standard test function...? 
     22    __doc__ = \ 
     23    """a wavy1 function generator 
    2324 
    24     def __init__(self): 
    25         AbstractFunction.__init__(self) 
     25A wavy1 function has a vector return value, and oscillates 
     26similarly to x+\sin(x) in each direction. When a reduction 
     27function, like 'numpy.add' is applied, the surface can be 
     28visualized. The global minimum is at the center of a 
     29cross-hairs running along x_i = -pi, with periodic local 
     30minima in each direction. 
     31 
     32The generated function f(x) requires len(x) > 0, and a 
     33reducing function for use in most optimizers. 
     34    """ + _doc 
     35    def __init__(self, ndim=2): # is n-dimensional 
     36        AbstractFunction.__init__(self, ndim=ndim) 
    2637        return 
    2738 
    2839    def function(self,coeffs): 
    29         """evaluates the Wavy1 function for a list of coeffs 
     40        """evaluates the wavy1 function for a list of coeffs 
    3041 
    31 minimum is f(x)=0.0 at xi=-3.141592653589793""" 
     42f(x) = \abs(x + 3*\sin(x + \pi) + \pi) 
     43 
     44Inspect with mystic_model_plotter using:: 
     45    mystic.models.wavy1 -b "-20:20:.5, -20:20:.5" -d -r numpy.add 
     46 
     47The minimum is f(x)=0.0 at x_i=-pi for all i""" 
    3248        x = asarray(coeffs) #XXX: must be numpy.array 
    3349        return abs(x+3.*sin(x+pi)+pi) 
    3450 
    35 #   def forward(self,pts): 
    36 #       """n-D Wavy; returns f(xi,yi,...) for pts=(x,y,...)""" 
    37 #       return AbstractFunction.forward(self,pts) 
    38  
     51    minimizers = [-pi] 
    3952    pass 
    4053 
    4154 
    42 class Wavy2(Wavy1): 
    43     """Wavy function #2: 
    44 a simple multi-minima function""" 
     55class Wavy2(AbstractFunction): #XXX: not a standard test function...? 
     56    """a wavy2 function generator 
    4557 
    46     def __init__(self): 
    47         Wavy1.__init__(self) 
     58A wavy2 function has a vector return value, and oscillates 
     59similarly to \sin(x) in each direction. When a reduction 
     60function, like 'numpy.add' is applied, the surface can be 
     61visualized. There are degenerate global minima which are 
     62periodic at 2*\pi, and similarly periodic local minima 
     63at nearly the same location and magnitude. 
     64 
     65The generated function f(x) requires len(x) > 0, and a 
     66reducing function for use in most optimizers. 
     67    """ + _doc 
     68    def __init__(self, ndim=2): # is n-dimensional 
     69        AbstractFunction.__init__(self, ndim=ndim) 
    4870        return 
    4971 
    5072    def function(self,coeffs): 
    51         """evaluates the Wavy2 function for a list of coeffs 
     73        """evaluates the wavy2 function for a list of coeffs 
    5274 
    53 (degenerate) minimum is f(x)=-6.9 at xi=-26.92""" 
     75f(x) = 4*\sin(x)+\sin(4*x)+\sin(8*x)+\sin(16*x)+\sin(32*x)+\sin(64*x) 
     76 
     77Inspect with mystic_model_plotter using:: 
     78    mystic.models.wavy2 -b "-10:10:.2, -10:10:.2" -d -r numpy.add 
     79 
     80The function has degenerate global minima of f(x)=-6.987594 
     81at x_i = 4.489843526 + 2*k*pi for all i, and k is an integer""" 
    5482        x = asarray(coeffs) #XXX: must be a numpy.array 
    55         return 4 *sin(x)+sin(4*x) + sin(8*x)+sin(16*x)+sin(32*x)+sin(64*x) 
     83        return 4*sin(x)+sin(4*x)+sin(8*x)+sin(16*x)+sin(32*x)+sin(64*x) 
    5684 
     85    minimizers = None #FIXME: degenerate minimum... 
     86                      # minimum is ??? 
    5787    pass 
    5888 
     89# cleanup 
     90del _doc 
    5991 
    6092# prepared instances 
    61 wavy1 = Wavy1() 
    62 wavy2 = Wavy2() 
    63  
     93wavy1 = Wavy1().function 
     94wavy2 = Wavy2().function 
    6495 
    6596# End of file 
  • mystic/models/zimmermann.py

    r713 r751  
    66# License: 3-clause BSD.  The full license text is available at: 
    77#  - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE 
    8 """ 
    9 Zimmermann's function 
     8__doc__ = _doc = """ 
     9This is part of Storn's "Differential Evolution" test suite, as defined 
     10in [2], with 'Zimmermann' function definitions drawn from [3]. 
    1011 
    1112References:: 
    12     [1] Storn, R. and Price, K. Differential Evolution - A Simple and Efficient 
    13     Heuristic for Global Optimization over Continuous Spaces. Journal of Global 
    14     Optimization 11: 341-359, 1997. 
     13    [1] Storn, R. and Price, K. "Differential Evolution - A Simple and 
     14    Efficient Heuristic for Global Optimization over Continuous Spaces" 
     15    Journal of Global Optimization 11: 341-359, 1997. 
    1516 
    16     [2] Storn, R. and Price, K. 
    17     (Same title as above, but as a technical report.) 
    18     http://www.icsi.berkeley.edu/~storn/deshort1.ps 
     17    [2] Storn, R. and Price, K. "Differential Evolution - A Simple and 
     18    Efficient Heuristic for Global Optimization over Continuous Spaces" 
     19    TR-95-012, ICSI, 1995. http://www.icsi.berkeley.edu/~storn/TR-95-012.pdf 
     20 
     21    [3] Zimmermann, W. "Operations Research" Oldenbourg Munchen, Wien, 1990. 
    1922""" 
    2023from abstract_model import AbstractFunction 
    2124 
    2225class Zimmermann(AbstractFunction): 
    23     """Zimmermann function: 
    24 a non-continuous function, Equation (24-26) of [2]""" 
     26    __doc__ = \ 
     27    """a Zimmermann function generator 
    2528 
    26     def __init__(self): 
    27         AbstractFunction.__init__(self) 
     29A Zimmermann function [1,2,3] poses difficulty for minimizers 
     30as the minimum is located at the corner of the constrained region. 
     31A penalty is applied to all values outside the constrained region, 
     32creating a local minimum. 
     33 
     34The generated function f(x) is a modified version of equation (24-26) 
     35of [2], and requires len(x) == 2. 
     36    """ + _doc 
     37    def __init__(self, ndim=2): 
     38        AbstractFunction.__init__(self, ndim=ndim) 
    2839        return 
    2940 
    3041    def function(self,coeffs): 
    31         """evaluates the Zimmermann function for a list of coeffs 
     42        """evaluates a Zimmermann function for a list of coeffs 
    3243 
    33 minimum is f(x)=0.0 at x=(7.0,2.0)""" 
     44f(x) = max(f_0(x), p_i(x)), with i = 0,1,2,3 
     45 
     46Where: 
     47f_0(x) = 9 - x_0 - x_1 
     48with for x_0 < 0: 
     49p_0(x) = -100 * x_0 
     50and for x_1 < 0: 
     51p_1(x) = -100 * x_1 
     52and for c_2(x) > 16 and c_3(x) > 14: 
     53p_i(x) = 100 * c_i(x), with i = 2,3 
     54c_2(x) = (x_0 - 3)^2 + (x_1 - 2)^2 
     55c_3(x) = x_0 * x_1 
     56Otherwise, p_i(x)=0 for i=0,1,2,3 and c_i(x)=0 for i=2,3. 
     57 
     58Inspect with mystic_model_plotter using:: 
     59    mystic.models.zimmermann -b "-5:10:.1, -5:10:.1" -d -x 1 
     60 
     61The minimum is f(x)=0.0 at x=(7.0,2.0)""" 
    3462        x0, x1 = coeffs #must provide 2 values (x0,y0) 
    3563        f8 = 9 - x0 - x1 
     64        #XXX: apply penalty p(k) = 100 + 100*k; k = |f(x) - c(x)| 
    3665        c0,c1,c2,c3 = 0,0,0,0 
    3766        if x0 < 0: c0 = -100 * x0 
     
    4271        return max(f8,c0,c1,c2,c3) 
    4372 
    44 #   def forward(self,pts): 
    45 #       """2-D Zimmermann; returns f(xi,yi) for pts=(x,y)""" 
    46 #       return AbstractFunction.forward(self,pts) 
    47  
     73    minimizers = [(7., 2.), (2.35477650,  5.94832200)] 
     74   #minima = [0.0, 0.69690150] 
    4875    pass 
    4976 
     77# cleanup 
     78del _doc 
    5079 
    5180# prepared instances 
    52 zimmermann = Zimmermann() 
     81zimmermann = Zimmermann().function 
    5382 
    5483# End of file 
  • mystic/scripts/mystic_model_plotter.py

    r747 r751  
    170170    else: 
    171171        raise ValueError("invalid format string: '%s'" % ','.join(option)) 
     172    if not x.size or not y.size: 
     173        raise ValueError("invalid format string: '%s'" % ','.join(option)) 
    172174    return x,y 
    173175 
     
    344346    parser = OptionParser(usage=__doc__) 
    345347    parser.add_option("-b","--bounds",action="store",dest="bounds",\ 
    346                       metavar="STR",default="0:1:.1, 0:1:.1", 
     348                      metavar="STR",default="-5:5:.1, -5:5:.1", 
    347349                      help="indicator string to set plot bounds and density") 
    348350    parser.add_option("-l","--label",action="store",dest="label",\ 
     
    386388      options = parsed_opts.bounds  # format is "-1:10:.1, -1:10:.1, 1.0" 
    387389    except: 
    388       options = "0:1:.1, 0:1:.1" 
     390      options = "-5:5:.1, -5:5:.1" 
    389391 
    390392    try: # plot using filled contours 
  • mystic/tests/solver_test_suite.py

    r735 r751  
    16991699            x1 = x[0] 
    17001700            x2 = x[1] 
    1701             return -20.*sin(0.1 + ((x1 - 4.)**2 + (x2 - 4.)**2)**(0.5))/   \ 
    1702                    (0.1 + ((x1 - 4.)**2 + (x2 - 4.)**2)**0.5) 
     1701            return -20.*sin((0.1 + (x1 - 4.)**2 + (x2 - 4.)**2)**(0.5))/   \ 
     1702                   ((0.1 + (x1 - 4.)**2 + (x2 - 4.)**2)**0.5) 
    17031703        self.costfunction = venkataraman_91 
    17041704        self.ND = 2 
Note: See TracChangeset for help on using the changeset viewer.