Changeset 109d963 in sasmodels
- Timestamp:
- Jul 31, 2017 5:59:10 PM (7 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- d49ca5c
- Parents:
- 48462b0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
r48462b0 r109d963 318 318 return np.random.uniform(*limits) 319 319 320 321 def randomize_pars(model_info, pars, seed=None): 322 # type: (ModelInfo, ParameterSet, int) -> ParameterSet 320 def _random_pd(model_info, pars): 321 pd = [p for p in model_info.parameters.kernel_parameters if p.polydisperse] 322 pd_volume = [] 323 pd_oriented = [] 324 for p in pd: 325 if p.type == 'orientation': 326 pd_oriented.append(p.name) 327 elif p.length_control is not None: 328 n = pars.get(p.length_control, 1) 329 pd_volume.extend(p.name+str(k+1) for k in range(n)) 330 elif p.length > 1: 331 pd_volume.extend(p.name+str(k+1) for k in range(p.length)) 332 else: 333 pd_volume.append(p.name) 334 u = np.random.rand() 335 n = len(pd_volume) 336 if u < 0.01 or n < 1: 337 pass # 1% chance of no polydispersity 338 elif u < 0.86 or n < 2: 339 pars[np.random.choice(pd_volume)+"_pd_n"] = 35 340 elif u < 0.99 or n < 3: 341 choices = np.random.choice(len(pd_volume), size=2) 342 pars[pd_volume[choices[0]]+"_pd_n"] = 25 343 pars[pd_volume[choices[1]]+"_pd_n"] = 10 344 else: 345 choices = np.random.choice(len(pd_volume), size=3) 346 pars[pd_volume[choices[0]]+"_pd_n"] = 25 347 pars[pd_volume[choices[1]]+"_pd_n"] = 10 348 pars[pd_volume[choices[2]]+"_pd_n"] = 5 349 if pd_oriented: 350 pars['theta_pd_n'] = 20 351 if np.random.rand() < 0.1: 352 pars['phi_pd_n'] = 5 353 if np.random.rand() < 0.1: 354 pars['psi_pd_n'] = 5 355 356 ## Show selected polydispersity 357 #for name, value in pars.items(): 358 # if name.endswith('_pd_n') and value > 0: 359 # print(name, value, pars.get(name[:-5], 0), pars.get(name[:-2], 0)) 360 361 362 def randomize_pars(model_info, pars): 363 # type: (ModelInfo, ParameterSet) -> ParameterSet 323 364 """ 324 365 Generate random values for all of the parameters. … … 334 375 if model_info.random is not None: 335 376 random_pars.update(model_info.random()) 336 377 _random_pd(model_info, random_pars) 337 378 return random_pars 379 338 380 339 381 def constrain_pars(model_info, pars): … … 348 390 Warning: this updates the *pars* dictionary in place. 349 391 """ 392 # TODO: move the model specific code to the individual models 350 393 name = model_info.id 351 394 # if it is a product model, then just look at the form factor since … … 446 489 pars = pars.copy() 447 490 for p in pars: 448 if p.endswith("_pd_n"): pars[p] = 0 491 if p.endswith("_pd_n"): 492 pars[p] = 0 449 493 return pars 450 494
Note: See TracChangeset
for help on using the changeset viewer.