Changeset 3c24ccd in sasmodels
- Timestamp:
- Oct 18, 2017 12:03:43 PM (7 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- ef8e68c
- Parents:
- fbb9397
- Location:
- sasmodels
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
rfbb9397 r3c24ccd 42 42 from . import exception 43 43 from .data import plot_theory, empty_data1D, empty_data2D, load_data 44 from .direct_model import DirectModel 44 from .direct_model import DirectModel, get_mesh 45 45 from .convert import revert_name, revert_pars, constrain_new_to_old 46 46 from .generate import FLOAT_RE 47 from .weights import plot_weights 47 48 48 49 try: … … 102 103 -abs/-rel* plot relative or absolute error 103 104 -title="note" adds note to the plot title, after the model name 105 -weights shows weights plots for the polydisperse parameters 104 106 105 107 === output options === … … 834 836 if opts['plot']: 835 837 limits = plot_models(opts, result, limits=limits, setnum=k) 838 if opts['show_weights']: 839 base, _ = opts['engines'] 840 base_pars, _ = opts['pars'] 841 model_info = base._kernel.info 842 dim = base._kernel.dim 843 plot_weights(model_info, get_mesh(model_info, base_pars, dim=dim)) 836 844 if opts['plot']: 837 845 import matplotlib.pyplot as plt … … 996 1004 OPTIONS = [ 997 1005 # Plotting 998 'plot', 'noplot', 1006 'plot', 'noplot', 'weights', 999 1007 'linear', 'log', 'q4', 1000 1008 'rel', 'abs', … … 1146 1154 'engine' : 'default', 1147 1155 'evals' : '1', 1156 'show_weights' : False, 1148 1157 } 1149 1158 for arg in flags: … … 1194 1203 elif arg == '-demo': opts['use_demo'] = True 1195 1204 elif arg == '-default': opts['use_demo'] = False 1205 elif arg == '-weights': opts['show_weights'] = True 1196 1206 elif arg == '-html': opts['html'] = True 1197 1207 elif arg == '-help': opts['html'] = True -
sasmodels/details.py
r8698a0d r3c24ccd 234 234 # skipping scale and background when building values and weights 235 235 values, dispersity, weights = zip(*mesh[2:npars+2]) if npars else ((), (), ()) 236 #weights = correct_theta_weights(kernel.info.parameters, values, weights)236 weights = correct_theta_weights(kernel.info.parameters, values, weights) 237 237 length = np.array([len(w) for w in weights]) 238 238 offset = np.cumsum(np.hstack((0, length))) -
sasmodels/direct_model.py
r32f87a5 r3c24ccd 55 55 *mono* is True if polydispersity should be set to none on all parameters. 56 56 """ 57 parameters = calculator.info.parameters 58 if mono: 59 active = lambda name: False 60 elif calculator.dim == '1d': 61 active = lambda name: name in parameters.pd_1d 62 elif calculator.dim == '2d': 63 active = lambda name: name in parameters.pd_2d 64 else: 65 active = lambda name: True 66 67 #print("pars",[p.id for p in parameters.call_parameters]) 68 mesh = [get_weights(p, pars, active(p.name)) 69 for p in parameters.call_parameters] 70 57 mesh = get_mesh(calculator.info, pars, dim=calculator.dim, mono=mono) 71 58 call_details, values, is_magnetic = make_kernel_args(calculator, mesh) 72 59 #print("values:", values) 73 60 return calculator(call_details, values, cutoff, is_magnetic) 74 75 61 76 62 def call_ER(model_info, pars): … … 128 114 return x, y, model_info.profile_axes 129 115 130 131 def get_weights(parameter, values, active=True): 132 # type: (Parameter, Dict[str, float]) -> Tuple[np.ndarray, np.ndarray] 116 def get_mesh(model_info, values, dim='1d', mono=False): 117 # type: (ModelInfo, Dict[str, float], str, bool) -> List[Tuple[float, np.ndarray, np.ndarry]] 118 """ 119 Retrieve the dispersity mesh described by the parameter set. 120 121 Returns a list of *(value, dispersity, weights)* with one tuple for each 122 parameter in the model call parameters. Inactive parameters return the 123 default value with a weight of 1.0. 124 """ 125 parameters = model_info.parameters 126 if mono: 127 active = lambda name: False 128 elif dim == '1d': 129 active = lambda name: name in parameters.pd_1d 130 elif dim == '2d': 131 active = lambda name: name in parameters.pd_2d 132 else: 133 active = lambda name: True 134 135 #print("pars",[p.id for p in parameters.call_parameters]) 136 mesh = [_get_par_weights(p, values, active(p.name)) 137 for p in parameters.call_parameters] 138 return mesh 139 140 141 def _get_par_weights(parameter, values, active=True): 142 # type: (Parameter, Dict[str, float]) -> Tuple[float, np.ndarray, np.ndarray] 133 143 """ 134 144 Generate the distribution for parameter *name* given the parameter values -
sasmodels/weights.py
r8698a0d r3c24ccd 232 232 233 233 234 def plot_weights(model_info, pairs):235 # type: (ModelInfo, List[Tuple[ np.ndarray, np.ndarray]]) -> None234 def plot_weights(model_info, mesh): 235 # type: (ModelInfo, List[Tuple[float, np.ndarray, np.ndarray]]) -> None 236 236 """ 237 237 Plot the weights returned by :func:`get_weights`. 238 238 239 *model_info* is 240 :param model_info: 241 :param pairs: 242 :return: 239 *model_info* defines model parameters, etc. 240 241 *mesh* is a list of tuples containing (*value*, *dispersity*, *weights*) 242 for each parameter, where (*dispersity*, *weights*) pairs are the 243 distributions to be plotted. 243 244 """ 244 245 import pylab 245 246 246 if any(len( values)>1 for values, weights in pairs):247 if any(len(dispersity)>1 for value, dispersity, weights in mesh): 247 248 labels = [p.name for p in model_info.parameters.call_parameters] 248 pylab.interactive(True)249 #pylab.interactive(True) 249 250 pylab.figure() 250 for (v,w), s in zip(pairs, labels): 251 if len(v) > 1: 252 #print("weights for", s, v, w) 253 pylab.plot(v, w, '-o', label=s) 251 for (v,x,w), s in zip(mesh, labels): 252 if len(x) > 1: 253 pylab.plot(x, w, '-o', label=s) 254 254 pylab.grid(True) 255 255 pylab.legend()
Note: See TracChangeset
for help on using the changeset viewer.