Changeset 766


Ignore:
Timestamp:
10/23/14 15:06:42 (19 months ago)
Author:
mmckerns
Message:

moved corana, griewangk, and zimmermann to storn to fix pickling of models;
fixed import of corana in examples

Location:
mystic
Files:
2 deleted
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • mystic/examples/mpl_corana.py

    r736 r766  
    1515from mystic.tools import getch 
    1616 
    17 from mystic.models.corana import corana1d as Corana1 
     17from mystic.models.storn import Corana 
     18Corana1 = Corana(1) 
    1819 
    1920x = numpy.arange(-2., 2., 0.01) 
  • mystic/examples/test_corana.py

    r723 r766  
    2525random.seed(123) 
    2626 
    27 from mystic.models import corana as Corana 
    28 from mystic.models.corana import corana1d as Corana1 
     27from mystic.models import corana 
     28from mystic.models.storn import Corana as Corana1 
     29corana1 = Corana1(1) 
    2930 
    3031ND = 4 
     
    3839    solver.SetEvaluationLimits(generations=MAX_GENERATIONS) 
    3940 
    40     solver.Solve(Corana, termination=VTR(0.00000001), strategy=Rand1Exp,\ 
     41    solver.Solve(corana, termination=VTR(0.00000001), strategy=Rand1Exp,\ 
    4142                 CrossProbability=0.5, ScalingFactor=0.9) 
    4243 
     
    5859        import random 
    5960        print  "\nScipy: " 
    60         sol = fmin(Corana, [random.random() for j in range(4)], full_output=0, retall=1) 
     61        sol = fmin(corana, [random.random() for j in range(4)], full_output=0, retall=1) 
    6162        print "solution: ", sol[-1][0] 
    6263        print "\nCorana 1 with Scipy" 
    63         sol = fmin(Corana1, [random.random()], full_output=1, retall=1) 
     64        sol = fmin(corana1, [random.random()], full_output=1, retall=1) 
    6465        print "solution: ", sol[-1][0] 
    6566    except: 
  • mystic/models/__init__.py

    r752 r766  
    7676# functions 
    7777from dejong import sphere, rosen, step, quartic, shekel 
    78 from corana import corana 
     78from storn import corana, griewangk, zimmermann 
    7979from wolfram import fosc3d, nmin51 
    80 from griewangk import griewangk 
    81 from zimmermann import zimmermann 
    8280from nag import peaks 
    8381from venkataraman import venkat91 
  • mystic/models/storn.py

    r751 r766  
    88__doc__ = _doc = """ 
    99This is part of Storn's "Differential Evolution" test suite, as defined 
    10 in [2], with 'Corana' function definitions drawn from [3,4]. 
     10in [2], with 'Corana' function definitions drawn from [3,4], 'Griewangk' 
     11function definitions drawn from [5], and 'Zimmermann' function definitions 
     12drawn from [6]. 
    1113 
    1214References:: 
     
    2628    'Simulated Annealing Algorithm'" ACM Transactions on Mathematical 
    2729    Software, March, 272-280, 1987. 
     30 
     31    [5] Griewangk, A.O. "Generalized Descent for Global Optimization" 
     32    Journal of Optimization Theory and Applications 34: 11-39, 1981. 
     33 
     34    [6] Zimmermann, W. "Operations Research" Oldenbourg Munchen, Wien, 1990. 
    2835""" 
    2936from abstract_model import AbstractFunction 
    3037 
    3138from numpy import asarray 
    32 from math import pow 
     39from math import pow, cos, sqrt 
    3340from numpy import sign, floor 
    3441 
     
    94101    pass 
    95102 
     103class Griewangk(AbstractFunction): 
     104    __doc__ = \ 
     105    """a Griewangk's function generator 
     106 
     107Griewangk's function [1,2,5] is a multi-dimensional cosine 
     108function that provides several periodic local minima, with 
     109the global minimum at the origin. The local minima are  
     110fractionally more shallow than the global minimum, such that 
     111when viewed at a very coarse scale the function appears as 
     112a multi-dimensional parabola similar to De Jong's sphere. 
     113 
     114The generated function f(x) is a modified version of equation (23) 
     115of [2], where len(x) >= 0. 
     116    """ + _doc 
     117    def __init__(self, ndim=10): # is n-dimensional (n=10 in ref) 
     118        AbstractFunction.__init__(self, ndim=ndim) 
     119        return 
     120 
     121    def function(self,coeffs): 
     122        """evaluates an N-dimensional Griewangk's function for a list of coeffs 
     123 
     124f(x) = f_0(x) - f_1(x) + 1 
     125 
     126Where: 
     127f_0(x) = \sum_(i=0)^(N-1) x_(i)^(2) / 4000. 
     128and: 
     129f_1(x) = \prod_(i=0)^(N-1) \cos( x_i / (i+1)^(1/2) ) 
     130 
     131Inspect with mystic_model_plotter using:: 
     132    mystic.models.griewangk -b "-10:10:.1, -10:10:.1" -d -x 5 
     133 
     134The minimum is f(x)=0.0 for x_i=0.0""" 
     135       #x = asarray(x) #XXX: converting to numpy.array slows by 10x 
     136        term1 = sum([c*c for c in coeffs])/4000. 
     137        term2 = 1 
     138        for i in range(len(coeffs)): 
     139            term2 = term2 * cos( coeffs[i] / sqrt(i+1.0) ) 
     140        return term1 - term2 + 1 
     141 
     142 
     143    minimizers = [0.] #XXX: there are many periodic local minima 
     144    pass 
     145 
     146class Zimmermann(AbstractFunction): 
     147    __doc__ = \ 
     148    """a Zimmermann function generator 
     149 
     150A Zimmermann function [1,2,6] poses difficulty for minimizers 
     151as the minimum is located at the corner of the constrained region. 
     152A penalty is applied to all values outside the constrained region, 
     153creating a local minimum. 
     154 
     155The generated function f(x) is a modified version of equation (24-26) 
     156of [2], and requires len(x) == 2. 
     157    """ + _doc 
     158    def __init__(self, ndim=2): 
     159        AbstractFunction.__init__(self, ndim=ndim) 
     160        return 
     161 
     162    def function(self,coeffs): 
     163        """evaluates a Zimmermann function for a list of coeffs 
     164 
     165f(x) = max(f_0(x), p_i(x)), with i = 0,1,2,3 
     166 
     167Where: 
     168f_0(x) = 9 - x_0 - x_1 
     169with for x_0 < 0: 
     170p_0(x) = -100 * x_0 
     171and for x_1 < 0: 
     172p_1(x) = -100 * x_1 
     173and for c_2(x) > 16 and c_3(x) > 14: 
     174p_i(x) = 100 * c_i(x), with i = 2,3 
     175c_2(x) = (x_0 - 3)^2 + (x_1 - 2)^2 
     176c_3(x) = x_0 * x_1 
     177Otherwise, p_i(x)=0 for i=0,1,2,3 and c_i(x)=0 for i=2,3. 
     178 
     179Inspect with mystic_model_plotter using:: 
     180    mystic.models.zimmermann -b "-5:10:.1, -5:10:.1" -d -x 1 
     181 
     182The minimum is f(x)=0.0 at x=(7.0,2.0)""" 
     183        x0, x1 = coeffs #must provide 2 values (x0,y0) 
     184        f8 = 9 - x0 - x1 
     185        #XXX: apply penalty p(k) = 100 + 100*k; k = |f(x) - c(x)| 
     186        c0,c1,c2,c3 = 0,0,0,0 
     187        if x0 < 0: c0 = -100 * x0 
     188        if x1 < 0: c1 = -100 * x1 
     189        xx =  (x0-3.)*(x0-3) + (x1-2.)*(x1-2) 
     190        if xx > 16: c2 = 100 * (xx-16) 
     191        if x0 * x1 > 14: c3 = 100 * (x0*x1-14.) 
     192        return max(f8,c0,c1,c2,c3) 
     193 
     194    minimizers = [(7., 2.), (2.35477650,  5.94832200)] 
     195   #minima = [0.0, 0.69690150] 
     196    pass 
     197 
    96198# cleanup 
    97199del _doc 
     
    99201# prepared instances 
    100202corana = Corana().function 
     203griewangk = Griewangk().function 
     204zimmermann = Zimmermann().function 
    101205 
    102206# End of file 
Note: See TracChangeset for help on using the changeset viewer.