Changeset 36873d1 in sasmodels


Ignore:
Timestamp:
May 24, 2018 2:31:44 PM (3 months ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
ticket-608-user-defined-weights
Children:
0e04dd7
Parents:
342b3dd
Message:

improve docs for user defined distributions and fix cyclic gaussian example

Files:
2 edited

Legend:

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

    raa25fc7 r36873d1  
    319319 
    320320You 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* 
     323and *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 
     346The code following wraps the Laplace distribution from scipy stats:: 
    329347 
    330348    import numpy as np 
     
    348366            return x, wx 
    349367 
    350 To see that the distribution is correct use the following:: 
     368You can plot the weights for a given value and width using the following:: 
    351369 
    352370    from numpy import inf 
     
    363381    plt.plot(x, wx, 'x') 
    364382 
    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. 
     383The *self.nsigmas* and *self.npts* parameters are normally used to control 
     384the accuracy of the distribution integral. The *self._linspace* function 
     385uses 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 
     387nsigmas you will need to generate your own *x*.  Be sure to honour the 
     388limits *lb* and *ub*, for example to disallow a negative radius or constrain 
     389the volume fraction to lie between zero and one. 
    375390 
    376391.. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 
  • example/weights/cyclic_gaussian.py

    r342b3dd r36873d1  
    3737        width = min(self.nsigmas*sigma, pi/2) 
    3838        x = np.linspace(-width, width, self.npts+2)[1:-1] 
    39         wx = P(x, a) 
    4039 
    4140        # Return orientation in degrees with Maier-Saupe weights 
Note: See TracChangeset for help on using the changeset viewer.