Changeset 765eb0e in sasmodels


Ignore:
Timestamp:
Sep 11, 2017 5:42:31 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:
2ad5d30
Parents:
ce8c388
Message:

allow random generation of parameters for product and mixture models

Location:
sasmodels
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    rd9ec8f9 r765eb0e  
    8888    -magnetic/-nonmagnetic* suppress magnetism 
    8989    -accuracy=Low accuracy of the resolution calculation Low, Mid, High, Xhigh 
     90    -neval=1 sets the number of evals for more accurate timing 
    9091 
    9192    === precision options === 
     
    10131014    'magnetic', 'nonmagnetic', 
    10141015    'accuracy=', 
     1016    'neval=',  # for timing... 
    10151017 
    10161018    # Precision options 
     
    10181020    'half', 'fast', 'single', 'double', 'single!', 'double!', 'quad!', 
    10191021    'sasview',  # TODO: remove sasview 3.x support 
    1020     'timing=', 
    10211022 
    10221023    # Output options 
     
    10681069 
    10691070    # Plug in values given in demo 
    1070     if use_demo: 
     1071    if use_demo and model_info.demo: 
    10711072        pars.update(model_info.demo) 
    10721073    return pars 
  • sasmodels/mixture.py

    r6dc78e4 r765eb0e  
    4040    # Build new parameter list 
    4141    combined_pars = [] 
    42     demo = {} 
    4342    for k, part in enumerate(parts): 
    4443        # Parameter prefix per model, A_, B_, ... 
     
    5655                p.length_control = prefix + p.length_control 
    5756            combined_pars.append(p) 
    58         demo.update((prefix+k, v) for k, v in part.demo.items() 
    59                     if k != "background") 
    60     #print("pars",combined_pars) 
    6157    parameters = ParameterTable(combined_pars) 
    6258    parameters.max_pd = sum(part.parameters.max_pd for part in parts) 
     59 
     60    def random(): 
     61        combined_pars = {} 
     62        for k, part in enumerate(parts): 
     63            prefix = chr(ord('A')+k) + '_' 
     64            pars = part.random() 
     65            combined_pars.update((prefix+k, v) for k, v in pars.items()) 
     66        return combined_pars 
    6367 
    6468    model_info = ModelInfo() 
     
    7175    model_info.category = "custom" 
    7276    model_info.parameters = parameters 
     77    model_info.random = random 
    7378    #model_info.single = any(part['single'] for part in parts) 
    7479    model_info.structure_factor = False 
     
    7984    # Remember the component info blocks so we can build the model 
    8085    model_info.composition = ('mixture', parts) 
    81     model_info.demo = demo 
    8286    return model_info 
    8387 
     
    8892        self.info = model_info 
    8993        self.parts = parts 
     94        self.dtype = parts[0].dtype 
    9095 
    9196    def make_kernel(self, q_vectors): 
  • sasmodels/product.py

    r8f04da4 r765eb0e  
    6868    translate_name = dict((old.id, new.id) for old, new 
    6969                          in zip(s_pars.kernel_parameters[1:], s_list)) 
    70     demo = {} 
    71     demo.update(p_info.demo.items()) 
    72     demo.update((translate_name[k], v) for k, v in s_info.demo.items() 
    73                 if k not in ("background", "scale") and not k.startswith(ER_ID)) 
    7470    combined_pars = p_pars.kernel_parameters + s_list 
    7571    parameters = ParameterTable(combined_pars) 
    7672    parameters.max_pd = p_pars.max_pd + s_pars.max_pd 
     73    def random(): 
     74        combined_pars = p_info.random() 
     75        s_names = set(par.id for par in s_pars.kernel_parameters[1:]) 
     76        s = s_info.random() 
     77        combined_pars.update((translate_name[k], v) 
     78                    for k, v in s_info.random().items() 
     79                    if k in s_names) 
     80        return combined_pars 
    7781 
    7882    model_info = ModelInfo() 
     
    8589    model_info.category = "custom" 
    8690    model_info.parameters = parameters 
     91    model_info.random = random 
    8792    #model_info.single = p_info.single and s_info.single 
    8893    model_info.structure_factor = False 
     
    95100    # TODO: delegate random to p_info, s_info 
    96101    #model_info.random = lambda: {} 
    97     model_info.demo = demo 
    98  
    99     ## Show the parameter table with the demo values 
     102 
     103    ## Show the parameter table 
    100104    #from .compare import get_pars, parlist 
    101105    #print("==== %s ====="%model_info.name) 
    102     #values = get_pars(model_info, use_demo=True) 
     106    #values = get_pars(model_info) 
    103107    #print(parlist(model_info, values, is2d=True)) 
    104108    return model_info 
     
    126130        self.P = P 
    127131        self.S = S 
     132        self.dtype = P.dtype 
    128133 
    129134    def make_kernel(self, q_vectors): 
Note: See TracChangeset for help on using the changeset viewer.