Changes in / [fa70e04:26a6608] in sasmodels
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/guide/pd/polydispersity.rst
r1f058ea r75e4319 40 40 calculations are generally more robust with more data points or more angles. 41 41 42 The following fivedistribution functions are provided:42 The following six distribution functions are provided: 43 43 44 44 * *Rectangular Distribution* 45 * *Uniform Distribution* 45 46 * *Gaussian Distribution* 46 47 * *Lognormal Distribution* 47 48 * *Schulz Distribution* 48 49 * *Array Distribution* 50 * *Boltzmann Distribution* 49 51 50 52 These are all implemented as *number-average* distributions. … … 83 85 Rectangular distribution. 84 86 87 Uniform Distribution 88 ^^^^^^^^^^^^^^^^^^^^^^^^ 89 90 The Uniform Distribution is defined as 91 92 .. math:: 93 94 f(x) = \frac{1}{\text{Norm}} 95 \begin{cases} 96 1 & \text{for } |x - \bar x| \leq \sigma \\ 97 0 & \text{for } |x - \bar x| > \sigma 98 \end{cases} 99 100 where $\bar x$ is the mean of the distribution, $\sigma$ is the half-width, and 101 *Norm* is a normalization factor which is determined during the numerical 102 calculation. 103 104 Note that the polydispersity is given by 105 106 .. math:: \text{PD} = \sigma / \bar x 107 108 .. figure:: pd_uniform.jpg 109 110 Uniform distribution. 111 85 112 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 86 113 … … 181 208 ^^^^^^^^^^^^^^^^^^ 182 209 183 This user-definable distribution should be given as a s asimple ASCII text210 This user-definable distribution should be given as a simple ASCII text 184 211 file where the array is defined by two columns of numbers: $x$ and $f(x)$. 185 212 The $f(x)$ will be normalized to 1 during the computation. … … 200 227 given for the model will have no affect, and will be ignored when computing 201 228 the average. This means that any parameter with an array distribution will 202 not be fittable. 229 not be fitable. 230 231 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ 232 233 Boltzmann Distribution 234 ^^^^^^^^^^^^^^^^^^^^^^ 235 236 The Boltzmann Distribution is defined as 237 238 .. math:: 239 240 f(x) = \frac{1}{\text{Norm}} 241 \exp\left(-\frac{ | x - \bar x | }{\sigma}\right) 242 243 where $\bar x$ is the mean of the distribution and *Norm* is a normalization 244 factor which is determined during the numerical calculation. 245 The width is defined as 246 247 .. math:: \sigma=\frac{k T}{E} 248 249 which is the inverse Boltzmann factor, 250 where $k$ is the Boltzmann constant, $T$ the temperature in Kelvin and $E$ a 251 characteristic energy per particle. 252 253 .. figure:: pd_boltzmann.jpg 254 255 Boltzmann distribution. 203 256 204 257 .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ -
sasmodels/weights.py
rf1a8811 r75e4319 55 55 """ 56 56 sigma = self.width * center if relative else self.width 57 if not relative: 58 # For orientation, the jitter is relative to 0 not the angle 59 center = 0 60 pass 57 61 if sigma == 0 or self.npts < 2: 58 62 if lb <= center <= ub: … … 93 97 return x, px 94 98 99 class UniformDispersion(Dispersion): 100 r""" 101 Uniform dispersion, with width $\sigma$. 102 103 .. math:: 104 105 w = 1 106 """ 107 type = "uniform" 108 default = dict(npts=35, width=0, nsigmas=1) 109 def _weights(self, center, sigma, lb, ub): 110 x = self._linspace(center, sigma, lb, ub) 111 x = x[np.fabs(x-center) <= np.fabs(sigma)] 112 return x, np.ones_like(x) 95 113 96 114 class RectangleDispersion(Dispersion): … … 186 204 return x, px 187 205 206 class BoltzmannDispersion(Dispersion): 207 r""" 208 Boltzmann dispersion, with $\sigma=k T/E$. 209 210 .. math:: 211 212 w = \exp\left( -|x - c|/\sigma\right) 213 """ 214 type = "boltzmann" 215 default = dict(npts=35, width=0, nsigmas=3) 216 def _weights(self, center, sigma, lb, ub): 217 x = self._linspace(center, sigma, lb, ub) 218 px = np.exp(-np.abs(x-center) / np.abs(sigma)) 219 return x, px 188 220 189 221 # dispersion name -> disperser lookup table. … … 192 224 MODELS = OrderedDict((d.type, d) for d in ( 193 225 RectangleDispersion, 226 UniformDispersion, 194 227 ArrayDispersion, 195 228 LogNormalDispersion, 196 229 GaussianDispersion, 197 230 SchulzDispersion, 231 BoltzmannDispersion 198 232 )) 199 233 … … 225 259 obj = cls(n, width, nsigmas) 226 260 v, w = obj.get_weights(value, limits[0], limits[1], relative) 227 return v, w 228 229 230 def plot_weights(model_info, pairs):231 # type: (ModelInfo, List[Tuple[ np.ndarray, np.ndarray]]) -> None261 return v, w/np.sum(w) 262 263 264 def plot_weights(model_info, mesh): 265 # type: (ModelInfo, List[Tuple[float, np.ndarray, np.ndarray]]) -> None 232 266 """ 233 267 Plot the weights returned by :func:`get_weights`. 234 268 235 *model_info* is 236 :param model_info: 237 :param pairs: 238 :return: 269 *model_info* defines model parameters, etc. 270 271 *mesh* is a list of tuples containing (*value*, *dispersity*, *weights*) 272 for each parameter, where (*dispersity*, *weights*) pairs are the 273 distributions to be plotted. 239 274 """ 240 275 import pylab 241 276 242 if any(len( values)>1 for values, weights in pairs):277 if any(len(dispersity)>1 for value, dispersity, weights in mesh): 243 278 labels = [p.name for p in model_info.parameters.call_parameters] 244 pylab.interactive(True)279 #pylab.interactive(True) 245 280 pylab.figure() 246 for (v,w), s in zip(pairs, labels): 247 if len(v) > 1: 248 #print("weights for", s, v, w) 249 pylab.plot(v, w, '-o', label=s) 281 for (v,x,w), s in zip(mesh, labels): 282 if len(x) > 1: 283 pylab.plot(x, w, '-o', label=s) 250 284 pylab.grid(True) 251 285 pylab.legend()
Note: See TracChangeset
for help on using the changeset viewer.