- Timestamp:
- May 23, 2018 5:55:27 PM (6 years ago)
- Branches:
- master
- Children:
- 910c0f4
- Parents:
- 33969b6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/guide/pd/polydispersity.rst
r29afc50 raa25fc7 28 28 sigmas $N_\sigma$ to include from the tails of the distribution, and the 29 29 number of points used to compute the average. The center of the distribution 30 is set by the value of the model parameter. The meaning of a polydispersity 31 parameter *PD* (not to be confused with a molecular weight distributions 32 in polymer science) in a model depends on the type of parameter it is being 30 is set by the value of the model parameter. The meaning of a polydispersity 31 parameter *PD* (not to be confused with a molecular weight distributions 32 in polymer science) in a model depends on the type of parameter it is being 33 33 applied too. 34 34 35 The distribution width applied to *volume* (ie, shape-describing) parameters 36 is relative to the center value such that $\sigma = \mathrm{PD} \cdot \bar x$. 37 However, the distribution width applied to *orientation* (ie, angle-describing) 35 The distribution width applied to *volume* (ie, shape-describing) parameters 36 is relative to the center value such that $\sigma = \mathrm{PD} \cdot \bar x$. 37 However, the distribution width applied to *orientation* (ie, angle-describing) 38 38 parameters is just $\sigma = \mathrm{PD}$. 39 39 … … 73 73 or angular orientations, use the Gaussian or Boltzmann distributions. 74 74 75 If applying polydispersion to parameters describing angles, use the Uniform 76 distribution. Beware of using distributions that are always positive (eg, the 75 If applying polydispersion to parameters describing angles, use the Uniform 76 distribution. Beware of using distributions that are always positive (eg, the 77 77 Lognormal) because angles can be negative! 78 78 … … 315 315 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 316 316 317 User-defined Distributions 318 ^^^^^^^^^^^^^^^^^^^^^^^^^^ 319 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:: 329 330 import numpy as np 331 from scipy.stats import laplace 332 333 from sasmodels import weights 334 335 class Dispersion(weights.Dispersion): 336 r""" 337 Laplace distribution 338 339 .. math:: 340 341 w(x) = e^{-\sigma |x - \mu|} 342 """ 343 type = "laplace" 344 default = dict(npts=35, width=0, nsigmas=3) # default values 345 def _weights(self, center, sigma, lb, ub): 346 x = self._linspace(center, sigma, lb, ub) 347 wx = laplace.pdf(x, center, sigma) 348 return x, wx 349 350 To see that the distribution is correct use the following:: 351 352 from numpy import inf 353 from matplotlib import pyplot as plt 354 from sasmodels import weights 355 356 # reload the user-defined weights 357 weights.load_weights() 358 x, wx = weights.get_weights('laplace', n=35, width=0.1, nsigmas=3, value=50, 359 limits=[0, inf], relative=True) 360 361 # plot the weights 362 plt.interactive(True) 363 plt.plot(x, wx, 'x') 364 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. 375 376 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 377 317 378 Note about DLS polydispersity 318 379 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: See TracChangeset
for help on using the changeset viewer.