Changeset 31df0c9 in sasmodels for sasmodels/compare.py


Ignore:
Timestamp:
Aug 1, 2017 4:38:47 PM (7 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:
1511c37c
Parents:
d49ca5c
Message:

tuned random model generation for more models

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    r109d963 r31df0c9  
    270270    Randomize a single parameter. 
    271271    """ 
     272    # Set the amount of polydispersity/angular dispersion, but by default pd_n 
     273    # is zero so there is no polydispersity.  This allows us to turn on/off 
     274    # pd by setting pd_n, and still have randomly generated values 
    272275    if name.endswith('_pd'): 
    273276        par = model_info.parameters[name[:-3]] 
     
    279282            return np.random.beta(1.5, 7) 
    280283 
     284    # pd is selected globally rather than per parameter, so set to 0 for no pd 
     285    # In particular, when multiple pd dimensions, want to decrease the number 
     286    # of points per dimension for faster computation 
    281287    if name.endswith('_pd_n'): 
    282         # let pd be selected globally rather than per parameter 
    283288        return 0 
    284289 
     290    # Don't mess with distribution type for now 
    285291    if name.endswith('_pd_type'): 
    286         # Don't mess with distribution type for now 
    287292        return 'gaussian' 
    288293 
     294    # type-dependent value of number of sigmas; for gaussian use 3. 
    289295    if name.endswith('_pd_nsigma'): 
    290         # type-dependent value; for gaussian use 3. 
    291296        return 3. 
    292297 
     298    # background in the range [0.01, 1] 
    293299    if name == 'background': 
    294         return np.random.uniform(0, 1) 
    295  
     300        return 10**np.random.uniform(-2, 0) 
     301 
     302    # scale defaults to 0.1% to 30% volume fraction 
    296303    if name == 'scale': 
    297         return 10**np.random.uniform(-5,0) 
    298  
     304        return 10**np.random.uniform(-3, -0.5) 
     305 
     306    # If it is a list of choices, pick one at random with equal probability 
     307    # In practice, the model specific random generator will override. 
    299308    par = model_info.parameters[name] 
    300309    if len(par.limits) > 2:  # choice list 
    301310        return np.random.randint(len(par.limits)) 
    302311 
     312    # If it is a fixed range, pick from it with equal probability. 
     313    # For logarithmic ranges, the model will have to override. 
    303314    if np.isfinite(par.limits).all(): 
    304315        return np.random.uniform(*par.limits) 
    305316 
     317    # If the paramter is marked as an sld use the range of neutron slds 
     318    # Should be doing something with randomly selected contrast matching 
     319    # but for now use random contrasts.  Since real data is contrast-matched, 
     320    # this will favour selection of hollow models when they exist. 
    306321    if par.type == 'sld': 
    307322        # Range of neutron SLDs 
    308323        return np.random.uniform(-0.5, 12) 
    309324 
     325    # Guess at the random length/radius/thickness.  In practice, all models 
     326    # are going to set their own reasonable ranges. 
    310327    if par.type == 'volume': 
    311328        if ('length' in par.name or 
    312329                'radius' in par.name or 
    313330                'thick' in par.name): 
    314             return 10**np.random.uniform(2,4) 
    315  
     331            return 10**np.random.uniform(2, 4) 
     332 
     333    # In the absence of any other info, select a value in [0, 2v], or 
     334    # [-2|v|, 2|v|] if v is negative, or [0, 1] if v is zero.  Mostly the 
     335    # model random parameter generators will override this default. 
    316336    low, high = parameter_range(par.name, value) 
    317337    limits = (max(par.limits[0], low), min(par.limits[1], high)) 
Note: See TracChangeset for help on using the changeset viewer.