Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare_many.py

    rcd3dba0 re922c5d  
    99from .compare import (MODELS, randomize_model, suppress_pd, eval_sasview, 
    1010                      eval_opencl, eval_ctypes, make_data, get_demo_pars, 
    11                       columnize, constrain_pars) 
     11                      columnize) 
    1212 
    1313def get_stats(target, value, index): 
     
    3636def compare_instance(name, data, index, N=1, mono=True, cutoff=1e-5): 
    3737    model_definition = core.load_model_definition(name) 
    38     pars = get_demo_pars(model_definition) 
     38    pars = get_demo_pars(name) 
    3939    header = '\n"Model","%s","Count","%d"'%(name, N) 
    4040    if not mono: header += ',"Cutoff",%g'%(cutoff,) 
    4141    print(header) 
    4242 
     43    # Stuff the failure flag into a mutable object so we can update it from 
     44    # within the nested function.  Note that the nested function uses "pars" 
     45    # which is dynamically scoped, not lexically scoped in this context.  That 
     46    # is, pars is replaced each time in the loop, so don't assume that it is 
     47    # the default values defined above. 
    4348    def trymodel(fn, *args, **kw): 
    4449        try: 
    45             result, _ = fn(model_definition, pars_i, data, *args, **kw) 
    46         except KeyboardInterrupt: 
    47             raise 
     50            result, _ = fn(model_definition, pars, data, *args, **kw) 
    4851        except: 
    49             print >>sys.stderr, traceback.format_exc() 
    50             print >>sys.stderr, "when comparing",name,"for seed",seed 
    51             if hasattr(data, 'qx_data'): 
    52                 result = np.NaN*data.data 
    53             else: 
    54                 result = np.NaN*data.x 
     52            result = np.NaN 
     53            traceback.print_exc() 
    5554        return result 
    5655 
    5756    num_good = 0 
    5857    first = True 
    59     for k in range(N): 
    60         print >>sys.stderr, name, k 
    61         pars_i, seed = randomize_model(pars) 
    62         constrain_pars(model_definition, pars_i) 
    63         if mono: suppress_pd(pars_i) 
     58    for _ in range(N): 
     59        pars, seed = randomize_model(name, pars) 
     60        if mono: suppress_pd(pars) 
     61 
     62        # Force parameter constraints on a per-model basis. 
     63        if name in ('teubner_strey','broad_peak'): 
     64            pars['scale'] = 1.0 
     65        #if name == 'parallelepiped': 
     66        #    pars['a_side'],pars['b_side'],pars['c_side'] = \ 
     67        #        sorted([pars['a_side'],pars['b_side'],pars['c_side']]) 
     68 
    6469 
    6570        good = True 
     
    9297            good = good and (stats[0] < 1e-14) 
    9398 
    94         columns += [v for _,v in sorted(pars_i.items())] 
     99        columns += [v for _,v in sorted(pars.items())] 
    95100        if first: 
    96             print_column_headers(pars_i, labels) 
     101            print_column_headers(pars, labels) 
    97102            first = False 
    98103        if good: 
Note: See TracChangeset for help on using the changeset viewer.