Changeset 853


Ignore:
Timestamp:
12/30/15 09:13:52 (5 months ago)
Author:
mmckerns
Message:

clarify 'combine' and provide new example using combine

Location:
mystic
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • mystic/mystic/constraints.py

    r852 r853  
    438438    args -- arguments for the penalty function [default: ()] 
    439439    kwds -- keyword arguments for the penalty function [default: {}] 
    440     k -- penalty multiplier 
    441     h -- iterative multiplier 
     440    k -- penalty multiplier [default: 1] 
     441    h -- iterative multiplier [default: 5] 
     442 
     443NOTE: The defaults provide a linear combination of the individual penalties 
     444    without any scaling. A different ptype (from 'mystic.penalty') will 
     445    apply a nonlinear scaling to the combined penalty, while a different 
     446    k will apply a linear scaling. 
    442447 
    443448NOTE: This function is also useful for combining constraints solvers 
     
    445450    Constraints solvers must first be converted to penalty functions 
    446451    (i.e. with 'as_penalty'), then combined, then can be converted to 
    447     a constraints solver (i.e. with `as_constraint'). The resulting 
     452    a constraints solver (i.e. with 'as_constraint'). The resulting 
    448453    constraints will likely be more expensive to evaluate and less 
    449454    accurate than writing the constraints solver from scratch. 
     
    453458   #if k is not None: settings['k'] = k 
    454459   #if h is not None: settings['h'] = h 
     460    k = settings.setdefault('k', 1) 
     461    if k is None: del settings['k'] 
    455462    ptype = settings.pop('ptype', None) 
    456463    if ptype is None: 
  • mystic/tests/test_combine.py

    r852 r853  
    2727    p3 = lambda x: abs(x3 - f3(x)) 
    2828    p = (p1,p2,p3) 
    29 #   p = [ptype(pi)(lambda x:0.) for pi in p] 
    30 #   ptype = None 
    31     penalty = combine(*p, k=k, ptype=ptype) 
     29    p = [ptype(pi)(lambda x:0.) for pi in p] 
     30    penalty = combine(*p, k=k) 
    3231    constraint = as_constraint(penalty, solver=solver) 
    3332 
     
    5554    c = (c1,c2,c3) 
    5655     
     56    k=1 
    5757    solver = 'buckshot' #'diffev' 
    5858    ptype = linear_equality #quadratic_equality 
    5959 
    6060    p = [as_penalty(ci, ptype) for ci in c] 
    61     penalty = combine(*p, k=1, ptype=linear_equality) 
     61    penalty = combine(*p, k=k) 
    6262    constraint = as_constraint(penalty, solver=solver) 
    6363 
Note: See TracChangeset for help on using the changeset viewer.