Changeset 36873d1 in sasmodels
- Timestamp:
- May 24, 2018 12:31:44 PM (7 years ago)
- Branches:
- master
- Children:
- 0e04dd7
- Parents:
- 342b3dd
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/guide/pd/polydispersity.rst
raa25fc7 r36873d1 319 319 320 320 You can define your own distribution by creating a python file defining a 321 *Distribution* object. The distribution is parameterized by *center* 322 (which is always zero for orientation dispersity, or parameter value for 323 size dispersity), *sigma* (which is the distribution width in degrees for 324 orientation parameters, or center times width for size dispersity), and 325 bounds *lb* and *ub* (which are the bounds on the possible values of the 326 parameter given in the model definition). 327 328 For example, the following wraps the Laplace distribution from scipy stats:: 321 *Distribution* object with a *_weights* method. The *_weights* method takes 322 *center*, *sigma*, *lb* and *ub* as arguments, and can access *self.npts* 323 and *self.nsigmas* from the distribution. They are interpreted as follows: 324 325 * *center* the value of the shape parameter (for size dispersity) or zero 326 if it is an angular dispersity. This parameter may be fitted. 327 328 * *sigma* the width of the distribution, with is the polydispersity parameter 329 times the center for size dispersity, or the polydispersity parameter alone 330 for angular dispersity. This parameter may be fitted. 331 332 * *lb*, *ub* are the parameter limits given in the model definition file. For 333 example, a radius parameter has *lb* equal to zero. A volume fraction 334 parameter would have *lb* equal to zero and *ub* equal to one. 335 336 * *self.nsigmas* the distance to go into the tails when evaluating the 337 distribution. For a two parameter distribution, this value could be 338 co-opted to use for the second parameter, though it will not be available 339 for fitting. 340 341 * *self.npts* the number of points to use when evaluating the distribution. 342 The user will adjust this to trade calculation time for accuracy, but the 343 distribution code is free to return more or fewer, or use it for the third 344 parameter in a three parameter distribution. 345 346 The code following wraps the Laplace distribution from scipy stats:: 329 347 330 348 import numpy as np … … 348 366 return x, wx 349 367 350 To see that the distribution is correct usethe following::368 You can plot the weights for a given value and width using the following:: 351 369 352 370 from numpy import inf … … 363 381 plt.plot(x, wx, 'x') 364 382 365 Any python code can be used to define the distribution. The distribution 366 parameters are available as *self.npts*, *self.width* and *self.nsigmas*. 367 Try to follow the convention of gaussian width, npts and number of sigmas 368 in the tail, but if your distribution requires more parameters you are free 369 to interpret them as something else. In particular, npts allows you to 370 trade accuracy against running time when evaluating your models. The 371 *self._linspace* function uses *self.npts* and *self.nsigmas* to define 372 the set of *x* values to use for the distribution (along with the *center*, 373 *sigma*, *lb*, and *ub* passed as parameters). You can use an arbitrary 374 set of *x* points. 383 The *self.nsigmas* and *self.npts* parameters are normally used to control 384 the accuracy of the distribution integral. The *self._linspace* function 385 uses them to define the *x* values (along with the *center*, *sigma*, 386 *lb*, and *ub* which are passed as parameters). If you repurpose npts or 387 nsigmas you will need to generate your own *x*. Be sure to honour the 388 limits *lb* and *ub*, for example to disallow a negative radius or constrain 389 the volume fraction to lie between zero and one. 375 390 376 391 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ -
example/weights/cyclic_gaussian.py
r342b3dd r36873d1 37 37 width = min(self.nsigmas*sigma, pi/2) 38 38 x = np.linspace(-width, width, self.npts+2)[1:-1] 39 wx = P(x, a)40 39 41 40 # Return orientation in degrees with Maier-Saupe weights
Note: See TracChangeset
for help on using the changeset viewer.