Changeset 158cee4 in sasmodels


Ignore:
Timestamp:
Oct 18, 2016 10:28:25 AM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
3ac4e1b
Parents:
b6f10d8
Message:

sascomp: apply constraints on random parameters before evaluating expressions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    rb6f10d8 r158cee4  
    320320        name = name.split('*')[0] 
    321321 
    322     if name == 'capped_cylinder' and pars['radius_cap'] < pars['radius']: 
    323         pars['radius'], pars['radius_cap'] = pars['radius_cap'], pars['radius'] 
    324     if name == 'barbell' and pars['radius_bell'] < pars['radius']: 
    325         pars['radius'], pars['radius_bell'] = pars['radius_bell'], pars['radius'] 
    326  
    327     # Limit guinier to an Rg such that Iq > 1e-30 (single precision cutoff) 
    328     if name == 'guinier': 
     322    if name == 'barbell': 
     323        if pars['radius_bell'] < pars['radius']: 
     324            pars['radius'], pars['radius_bell'] = pars['radius_bell'], pars['radius'] 
     325 
     326    elif name == 'capped_cylinder': 
     327        if pars['radius_cap'] < pars['radius']: 
     328            pars['radius'], pars['radius_cap'] = pars['radius_cap'], pars['radius'] 
     329 
     330    elif name == 'guinier': 
     331        # Limit guinier to an Rg such that Iq > 1e-30 (single precision cutoff) 
    329332        #q_max = 0.2  # mid q maximum 
    330333        q_max = 1.0  # high q maximum 
     
    332335        pars['rg'] = min(pars['rg'], rg_max) 
    333336 
    334     if name == 'rpa': 
     337    elif name == 'rpa': 
    335338        # Make sure phi sums to 1.0 
    336339        if pars['case_num'] < 2: 
     
    342345        for c in '1234': 
    343346            pars['Phi'+c] /= total 
     347 
     348    elif name == 'stacked_disks': 
     349        pars['n_stacking'] = math.ceil(pars['n_stacking']) 
    344350 
    345351def parlist(model_info, pars, is2d): 
     
    719725        else: 
    720726            err, errstr, errview = abs(relerr), "rel err", "log" 
    721         #sorted = np.sort(err.flatten()) 
    722         #cutoff = sorted[int(sorted.size*0.95)] 
    723         #err[err>cutoff] = cutoff 
     727        if 0:  # 95% cutoff 
     728            sorted = np.sort(err.flatten()) 
     729            cutoff = sorted[int(sorted.size*0.95)] 
     730            err[err>cutoff] = cutoff 
    724731        #err,errstr = base/comp,"ratio" 
    725732        plot_theory(data, None, resid=err, view=errview, use_data=False) 
     
    965972        if model_info != model_info2: 
    966973            pars2 = randomize_pars(model_info2, pars2, seed=opts['seed']) 
     974            # Share values for parameters with the same name 
     975            for k, v in pars.items(): 
     976                if k in pars2: 
     977                    pars2[k] = v 
    967978        else: 
    968979            pars2 = pars.copy() 
     980        constrain_pars(model_info, pars) 
     981        constrain_pars(model_info2, pars2) 
    969982        print("Randomize using -random=%i"%opts['seed']) 
    970983    if opts['mono']: 
     
    10161029    pars2.update(presets2)  # set value after random to control value 
    10171030    #import pprint; pprint.pprint(model_info) 
    1018     constrain_pars(model_info, pars) 
    1019     constrain_pars(model_info2, pars2) 
    10201031 
    10211032    same_model = name == name2 and pars == pars 
Note: See TracChangeset for help on using the changeset viewer.