# Changeset a5a12ca in sasmodels

Ignore:
Timestamp:
Oct 28, 2017 2:02:56 AM (2 years ago)
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
75e4319
Parents:
6db17bd
Message:

implementation of Boltzmann distribution refs #1018

Files:
2 edited

### Legend:

Unmodified
 r1f058ea calculations are generally more robust with more data points or more angles. The following five distribution functions are provided: The following six distribution functions are provided: *  *Rectangular Distribution* *  *Schulz Distribution* *  *Array Distribution* *  *Boltzmann Distribution* These are all implemented as *number-average* distributions. ^^^^^^^^^^^^^^^^^^ This user-definable distribution should be given as as a simple ASCII text This user-definable distribution should be given as a simple ASCII text file where the array is defined by two columns of numbers: $x$ and $f(x)$. The $f(x)$ will be normalized to 1 during the computation. given for the model will have no affect, and will be ignored when computing the average.  This means that any parameter with an array distribution will not be fittable. not be fitable. .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ Boltzmann Distribution ^^^^^^^^^^^^^^^^^^^^^^ The Boltzmann Distribution is defined as .. math:: f(x) = \frac{1}{\text{Norm}} \exp\left(-\frac{ | x - \bar x | }{\sigma}\right) where $\bar x$ is the mean of the distribution and *Norm* is a normalization factor which is determined during the numerical calculation. The width is defined as .. math:: \sigma=\frac{k T}{E} which is the inverse Boltzmann factor, where $k$ is the Boltzmann constant, $T$ the temperature in Kelvin and $E$ a characteristic energy per particle. .. figure:: pd_boltzmann.jpg Boltzmann distribution. .. ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
 r41e7f2e """ sigma = self.width * center if relative else self.width if not relative: # For orientation, the jitter is relative to 0 not the angle center = 0 pass if sigma == 0 or self.npts < 2: if lb <= center <= ub: return x, px class BoltzmannDispersion(Dispersion): r""" Boltzmann dispersion, with $\sigma=k T/E$. .. math:: w = \exp\left( -|x - c|/\sigma\right) """ type = "boltzmann" default = dict(npts=35, width=0, nsigmas=3) def _weights(self, center, sigma, lb, ub): x = self._linspace(center, sigma, lb, ub) px = np.exp(-np.abs(x-center) / np.abs(sigma)) return x, px # dispersion name -> disperser lookup table. GaussianDispersion, SchulzDispersion, BoltzmannDispersion )) obj = cls(n, width, nsigmas) v, w = obj.get_weights(value, limits[0], limits[1], relative) return v, w def plot_weights(model_info, pairs): # type: (ModelInfo, List[Tuple[np.ndarray, np.ndarray]]) -> None return v, w/np.sum(w) def plot_weights(model_info, mesh): # type: (ModelInfo, List[Tuple[float, np.ndarray, np.ndarray]]) -> None """ Plot the weights returned by :func:get_weights. *model_info* is :param model_info: :param pairs: :return: *model_info* defines model parameters, etc. *mesh* is a list of tuples containing (*value*, *dispersity*, *weights*) for each parameter, where (*dispersity*, *weights*) pairs are the distributions to be plotted. """ import pylab if any(len(values)>1 for values, weights in pairs): if any(len(dispersity)>1 for value, dispersity, weights in mesh): labels = [p.name for p in model_info.parameters.call_parameters] pylab.interactive(True) #pylab.interactive(True) pylab.figure() for (v,w), s in zip(pairs, labels): if len(v) > 1: #print("weights for", s, v, w) pylab.plot(v, w, '-o', label=s) for (v,x,w), s in zip(mesh, labels): if len(x) > 1: pylab.plot(x, w, '-o', label=s) pylab.grid(True) pylab.legend()