Changeset a5a12ca in sasmodels for sasmodels/weights.py


Ignore:
Timestamp:
Oct 28, 2017 4:02:56 AM (6 years ago)
Author:
dirk
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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/weights.py

    r41e7f2e ra5a12ca  
    5555        """ 
    5656        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 
    5761        if sigma == 0 or self.npts < 2: 
    5862            if lb <= center <= ub: 
     
    186190        return x, px 
    187191 
     192class BoltzmannDispersion(Dispersion): 
     193    r""" 
     194    Boltzmann dispersion, with $\sigma=k T/E$. 
     195 
     196    .. math:: 
     197 
     198        w = \exp\left( -|x - c|/\sigma\right) 
     199    """ 
     200    type = "boltzmann" 
     201    default = dict(npts=35, width=0, nsigmas=3) 
     202    def _weights(self, center, sigma, lb, ub): 
     203        x = self._linspace(center, sigma, lb, ub) 
     204        px = np.exp(-np.abs(x-center) / np.abs(sigma)) 
     205        return x, px 
    188206 
    189207# dispersion name -> disperser lookup table. 
     
    196214    GaussianDispersion, 
    197215    SchulzDispersion, 
     216    BoltzmannDispersion 
    198217)) 
    199218 
     
    225244    obj = cls(n, width, nsigmas) 
    226245    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]]) -> None 
     246    return v, w/np.sum(w) 
     247 
     248 
     249def plot_weights(model_info, mesh): 
     250    # type: (ModelInfo, List[Tuple[float, np.ndarray, np.ndarray]]) -> None 
    232251    """ 
    233252    Plot the weights returned by :func:`get_weights`. 
    234253 
    235     *model_info* is 
    236     :param model_info: 
    237     :param pairs: 
    238     :return: 
     254    *model_info* defines model parameters, etc. 
     255 
     256    *mesh* is a list of tuples containing (*value*, *dispersity*, *weights*) 
     257    for each parameter, where (*dispersity*, *weights*) pairs are the 
     258    distributions to be plotted. 
    239259    """ 
    240260    import pylab 
    241261 
    242     if any(len(values)>1 for values, weights in pairs): 
     262    if any(len(dispersity)>1 for value, dispersity, weights in mesh): 
    243263        labels = [p.name for p in model_info.parameters.call_parameters] 
    244         pylab.interactive(True) 
     264        #pylab.interactive(True) 
    245265        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) 
     266        for (v,x,w), s in zip(mesh, labels): 
     267            if len(x) > 1: 
     268                pylab.plot(x, w, '-o', label=s) 
    250269        pylab.grid(True) 
    251270        pylab.legend() 
Note: See TracChangeset for help on using the changeset viewer.