Changes in / [01dba26:2c12061] in sasmodels
- Files:
-
- 5 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/guide/pd/polydispersity.rst
rd089a00 rd089a00 34 34 Each distribution is characterized by a center value $\bar x$ or 35 35 $x_\text{med}$, a width parameter $\sigma$ (note this is *not necessarily* 36 <<<<<<< HEAD37 the standard deviation, so read the description carefully), the number of38 sigmas $N_\sigma$ to include from the tails of the distribution, and the39 number of points used to compute the average. The center of the distribution40 is set by the value of the model parameter. The meaning of a polydispersity41 parameter *PD* (not to be confused with a molecular weight distributions42 in polymer science) in a model depends on the type of parameter it is being43 applied too.44 45 The distribution width applied to *volume* (ie, shape-describing) parameters46 is relative to the center value such that $\sigma = \mathrm{PD} \cdot \bar x$.47 However, the distribution width applied to *orientation* (ie, angle-describing)48 parameters is just $\sigma = \mathrm{PD}$.49 =======50 36 the standard deviation, so read the description of the distribution carefully), 51 37 the number of sigmas $N_\sigma$ to include from the tails of the distribution, … … 57 43 However, the distribution width applied to *orientation* parameters is just 58 44 $\sigma = \mathrm{PD}$. 59 >>>>>>> master60 45 61 46 $N_\sigma$ determines how far into the tails to evaluate the distribution, … … 81 66 * *Schulz Distribution* 82 67 * *Array Distribution* 83 * *User-defined Distributions*84 68 85 69 These are all implemented as *number-average* distributions. 86 70 71 Additional distributions are under consideration. 87 72 88 73 **Beware: when the Polydispersity & Orientational Distribution panel in SasView is** … … 107 92 or angular orientations, consider using the Gaussian or Boltzmann distributions. 108 93 109 If applying polydispersion to parameters describing angles, use the Uniform 110 distribution. Beware of using distributions that are always positive (eg, the 94 If applying polydispersion to parameters describing angles, use the Uniform 95 distribution. Beware of using distributions that are always positive (eg, the 111 96 Lognormal) because angles can be negative! 112 97 113 The array distribution provides a very simple means of implementing a user- 114 defined distribution, but without any fittable parameters. Greater flexibility 115 is conferred by the user-defined distribution. 98 The array distribution allows a user-defined distribution to be applied. 116 99 117 100 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ … … 351 334 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 352 335 353 User-defined Distributions354 ^^^^^^^^^^^^^^^^^^^^^^^^^^355 356 You can also define your own distribution by creating a python file defining a357 *Distribution* object with a *_weights* method. The *_weights* method takes358 *center*, *sigma*, *lb* and *ub* as arguments, and can access *self.npts*359 and *self.nsigmas* from the distribution. They are interpreted as follows:360 361 * *center* the value of the shape parameter (for size dispersity) or zero362 if it is an angular dispersity. This parameter may be fitted.363 364 * *sigma* the width of the distribution, which is the polydispersity parameter365 times the center for size dispersity, or the polydispersity parameter alone366 for angular dispersity. This parameter may be fitted.367 368 * *lb*, *ub* are the parameter limits (lower & upper bounds) given in the model369 definition file. For example, a radius parameter has *lb* equal to zero. A370 volume fraction parameter would have *lb* equal to zero and *ub* equal to one.371 372 * *self.nsigmas* the distance to go into the tails when evaluating the373 distribution. For a two parameter distribution, this value could be374 co-opted to use for the second parameter, though it will not be available375 for fitting.376 377 * *self.npts* the number of points to use when evaluating the distribution.378 The user will adjust this to trade calculation time for accuracy, but the379 distribution code is free to return more or fewer, or use it for the third380 parameter in a three parameter distribution.381 382 As an example, the code following wraps the Laplace distribution from scipy stats::383 384 import numpy as np385 from scipy.stats import laplace386 387 from sasmodels import weights388 389 class Dispersion(weights.Dispersion):390 r"""391 Laplace distribution392 393 .. math::394 395 w(x) = e^{-\sigma |x - \mu|}396 """397 type = "laplace"398 default = dict(npts=35, width=0, nsigmas=3) # default values399 def _weights(self, center, sigma, lb, ub):400 x = self._linspace(center, sigma, lb, ub)401 wx = laplace.pdf(x, center, sigma)402 return x, wx403 404 You can plot the weights for a given value and width using the following::405 406 from numpy import inf407 from matplotlib import pyplot as plt408 from sasmodels import weights409 410 # reload the user-defined weights411 weights.load_weights()412 x, wx = weights.get_weights('laplace', n=35, width=0.1, nsigmas=3, value=50,413 limits=[0, inf], relative=True)414 415 # plot the weights416 plt.interactive(True)417 plt.plot(x, wx, 'x')418 419 The *self.nsigmas* and *self.npts* parameters are normally used to control420 the accuracy of the distribution integral. The *self._linspace* function421 uses them to define the *x* values (along with the *center*, *sigma*,422 *lb*, and *ub* which are passed as parameters). If you repurpose npts or423 nsigmas you will need to generate your own *x*. Be sure to honour the424 limits *lb* and *ub*, for example to disallow a negative radius or constrain425 the volume fraction to lie between zero and one.426 427 To activate a user-defined distribution, put it in a file such as *distname.py*428 in the *SAS_WEIGHTS_PATH* folder. This is defined with an environment429 variable, defaulting to::430 431 SAS_WEIGHTS_PATH=~/.sasview/weights432 433 The weights path is loaded on startup. To update the distribution definition434 in a running application you will need to enter the following python commands::435 436 import sasmodels.weights437 sasmodels.weights.load_weights('path/to/distname.py')438 439 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ440 441 336 Note about DLS polydispersity 442 337 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -
sasmodels/compare.py
rbd7630d rbd7630d 41 41 from . import kerneldll 42 42 from . import kernelcl 43 from . import weights44 43 from .data import plot_theory, empty_data1D, empty_data2D, load_data 45 44 from .direct_model import DirectModel, get_mesh 46 45 from .generate import FLOAT_RE, set_integration_size 46 from .weights import plot_weights 47 47 48 48 # pylint: disable=unused-import … … 114 114 115 115 === environment variables === 116 -DSAS_MODELPATH=~/.sasmodels/custom_models sets path to custom models 117 -DSAS_WEIGHTS_PATH=~/.sasview/weights sets path to custom distributions 116 -DSAS_MODELPATH=path sets directory containing custom models 118 117 -DSAS_OPENCL=vendor:device|none sets the target OpenCL device 119 118 -DXDG_CACHE_HOME=~/.cache sets the pyopencl cache root (linux only) 120 119 -DSAS_COMPILER=tinycc|msvc|mingw|unix sets the DLL compiler 121 -DSAS_OPENMP= 0 set to 1 to turnon OpenMP for the DLLs122 -DSAS_DLL_PATH= ~/.sasmodels/compiled_models sets the DLL cache120 -DSAS_OPENMP=1 turns on OpenMP for the DLLs 121 -DSAS_DLL_PATH=path sets the path to the compiled modules 123 122 124 123 The interpretation of quad precision depends on architecture, and may … … 784 783 model_info = base._kernel.info 785 784 dim = base._kernel.dim 786 weights.plot_weights(model_info, get_mesh(model_info, base_pars, dim=dim))785 plot_weights(model_info, get_mesh(model_info, base_pars, dim=dim)) 787 786 if opts['show_profile']: 788 787 import pylab … … 1441 1440 #import pprint; pprint.pprint(model_info) 1442 1441 1443 # Hack to load user-defined distributions; run through all parameters1444 # and make sure any pd_type parameter is a defined distribution.1445 if (any(p.endswith('pd_type') and v not in weights.MODELS1446 for p, v in pars.items()) or1447 any(p.endswith('pd_type') and v not in weights.MODELS1448 for p, v in pars2.items())):1449 weights.load_weights()1450 1451 1442 if opts['show_pars']: 1452 1443 if model_info.name != model_info2.name or pars != pars2: -
sasmodels/sasview_model.py
raa25fc7 rd533590 30 30 from . import modelinfo 31 31 from .details import make_kernel_args, dispersion_mesh 32 33 # Hack: load in any custom distributions34 # Uses ~/.sasview/weights/*.py unless SASMODELS_WEIGHTS is set in the environ.35 # Override with weights.load_weights(pattern="<weights_path>/*.py")36 weights.load_weights()37 32 38 33 # pylint: disable=unused-import -
sasmodels/weights.py
rf41027b r3d58247 231 231 )) 232 232 233 SAS_WEIGHTS_PATH = "~/.sasview/weights"234 def load_weights(pattern=None):235 # type: (str) -> None236 """237 Load dispersion distributions matching the given glob pattern238 """239 import logging240 import os241 import os.path242 import glob243 import traceback244 from .custom import load_custom_kernel_module245 if pattern is None:246 path = os.environ.get("SAS_WEIGHTS_PATH", SAS_WEIGHTS_PATH)247 pattern = os.path.join(path, "*.py")248 for filename in sorted(glob.glob(os.path.expanduser(pattern))):249 try:250 #print("loading weights from", filename)251 module = load_custom_kernel_module(filename)252 MODELS[module.Dispersion.type] = module.Dispersion253 except Exception as exc:254 logging.error(traceback.format_exc(exc))255 233 256 234 def get_weights(disperser, n, width, nsigmas, value, limits, relative):
Note: See TracChangeset
for help on using the changeset viewer.