Changeset aa25fc7 in sasmodels for doc/guide


Ignore:
Timestamp:
May 23, 2018 5:55:27 PM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master
Children:
910c0f4
Parents:
33969b6
Message:

load user-defined weight functions from ~/.sasview/weights/*.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/guide/pd/polydispersity.rst

    r29afc50 raa25fc7  
    2828sigmas $N_\sigma$ to include from the tails of the distribution, and the 
    2929number 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  
     30is set by the value of the model parameter. The meaning of a polydispersity 
     31parameter *PD* (not to be confused with a molecular weight distributions 
     32in polymer science) in a model depends on the type of parameter it is being 
    3333applied too. 
    3434 
    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)  
     35The distribution width applied to *volume* (ie, shape-describing) parameters 
     36is relative to the center value such that $\sigma = \mathrm{PD} \cdot \bar x$. 
     37However, the distribution width applied to *orientation* (ie, angle-describing) 
    3838parameters is just $\sigma = \mathrm{PD}$. 
    3939 
     
    7373or angular orientations, use the Gaussian or Boltzmann distributions. 
    7474 
    75 If applying polydispersion to parameters describing angles, use the Uniform  
    76 distribution. Beware of using distributions that are always positive (eg, the  
     75If applying polydispersion to parameters describing angles, use the Uniform 
     76distribution. Beware of using distributions that are always positive (eg, the 
    7777Lognormal) because angles can be negative! 
    7878 
     
    315315.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
    316316 
     317User-defined Distributions 
     318^^^^^^^^^^^^^^^^^^^^^^^^^^ 
     319 
     320You 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 
     323size dispersity), *sigma* (which is the distribution width in degrees for 
     324orientation parameters, or center times width for size dispersity), and 
     325bounds *lb* and *ub* (which are the bounds on the possible values of the 
     326parameter given in the model definition). 
     327 
     328For 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 
     350To 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 
     365Any python code can be used to define the distribution.  The distribution 
     366parameters are available as *self.npts*, *self.width* and *self.nsigmas*. 
     367Try to follow the convention of gaussian width, npts and number of sigmas 
     368in the tail, but if your distribution requires more parameters you are free 
     369to interpret them as something else.  In particular, npts allows you to 
     370trade accuracy against running time when evaluating your models.  The 
     371*self._linspace* function uses *self.npts* and *self.nsigmas* to define 
     372the 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 
     374set of *x* points. 
     375 
     376.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
     377 
    317378Note about DLS polydispersity 
    318379^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
Note: See TracChangeset for help on using the changeset viewer.