Changeset 31df0c9 in sasmodels for sasmodels/compare.py
- Timestamp:
- Aug 1, 2017 4:38:47 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:
- 1511c37c
- Parents:
- d49ca5c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
r109d963 r31df0c9 270 270 Randomize a single parameter. 271 271 """ 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 272 275 if name.endswith('_pd'): 273 276 par = model_info.parameters[name[:-3]] … … 279 282 return np.random.beta(1.5, 7) 280 283 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 281 287 if name.endswith('_pd_n'): 282 # let pd be selected globally rather than per parameter283 288 return 0 284 289 290 # Don't mess with distribution type for now 285 291 if name.endswith('_pd_type'): 286 # Don't mess with distribution type for now287 292 return 'gaussian' 288 293 294 # type-dependent value of number of sigmas; for gaussian use 3. 289 295 if name.endswith('_pd_nsigma'): 290 # type-dependent value; for gaussian use 3.291 296 return 3. 292 297 298 # background in the range [0.01, 1] 293 299 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 296 303 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. 299 308 par = model_info.parameters[name] 300 309 if len(par.limits) > 2: # choice list 301 310 return np.random.randint(len(par.limits)) 302 311 312 # If it is a fixed range, pick from it with equal probability. 313 # For logarithmic ranges, the model will have to override. 303 314 if np.isfinite(par.limits).all(): 304 315 return np.random.uniform(*par.limits) 305 316 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. 306 321 if par.type == 'sld': 307 322 # Range of neutron SLDs 308 323 return np.random.uniform(-0.5, 12) 309 324 325 # Guess at the random length/radius/thickness. In practice, all models 326 # are going to set their own reasonable ranges. 310 327 if par.type == 'volume': 311 328 if ('length' in par.name or 312 329 'radius' in par.name or 313 330 '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. 316 336 low, high = parameter_range(par.name, value) 317 337 limits = (max(par.limits[0], low), min(par.limits[1], high))
Note: See TracChangeset
for help on using the changeset viewer.