Changeset 5c962df in sasmodels for sasmodels/weights.py
- Timestamp:
- Jan 30, 2016 11:02:03 PM (8 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 3a45c2c
- Parents:
- 5925e90
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/weights.py
r823e620 r5c962df 22 22 23 23 def get_pars(self): 24 """ 25 Return the parameters to the disperser as a dictionary. 26 """ 24 27 pars = {'type': self.type} 25 28 pars.update(self.__dict__) … … 28 31 # pylint: disable=no-self-use 29 32 def set_weights(self, values, weights): 33 """ 34 Set the weights on the disperser if it is :class:`ArrayDispersion`. 35 """ 30 36 raise RuntimeError("set_weights is only available for ArrayDispersion") 31 37 … … 63 69 64 70 class GaussianDispersion(Dispersion): 71 r""" 72 Gaussian dispersion, with 1-\ $\sigma$ width. 73 74 .. math:: 75 76 w = \exp\left(-\tfrac12 (x - c)^2/\sigma^2\right) 77 """ 65 78 type = "gaussian" 66 79 default = dict(npts=35, width=0, nsigmas=3) … … 72 85 73 86 class RectangleDispersion(Dispersion): 87 r""" 88 Uniform dispersion, with width $\sqrt{3}\sigma$. 89 90 .. math:: 91 92 w = 1 93 """ 74 94 type = "rectangle" 75 95 default = dict(npts=35, width=0, nsigmas=1.70325) … … 81 101 82 102 class LogNormalDispersion(Dispersion): 103 r""" 104 log Gaussian dispersion, with 1-\ $\sigma$ width. 105 106 .. math:: 107 108 w = \frac{\exp\left(-\tfrac12 (\ln x - c)^2/\sigma^2\right)}{x\sigma} 109 """ 83 110 type = "lognormal" 84 111 default = dict(npts=80, width=0, nsigmas=8) 85 112 def _weights(self, center, sigma, lb, ub): 86 113 x = self._linspace(center, sigma, max(lb, 1e-8), max(ub, 1e-8)) 87 px = np.exp(-0.5*(np.log(x)-center)**2 )/sigma**2/(x*sigma)114 px = np.exp(-0.5*(np.log(x)-center)**2/sigma**2)/(x*sigma) 88 115 return x, px 89 116 90 117 91 118 class SchulzDispersion(Dispersion): 119 r""" 120 Schultz dispersion, with 1-\ $\sigma$ width. 121 122 .. math:: 123 124 w = \frac{z^z\,R^{z-1}}{e^{Rz}\,c \Gamma(z)} 125 126 where $c$ is the center of the distribution, $R = x/c$ and $z=(c/\sigma)^2$. 127 128 This is evaluated using logarithms as 129 130 .. math:: 131 132 w = \exp\left(z \ln z + (z-1)\ln R - Rz - \ln c - \ln \Gamma(z) \right) 133 """ 92 134 type = "schulz" 93 135 default = dict(npts=80, width=0, nsigmas=8) … … 102 144 103 145 class ArrayDispersion(Dispersion): 146 r""" 147 Empirical dispersion curve. 148 149 Use :meth:`set_weights` to set $w = f(x)$. 150 """ 104 151 type = "array" 105 152 default = dict(npts=35, width=0, nsigmas=1) … … 110 157 111 158 def set_weights(self, values, weights): 159 """ 160 Set the weights for the given x values. 161 """ 112 162 self.values = np.ascontiguousarray(values, 'd') 113 163 self.weights = np.ascontiguousarray(weights, 'd')
Note: See TracChangeset
for help on using the changeset viewer.