Changeset 338


Ignore:
Timestamp:
07/21/10 09:10:59 (6 years ago)
Author:
altafang
Message:

Found some good sources of optimization test problems, and translated some of them into Python.

Location:
branches/alta/mystic-0.2a1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/alta/mystic-0.2a1/test_constraints_cvxopt_qp.py

    r334 r338  
    3636      x + y == 1.0}, {x, y}] 
    3737    Solution: {1.875, {x -> 0.25, y -> 0.75}} 
     38 
     39    OpenOpt code and results: 
     40    ------------------------- 
     41    from FuncDesigner import * 
     42    from openopt import NLP 
     43    x1, x2 = oovars ('x1', 'x2') 
     44    f = 2.*x1**2 + x2**2 + x1*x2 + x1 + x2 
     45    constraints = [x1 >= 0.0, x2 >= 0.0, x1 + x2 == 1.0] 
     46    x0 = {x1:1.,x2: 1.} 
     47    problem = NLP(f, x0, constraints=constraints) 
     48    soln = problem.solve('ralg') 
     49    print soln.xf 
     50    Solution: {x1: array([ 0.2500267]), x2: array([ 0.7499733])} 
    3851""" 
    3952 
  • branches/alta/mystic-0.2a1/test_problems_unconstrained.py

    r323 r338  
    44""" 
    55from math import * 
     6import numpy 
    67 
    78def peaks(x_vector): 
     
    4647 
    4748#print venkataraman_corner([1., 1.]) 
     49 
     50#--------------------------------------------------------------------- 
     51# Below: functions from http://www.geatbx.com/docu/fcnindex-01.html 
     52# that are not already in mystic.models. 
     53# Another good source of test problems:  
     54# http://www-optima.amp.i.kyoto-u.ac.jp/member/student/hedar/Hedar_files/TestGO.htm 
     55 
     56def rastrigin(x): 
     57    """Rastrigin's function. Global minimum at xi=0, f(x)=0. Contains 
     58many local minima regularly distributed. Can be n-dimensional. 
     59xi in [-5.12, 5.12] 
     60http://www.geatbx.com/docu/fcnindex-01.html""" 
     61    x = numpy.asarray(x) 
     62    return 10.*len(x) + numpy.sum(x**2 - 10*numpy.cos(2.*pi*x)) 
     63 
     64#print 'Rastrigin:', rastrigin([0., 0.]) 
     65 
     66def schwefel(x): 
     67    """'Schwefel's function [Sch81] is deceptive in that the global minimum is  
     68geometrically distant, over the parameter space, from the next best local  
     69minima. Therefore, the search algorithms are potentially prone to convergence  
     70in the wrong direction.' - http://www.geatbx.com/docu/fcnindex-01.html 
     71xi in [-500, 500] 
     72global minimum: f(x) = -n*418.9829, xi=420.9687 
     73Can be n-dimensional. 
     74""" 
     75    x = numpy.asarray(x) 
     76    return numpy.sum(-x*numpy.sin(abs(x)**0.5)) 
     77 
     78#print "Schwefel:", schwefel([420.9687, 420.9687, 420.9687]) 
     79#print -3.*418.9829 
     80 
     81def ackley(x): 
     82    """Ackley's Path function. 
     83xi in [-32.768., 32.768] 
     84global minimum f(x)=0 at xi=0 
     85can be n-dimensional. http://www.geatbx.com/docu/fcnindex-01.html""" 
     86    x = numpy.asarray(x) 
     87    n = len(x) 
     88    return -20.*exp(-0.2*sqrt(1./n*numpy.sum(x**2))) - exp(1./n*numpy.sum( 
     89            numpy.cos(2.*pi*x))) + 20. + exp(1) 
     90 
     91#print "Ackley:", ackley([0., 0.]) 
     92 
     93def easom(x): 
     94    """'The Easom function [Eas90] is a unimodal test function, where the global  
     95minimum has a small area relative to the search space. The function was  
     96inverted for minimization.' - http://www.geatbx.com/docu/fcnindex-01.html 
     97Global minimum f(x1, x2) = -1 at (x1, x2) = (pi, pi) 
     98xi in -100, 100. 2-dimensional.""" 
     99    x1 = x[0] 
     100    x2 = x[1] 
     101    return -cos(x1)*cos(x2)*exp(-(x1-pi)**2 + (x2 - pi)**2) 
     102 
     103#print "Easom:", easom([pi, pi]) 
     104 
Note: See TracChangeset for help on using the changeset viewer.