Changeset 852
- Timestamp:
- 12/30/15 06:58:34 (5 months ago)
- Location:
- mystic
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mystic/mystic/constraints.py
r851 r852 12 12 'with_mean','with_variance','with_std','with_spread','normalized', 13 13 'issolution','solve','discrete','integers','near_integers', 14 'unique','has_unique','impose_unique' ]14 'unique','has_unique','impose_unique', 'combine'] 15 15 16 16 from mystic.math.measures import * … … 426 426 427 427 return penalty 428 429 430 def combine(*penalties, **settings): #XXX: is this in the right module? 431 """combine several penalties into a single penalty function 432 433 Inputs: 434 penalties -- penalty functions (or penalty conditions) 435 436 Additional Inputs: 437 ptype -- penalty function type [default: linear_equality] 438 args -- arguments for the penalty function [default: ()] 439 kwds -- keyword arguments for the penalty function [default: {}] 440 k -- penalty multiplier 441 h -- iterative multiplier 442 443 NOTE: This function is also useful for combining constraints solvers 444 into a single constraints solver, however can not do so directly. 445 Constraints solvers must first be converted to penalty functions 446 (i.e. with 'as_penalty'), then combined, then can be converted to 447 a constraints solver (i.e. with `as_constraint'). The resulting 448 constraints will likely be more expensive to evaluate and less 449 accurate than writing the constraints solver from scratch. 450 """ 451 #k = settings.pop('k', None) 452 #h = settings.pop('h', None) 453 #if k is not None: settings['k'] = k 454 #if h is not None: settings['h'] = h 455 ptype = settings.pop('ptype', None) 456 if ptype is None: 457 from mystic.penalty import linear_equality as ptype 458 penalty = lambda x: sum(p(x) for p in penalties) 459 return ptype(penalty, **settings)(lambda x:0.) 460 #from mystic.constraints import as_constraint 461 #return as_constraint(penalty, **settings) 428 462 429 463
Note: See TracChangeset
for help on using the changeset viewer.