Changes in / [15f5138:0d26e91] in sasmodels
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/guide/plugin.rst
r94bfa42 r81751c2 272 272 structure factor to account for interactions between particles. See 273 273 `Form_Factors`_ for more details. 274 275 **model_info = ...** lets you define a model directly, for example, by276 loading and modifying existing models. This is done implicitly by277 :func:`sasmodels.core.load_model_info`, which can create a mixture model278 from a pair of existing models. For example::279 280 from sasmodels.core import load_model_info281 model_info = load_model_info('sphere+cylinder')282 283 See :class:`sasmodels.modelinfo.ModelInfo` for details about the model284 attributes that are defined.285 274 286 275 Model Parameters … … 905 894 - \frac{\sin(x)}{x}\left(\frac{1}{x} - \frac{3!}{x^3} + \frac{5!}{x^5} - \frac{7!}{x^7}\right) 906 895 907 For small arguments ,896 For small arguments , 908 897 909 898 .. math:: -
example/multiscatfit.py
r2c4a190 r49d1f8b8 15 15 16 16 # Show the model without fitting 17 PYTHONPATH=..:../ ../bumps:../../sasview/src python multiscatfit.py17 PYTHONPATH=..:../explore:../../bumps:../../sasview/src python multiscatfit.py 18 18 19 19 # Run the fit 20 PYTHONPATH=..:../ ../bumps:../../sasview/src ../../bumps/run.py \20 PYTHONPATH=..:../explore:../../bumps:../../sasview/src ../../bumps/run.py \ 21 21 multiscatfit.py --store=/tmp/t1 22 22 … … 55 55 ) 56 56 57 # Tie the model to the data58 M = Experiment(data=data, model=model)59 60 # Stack mulitple scattering on top of the existing resolution function.61 M.resolution = MultipleScattering(resolution=M.resolution, probability=0.)62 63 57 # SET THE FITTING PARAMETERS 64 58 model.radius_polar.range(15, 3000) … … 71 65 model.scale.range(0, 0.1) 72 66 73 # The multiple scattering probability parameter is in the resolution function 74 # instead of the scattering function, so access it through M.resolution 75 M.scattering_probability.range(0.0, 0.9) 67 # Mulitple scattering probability parameter 68 # HACK: the probability is stuffed in as an extra parameter to the experiment. 69 probability = Parameter(name="probability", value=0.0) 70 probability.range(0.0, 0.9) 76 71 77 # Let bumps know that we are fitting this experiment 72 M = Experiment(data=data, model=model, extra_pars={'probability': probability}) 73 74 # Stack mulitple scattering on top of the existing resolution function. 75 # Because resolution functions in sasview don't have fitting parameters, 76 # we instead allow the multiple scattering calculator to take a function 77 # instead of a probability. This function returns the current value of 78 # the parameter. ** THIS IS TEMPORARY ** when multiple scattering is 79 # properly integrated into sasmodels and sasview, its fittable parameter 80 # will be treated like the model parameters. 81 M.resolution = MultipleScattering(resolution=M.resolution, 82 probability=lambda: probability.value, 83 ) 84 M._kernel_inputs = M.resolution.q_calc 78 85 problem = FitProblem(M) 79 86 -
sasmodels/__init__.py
r37f38ff ra1ec908 14 14 defining new models. 15 15 """ 16 __version__ = "0.9 9"16 __version__ = "0.98" 17 17 18 18 def data_files(): -
sasmodels/bumps_model.py
r2c4a190 r49d1f8b8 35 35 # when bumps is not on the path. 36 36 from bumps.names import Parameter # type: ignore 37 from bumps.parameter import Reference # type: ignore38 37 except ImportError: 39 38 pass … … 140 139 def __init__(self, data, model, cutoff=1e-5, name=None, extra_pars=None): 141 140 # type: (Data, Model, float) -> None 142 # Allow resolution function to define fittable parameters. We do this143 # by creating reference parameters within the resolution object rather144 # than modifying the object itself to use bumps parameters. We need145 # to reset the parameters each time the object has changed. These146 # additional parameters need to be returned from the fitting engine.147 # To make them available to the user, they are added as top-level148 # attributes to the experiment object. The only change to the149 # resolution function is that it needs an optional 'fittable' attribute150 # which maps the internal name to the user visible name for the151 # for the parameter.152 self._resolution = None153 self._resolution_pars = {}154 141 # remember inputs so we can inspect from outside 155 142 self.name = data.filename if name is None else name … … 158 145 self._interpret_data(data, model.sasmodel) 159 146 self._cache = {} 160 # CRUFT: no longer need extra parameters161 # Multiple scattering probability is now retrieved directly from the162 # multiple scattering resolution function.163 147 self.extra_pars = extra_pars 164 148 … … 178 162 return len(self.Iq) 179 163 180 @property181 def resolution(self):182 return self._resolution183 184 @resolution.setter185 def resolution(self, value):186 self._resolution = value187 188 # Remove old resolution fitting parameters from experiment189 for name in self._resolution_pars:190 delattr(self, name)191 192 # Create new resolution fitting parameters193 res_pars = getattr(self._resolution, 'fittable', {})194 self._resolution_pars = {195 name: Reference(self._resolution, refname, name=name)196 for refname, name in res_pars.items()197 }198 199 # Add new resolution fitting parameters as experiment attributes200 for name, ref in self._resolution_pars.items():201 setattr(self, name, ref)202 203 164 def parameters(self): 204 165 # type: () -> Dict[str, Parameter] … … 207 168 """ 208 169 pars = self.model.parameters() 209 if self.extra_pars is not None:170 if self.extra_pars: 210 171 pars.update(self.extra_pars) 211 pars.update(self._resolution_pars)212 172 return pars 213 173 -
sasmodels/direct_model.py
r2c4a190 r5024a56 224 224 else: 225 225 Iq, dIq = None, None 226 #self._theory = np.zeros_like(q) 227 q_vectors = [res.q_calc] 226 228 elif self.data_type == 'Iqxy': 227 229 #if not model.info.parameters.has_2d: … … 240 242 res = resolution2d.Pinhole2D(data=data, index=index, 241 243 nsigma=3.0, accuracy=accuracy) 244 #self._theory = np.zeros_like(self.Iq) 245 q_vectors = res.q_calc 242 246 elif self.data_type == 'Iq': 243 247 index = (data.x >= data.qmin) & (data.x <= data.qmax) … … 264 268 else: 265 269 res = resolution.Perfect1D(data.x[index]) 270 271 #self._theory = np.zeros_like(self.Iq) 272 q_vectors = [res.q_calc] 266 273 elif self.data_type == 'Iq-oriented': 267 274 index = (data.x >= data.qmin) & (data.x <= data.qmax) … … 279 286 qx_width=data.dxw[index], 280 287 qy_width=data.dxl[index]) 288 q_vectors = res.q_calc 281 289 else: 282 290 raise ValueError("Unknown data type") # never gets here … … 284 292 # Remember function inputs so we can delay loading the function and 285 293 # so we can save/restore state 294 self._kernel_inputs = q_vectors 286 295 self._kernel = None 287 296 self.Iq, self.dIq, self.index = Iq, dIq, index … … 320 329 # type: (ParameterSet, float) -> np.ndarray 321 330 if self._kernel is None: 322 # TODO: change interfaces so that resolution returns kernel inputs 323 # Maybe have resolution always return a tuple, or maybe have 324 # make_kernel accept either an ndarray or a pair of ndarrays. 325 kernel_inputs = self.resolution.q_calc 326 if isinstance(kernel_inputs, np.ndarray): 327 kernel_inputs = (kernel_inputs,) 328 self._kernel = self._model.make_kernel(kernel_inputs) 331 self._kernel = self._model.make_kernel(self._kernel_inputs) 329 332 330 333 # Need to pull background out of resolution for multiple scattering -
sasmodels/multiscat.py
r2c4a190 rb3703f5 342 342 343 343 *probability* is related to the expected number of scattering 344 events in the sample $\lambda$ as $p = 1 - e^{-\lambda}$. 345 *coverage* determines how many scattering steps to consider. The 346 default is 0.99, which sets $n$ such that $1 \ldots n$ covers 99% 347 of the Poisson probability mass function. 344 events in the sample $\lambda$ as $p = 1 = e^{-\lambda}$. As a 345 hack to allow probability to be a fitted parameter, the "value" 346 can be a function that takes no parameters and returns the current 347 value of the probability. *coverage* determines how many scattering 348 steps to consider. The default is 0.99, which sets $n$ such that 349 $1 \ldots n$ covers 99% of the Poisson probability mass function. 348 350 349 351 *is2d* is True then 2D scattering is used, otherwise it accepts … … 397 399 self.qmin = qmin 398 400 self.nq = nq 399 self.probability = 0. if probability is None elseprobability401 self.probability = probability 400 402 self.coverage = coverage 401 403 self.is2d = is2d … … 454 456 self.Iqxy = None # type: np.ndarray 455 457 456 # Label probability as a fittable parameter, and give its external name457 # Note that the external name must be a valid python identifier, since458 # is will be set as an experiment attribute.459 self.fittable = {'probability': 'scattering_probability'}460 461 458 def apply(self, theory): 462 459 if self.is2d: … … 466 463 Iq_calc = Iq_calc.reshape(self.nq, self.nq) 467 464 468 # CRUFT: don't need probability as a function anymore469 465 probability = self.probability() if callable(self.probability) else self.probability 470 466 coverage = self.coverage -
sasmodels/sasview_model.py
r3a1afed r3a1afed 25 25 from . import core 26 26 from . import custom 27 from . import kernelcl28 27 from . import product 29 28 from . import generate … … 31 30 from . import modelinfo 32 31 from .details import make_kernel_args, dispersion_mesh 33 from .kernelcl import reset_environment34 32 35 33 # pylint: disable=unused-import … … 70 68 #: has changed since we last reloaded. 71 69 _CACHED_MODULE = {} # type: Dict[str, "module"] 72 73 def reset_environment():74 # type: () -> None75 """76 Clear the compute engine context so that the GUI can change devices.77 78 This removes all compiled kernels, even those that are active on fit79 pages, but they will be restored the next time they are needed.80 """81 kernelcl.reset_environment()82 for model in MODELS.values():83 model._model = None84 70 85 71 def find_model(modelname): … … 710 696 def _calculate_Iq(self, qx, qy=None): 711 697 if self._model is None: 712 # Only need one copy of the compiled kernel regardless of how many 713 # times it is used, so store it in the class. Also, to reset the 714 # compute engine, need to clear out all existing compiled kernels, 715 # which is much easier to do if we store them in the class. 716 self.__class__._model = core.build_model(self._model_info) 698 self._model = core.build_model(self._model_info) 717 699 if qy is not None: 718 700 q_vectors = [np.asarray(qx), np.asarray(qy)]
Note: See TracChangeset
for help on using the changeset viewer.