Changeset 9e771a3 in sasmodels


Ignore:
Timestamp:
Oct 18, 2017 10:51:08 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
94f4543
Parents:
9b7b23f
Message:

sort out weights (seems to be correct this time)

Location:
sasmodels
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/core.py

    ra85a569 r9e771a3  
    272272    Possible types include 'half', 'single', 'double' and 'quad'.  If the 
    273273    type is 'fast', then this is equivalent to dtype 'single' but using 
    274     fast native functions rather than those with the precision level guaranteed 
    275     by the OpenCL standard. 
     274    fast native functions rather than those with the precision level 
     275    guaranteed by the OpenCL standard.  'default' will choose the appropriate 
     276    default for the model and platform. 
    276277 
    277278    Platform preference can be specfied ("ocl" vs "dll"), with the default 
  • sasmodels/details.py

    r3c24ccd r9e771a3  
    234234    # skipping scale and background when building values and weights 
    235235    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, dispersity, weights) 
    237237    length = np.array([len(w) for w in weights]) 
    238238    offset = np.cumsum(np.hstack((0, length))) 
     
    247247    return call_details, data, is_magnetic 
    248248 
    249 def correct_theta_weights(parameters, values, weights): 
     249def correct_theta_weights(parameters, dispersity, weights): 
    250250    # type: (ParameterTable, Sequence[np.ndarray], Sequence[np.ndarray]) -> Sequence[np.ndarray] 
    251251    """ 
    252252    If there is a theta parameter, update the weights of that parameter so that 
    253     the cosine weighting required for polar integration is preserved.  Avoid 
    254     evaluation strictly at the pole, which would otherwise send the weight to 
    255     zero. 
    256  
    257     Note: values and weights do not include scale and background 
    258     """ 
    259     # TODO: document code, explaining why scale and background are skipped 
    260     # given that we don't have scale and background in the list, we 
    261     # should be calling the variables something other than values and weights 
     253    the cosine weighting required for polar integration is preserved. 
     254 
     255    Avoid evaluation strictly at the pole, which would otherwise send the 
     256    weight to zero.  This is probably not a problem in practice (if dispersity 
     257    is +/- 90, then you probably should be using a 1-D model of the circular 
     258    average). 
     259 
     260    Note: scale and background parameters are not include in the tuples for 
     261    dispersity and weights, so index is parameters.theta_offset, not 
     262    parameters.theta_offset+2 
     263 
     264    Returns updated weights vectors 
     265    """ 
     266    # TODO: explain in a comment why scale and background are missing 
    262267    # Apparently the parameters.theta_offset similarly skips scale and 
    263     # and background, so the indexing works out. 
     268    # and background, so the indexing works out, but they are still shipped 
     269    # to the kernel, so we need to add two there. 
    264270    if parameters.theta_offset >= 0: 
    265271        index = parameters.theta_offset 
    266         theta = values[index] 
    267         theta_weight = np.minimum(abs(cos(radians(theta))), 1e-6) 
    268         # copy the weights list so we can update it 
    269         weights = list(weights) 
    270         weights[index] = theta_weight*np.asarray(weights[index]) 
    271         weights = tuple(weights) 
     272        theta = dispersity[index] 
     273        # TODO: modify the dispersity vector to avoid the theta=-90,90,270,... 
     274        theta_weight = abs(cos(radians(theta))) 
     275        weights = tuple(theta_weight*v if k == index else v 
     276                        for k, v in enumerate(weights)) 
    272277    return weights 
    273278 
  • sasmodels/direct_model.py

    r3c24ccd r9e771a3  
    5656    """ 
    5757    mesh = get_mesh(calculator.info, pars, dim=calculator.dim, mono=mono) 
     58    #print("pars", list(zip(*mesh))[0]) 
    5859    call_details, values, is_magnetic = make_kernel_args(calculator, mesh) 
    5960    #print("values:", values) 
     
    152153    width = values.get(parameter.name+'_pd', 0.0) 
    153154    relative = parameter.relative_pd 
    154     if npts == 0 or width == 0 or not active: 
     155    if npts == 0 or width == 0.0 or not active: 
    155156        # Note: orientation parameters have the viewing angle as the parameter 
    156157        # value and the jitter in the distribution, so be sure to set the 
    157158        # empty pd for orientation parameters to 0. 
    158         pd = [value if relative else 0.0], [1.0] 
     159        pd = [value if relative or not parameter.polydisperse else 0.0], [1.0] 
    159160    else: 
    160161        limits = parameter.limits 
     
    166167 
    167168 
    168 def _vol_pars(model_info, pars): 
     169def _vol_pars(model_info, values): 
    169170    # type: (ModelInfo, ParameterSet) -> Tuple[np.ndarray, np.ndarray] 
    170     vol_pars = [get_weights(p, pars) 
     171    vol_pars = [_get_par_weights(p, values) 
    171172                for p in model_info.parameters.call_parameters 
    172173                if p.type == 'volume'] 
    173174    #import pylab; pylab.plot(vol_pars[0][0],vol_pars[0][1]); pylab.show() 
    174     value, weight = dispersion_mesh(model_info, vol_pars) 
    175     return value, weight 
     175    dispersity, weight = dispersion_mesh(model_info, vol_pars) 
     176    return dispersity, weight 
    176177 
    177178 
Note: See TracChangeset for help on using the changeset viewer.