- Timestamp:
- 12/13/12 12:43:16 (3 years ago)
- Location:
- branches/decorate
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/decorate/constraints.py
r609 r610 1 #!/usr/bin/env python 2 1 3 # XXX: provide the below from measures, which from bounded?, and ...generic? 2 4 # XXX: with_*** is a 'wrap' constraint, what about 'nested' constraints? -
branches/decorate/penalty.py
r609 r610 1 #!/usr/bin/env python 2 3 """ 4 References: 5 [1] http://en.wikipedia.org/wiki/Penalty_method 6 [2] Applied Optimization with MATLAB Programming, by Venkataraman. 7 Wiley, 2nd edition, 2009. 8 [3] http://www.srl.gatech.edu/education/ME6103/Penalty-Barrier.ppt 9 [4] "An Augmented Lagrange Multiplier Based Method for Mixed Integer 10 Discrete Continuous Optimization and Its Applications to Mechanical 11 Design", by Kannan and Kramer. 1994. 12 """ 1 13 2 14 def with_penalty(ptype, *args, **kwds): -
branches/decorate/test_penalty.py
r609 r610 19 19 return abs(sum(x) - 5.0) 20 20 21 from mystic.solvers import fmin _powell21 from mystic.solvers import fmin 22 22 from numpy import array 23 23 x = array([1,2,3,4,5]) 24 y = fmin _powell(cost, x, penalty=penalty, disp=False)24 y = fmin(cost, x, penalty=penalty, disp=False) 25 25 26 26 assert round(mean(y)) == 5.0 … … 82 82 83 83 ndim = 3 84 constraints = as_constraint(penalty, solver='fmin _powell')84 constraints = as_constraint(penalty, solver='fmin') 85 85 #XXX: this is expensive to evaluate, as there are nested optimizations 86 86 … … 91 91 assert round(mean(_x)) == 5.0 92 92 assert round(spread(_x)) == 5.0 93 assert round(penalty(_x)) == 0.0 93 94 94 95 def cost(x): … … 96 97 97 98 npop = ndim*3 98 from mystic.solvers import fmin_powell,diffev99 from mystic.solvers import diffev 99 100 y = diffev(cost, x, npop, constraints=constraints, disp=False, gtol=10) 100 101 … … 122 123 return abs(sum(x) - 5.0) 123 124 124 from mystic.solvers import fmin _powell125 y = fmin _powell(cost, x, penalty=penalty, disp=False)125 from mystic.solvers import fmin 126 y = fmin(cost, x, penalty=penalty, disp=False) 126 127 127 128 assert round(mean(y)) == 5.0 … … 140 141 return abs(sum(x) - 5.0) 141 142 142 from mystic.solvers import fmin _powell143 from mystic.solvers import fmin 143 144 from numpy import array 144 145 x = array([1,2,3,4,5]) 145 y = fmin _powell(cost, x, penalty=penalty, disp=False)146 y = fmin(cost, x, penalty=penalty, disp=False) 146 147 147 148 assert round(mean(y)) == 5.0 -
branches/decorate/wrapper.py
r609 r610 1 #!/usr/bin/env python 2 1 3 #XXX: be mindful if the decorators restrict to functions that expect arrays 2 4 # compare against the originals for restrictions 3 5 4 6 #XXX: when_decorated registers methods to 'populate up' when is decorated ? 5 6 7 7 8 from mystic.tools import Null … … 83 84 84 85 86 def isbounded(func, x, min=None, max=None): 87 """return False if func(x) evaluates outside the bounds, True otherwise. 88 89 Inputs: 90 func -- a function of x. 91 x -- a list of parameters. 92 93 Additional Inputs: 94 min -- list of lower bounds on parameters. 95 max -- list of upper bounds on parameters. 96 """ 97 #from numpy import clip, array #XXX: numpy.clip doesn't need/use func 98 #return all(clip(x,min,max) == array(x)) 99 bound = bounded(min,max) 100 wrapped = bound(func) 101 if wrapped(x) == inf: 102 return False 103 return True 104 105 85 106 def mixedin(scale=1.0, shift=0.0, mixin=lambda x:x, normalized=False): 86 107 """build a function from the weighted sum of two functions
Note: See TracChangeset
for help on using the changeset viewer.