- Timestamp:
- 12/17/12 17:14:53 (3 years ago)
- Location:
- branches/decorate
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/decorate/symbolic.py
r611 r612 249 249 constraint = fixed.strip() 250 250 251 # Replace 'mean' with actual expression for calculating mean 251 # Replace 'range', 'mean', and 'variance' 252 if constraint.find('range') != -1: 253 constraint = constraint.replace('range', 'ptp') # spread 252 254 if constraint.find('mean') != -1: 253 constraint = constraint.replace('mean', 'average(asarray(x))') 254 # Replace 'range' with actual expression for calculating range 255 if constraint.find('range') != -1: 256 constraint = constraint.replace('range', 'max(x) - min(x)') 255 constraint = constraint.replace('mean', 'average') # mean 256 if constraint.find('variance') != -1: 257 constraint = constraint.replace('variance', 'var') # variance 257 258 #FIXME: also enable functions from mystic.math.measures ? 258 259 … … 320 321 constraint = fixed.strip() 321 322 322 # Replace 'mean' with actual expression for calculating mean 323 # Replace 'range', 'mean', and 'variance' 324 if constraint.find('range') != -1: 325 constraint = constraint.replace('range', 'ptp') # spread 323 326 if constraint.find('mean') != -1: 324 constraint = constraint.replace('mean', 'average(asarray(x))') 325 # Replace 'range' with actual expression for calculating range 326 if constraint.find('range') != -1: 327 constraint = constraint.replace('range', 'max(x) - min(x)') 327 constraint = constraint.replace('mean', 'average') # mean 328 if constraint.find('variance') != -1: 329 constraint = constraint.replace('variance', 'var') # variance 328 330 #FIXME: also enable functions from mystic.math.measures ? 329 331 -
branches/decorate/test_symbolic.py
r611 r612 22 22 23 23 24 def test_numpy_penalty(): 25 26 constraints = """ 27 mean([x1, x2, x3]) = 5.0 28 x1 = x2 + x3""" 29 30 ineq,eq = generate_conditions(constraints) 31 assert eq[0]([7,5,3]) == 0.0 32 assert eq[1]([7,4,3]) == 0.0 33 34 penalty = generate_penalty((ineq,eq)) 35 assert penalty([9.0,5,4.0]) == 100.0 36 assert penalty([7.5,4,3.5]) == 0.0 37 38 constraint = as_constraint(penalty, solver='fmin') 39 assert almostEqual(penalty(constraint([3,4,5])), 0.0, 1e-10) 40 41 24 42 if __name__ == '__main__': 25 43 test_generate_penalty() 44 test_numpy_penalty() 26 45
Note: See TracChangeset
for help on using the changeset viewer.