def make_loops(pars, dtype='double'): # 0.2 ms on sparkle to form the final loops radius, length, theta, phi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuCylinder.PD_PARS] parts = [ radius.get_weights(pars['radius'], 0, 10000, True), length.get_weights(pars['length'], 0, 10000, True), theta.get_weights(pars['cyl_theta'], -np.inf, np.inf, False), phi.get_weights(pars['cyl_phi'], -np.inf, np.inf, False), ] # Make sure that weights are normalized to peaks at 1 so that # the tolerance term can be used properly on truncated distributions loops = np.hstack((v, w / w.max()) for v, w in parts) #loops = np.hstack(parts) loops = np.ascontiguousarray(loops.T, dtype).flatten() return loops, [len(p[0]) for p in parts]
def eval(self, pars): _ctx, queue = card() radius, length = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in OneDGpuCylinder.PD_PARS] #Get the weights for each radius.value, radius.weight = radius.get_weights( pars['radius'], 0, 10000, True) length.value, length.weight = length.get_weights( pars['length'], 0, 10000, True) #Perform the computation, with all weight points sum, norm, vol = 0.0, 0.0, 0.0, sub = pars['sldCyl'] - pars['sldSolv'] real = np.float32 if self.q.dtype == np.dtype( 'float32') else np.float64 #Loop over radius, length, theta, phi weight points for r in xrange(len(radius.weight)): for l in xrange(len(length.weight)): self.prg.OneDCylKernel(queue, self.q.shape, None, self.q_b, self.res_b, real(sub), real(length.value[l]), real(radius.value[r]), real(pars['scale']), np.uint32(self.q.size), real(pars['uplim']), real(pars['bolim'])) cl.enqueue_copy(queue, self.res, self.res_b) sum += radius.weight[r] * length.weight[l] * self.res * pow( radius.value[r], 2) * length.value[l] vol += radius.weight[r] * length.weight[l] * pow( radius.value[r], 2) * length.value[l] norm += radius.weight[r] * length.weight[l] if vol != 0.0 and norm != 0.0: sum *= norm / vol return sum / norm + pars['background']
def __init__(self, model_info, parameter_collection): """ Initialization""" BaseComponent.__init__(self) self.model_info = model_info pars = model_info.parameters # ===== Variable state which needs to be copied/saved ===== self.params = dict((p.name, p.default) for p in pars) self.details = dict((p.name, [p.unit, None, None]) for p in pars) self.dispersion = dict((p.name, GaussianDispersion().get_pars()) for p in pars if p.flags & ParameterFlags.Polydisperse) #list of parameter that start out fixed by default self.fixed = [] # ===== Fixed state that is not changed by the sasview gui ===== ## Name of the model self.name = model_info.name self.description = model_info.description self.non_fittable = [ p.name for p in pars if p.flags & (ParameterFlags.Unfittable | ParameterFlags.RepeatCount) ] self.orientation_params = [ p.name for p in pars if p.flags & ParameterFlags.Orientation ] self.magnetic_params = [ p.name for p in pars if p.flags & ParameterFlags.Magnetic ] ## independent parameter name and unit [string] self.input_name = "Q" self.input_unit = "A^{-1}" ## output name and unit [string] self.output_name = "Intensity" self.output_unit = "cm^{-1}"
def eval(self, pars): #b_n = radius_b # want, a_n = radius_a # want, etc ctx,queue = card() radius_a, radius_b, axis_theta, axis_phi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuEllipse.PD_PARS] radius_a.value, radius_a.weight = radius_a.get_weights(pars['radius_a'], 0, 1000, True) radius_b.value, radius_b.weight = radius_b.get_weights(pars['radius_b'], 0, 1000, True) axis_theta.value, axis_theta.weight = axis_theta.get_weights(pars['axis_theta'], -90, 180, False) axis_phi.value, axis_phi.weight = axis_phi.get_weights(pars['axis_phi'], -90, 180, False) #Perform the computation, with all weight points sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(axis_theta.weight) sub = pars['sldEll'] - pars['sldSolv'] real = np.float32 if self.qx.dtype == np.dtype('float32') else np.float64 x = [radius_a.value, radius_a.weight, radius_b.value, radius_b.weight, axis_theta.value, axis_theta.weight, axis_phi.value, axis_phi.weight] array = np.hstack(x) array_b = cl.Buffer(ctx, cl.mem_flags.READ_ONLY | cl.mem_flags.COPY_HOST_PTR, hostbuf=array) self.prg.EllipsoidKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.place_b, array_b, self.res_b, real(pars['scale']), real(sub), np.uint32(self.qx.size), np.uint32(len(axis_theta.weight))) #copy result back from buffer cl.enqueue_copy(queue, self.res, self.res_b) a = open("answer.txt", "w") for x in xrange(len(self.res)): a.write(str(self.res)) a.write("\n") return self.res+pars['background']
def eval(self, pars): #b_n = radius_b # want, a_n = radius_a # want, etc _ctx, queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) radius_a, radius_b, axis_theta, axis_phi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuEllipse.PD_PARS] radius_a.value, radius_a.weight = radius_a.get_weights( pars['radius_a'], 0, 10000, True) radius_b.value, radius_b.weight = radius_b.get_weights( pars['radius_b'], 0, 10000, True) axis_theta.value, axis_theta.weight = axis_theta.get_weights( pars['axis_theta'], -90, 180, False) axis_phi.value, axis_phi.weight = axis_phi.get_weights( pars['axis_phi'], -90, 180, False) #Perform the computation, with all weight points sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(axis_theta.weight) sub = pars['sldEll'] - pars['sldSolv'] real = np.float32 if self.qx.dtype == np.dtype( 'float32') else np.float64 #Loop over radius weight points for i in xrange(len(radius_a.weight)): #Loop over length weight points for j in xrange(len(radius_b.weight)): #Average over theta distribution vol += radius_a.weight[i] * radius_b.weight[j] * pow( radius_b.value[j], 2) * radius_a.value[i] norm_vol += radius_a.weight[i] * radius_b.weight[j] for k in xrange(len(axis_theta.weight)): #Average over phi distribution for l in xrange(len(axis_phi.weight)): #call the kernel self.prg.EllipsoidKernel( queue, self.qx.shape, None, real(radius_a.weight[i]), real(radius_b.weight[j]), real(axis_theta.weight[k]), real(axis_phi.weight[l]), real(pars['scale']), real(radius_a.value[i]), real(radius_b.value[j]), real(sub), real(axis_theta.value[k]), real(axis_phi.value[l]), self.qx_b, self.qy_b, self.res_b, np.uint32(self.qx.size), np.uint32(len(axis_theta.weight))) norm += radius_a.weight[i] * radius_b.weight[ j] * axis_theta.weight[k] * axis_phi.weight[l] # Averaging in theta needs an extra normalization # factor to account for the sin(theta) term in the # integration (see documentation). # if size > 1: # norm /= math.asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum += self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol / vol return sum / norm + pars['background']
def eval(self, pars): _ctx, queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) rad_cyl,len_cyl,rad_cap,theta,phi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuCapCylinder.PD_PARS] rad_cyl.value, rad_cyl.weight = rad_cyl.get_weights( pars['rad_cyl'], 0, 10000, True) rad_cap.value, rad_cap.weight = rad_cap.get_weights( pars['rad_cap'], 0, 10000, True) len_cyl.value, len_cyl.weight = len_cyl.get_weights( pars['len_cyl'], 0, 10000, True) theta.value, theta.weight = theta.get_weights(pars['theta'], -90, 180, False) phi.value, phi.weight = phi.get_weights(pars['phi'], -90, 180, False) sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(theta.weight) sub = pars['sld_capcyl'] - pars['sld_solv'] real = np.float32 if self.qx.dtype == np.dtype( 'float32') else np.float64 for i in xrange(len(rad_cyl.weight)): for m in xrange(len(rad_cap.weight)): for j in xrange(len(len_cyl.weight)): hDist = -1.0 * sqrt( fabs(rad_cap.value[m] * rad_cap.value[m] - rad_cyl.value[i] * rad_cyl.value[i])) vol_i = 4.0*atan(1.0)*rad_cyl.value[i]*rad_cyl.value[i]*len_cyl.value[j]+2.0*4.0*atan(1.0)/3.0\ *((rad_cap.value[m]-hDist)*(rad_cap.value[m]-hDist)*(2*rad_cap.value[m]+hDist)) vol += rad_cyl.weight[i] * len_cyl.weight[ j] * rad_cap.weight[m] * vol_i norm_vol += rad_cyl.weight[i] * len_cyl.weight[ j] * rad_cap.weight[m] for k in xrange(len(theta.weight)): for l in xrange(len(phi.weight)): self.prg.CapCylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, real(vol_i), real(hDist), real(rad_cyl.value[i]), real(rad_cap.value[m]), real(len_cyl.value[j]), real(theta.value[k]), real(phi.value[l]), real(sub), real(pars['scale']), real(phi.weight[l]), real(theta.weight[k]), real(rad_cap.weight[m]), real(rad_cyl.weight[i]), real(len_cyl.weight[j]), real(theta.weight[k]), np.uint32(self.qx.size), np.uint32(size)) norm += rad_cyl.weight[i] * len_cyl.weight[ j] * rad_cap.weight[m] * theta.weight[ k] * phi.weight[l] #if size > 1: # norm /= asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum += self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol / vol return sum / norm + pars['background']
def eval(self, pars): _ctx, queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) radius, length, thickness, axis_phi, axis_theta = [ GaussianDispersion(int(pars[base + '_pd_n']), pars[base + '_pd'], pars[base + '_pd_nsigma']) for base in GpuCoreShellCylinder.PD_PARS ] radius.value, radius.weight = radius.get_weights( pars['radius'], 0, 10000, True) length.value, length.weight = length.get_weights( pars['length'], 0, 10000, True) thickness.value, thickness.weight = thickness.get_weights( pars['thickness'], 0, 10000, True) axis_phi.value, axis_phi.weight = axis_phi.get_weights( pars['axis_phi'], -90, 180, False) axis_theta.value, axis_theta.weight = axis_theta.get_weights( pars['axis_theta'], -90, 180, False) sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(axis_theta.weight) real = np.float32 if self.qx.dtype == np.dtype( 'float32') else np.float64 for r in xrange(len(radius.weight)): for l in xrange(len(length.weight)): for th in xrange(len(thickness.weight)): vol += radius.weight[r]*length.weight[l]*thickness.weight[th]*pow(radius.value[r]+thickness.value[th],2)\ *(length.value[l]+2.0*thickness.value[th]) norm_vol += radius.weight[r] * length.weight[ l] * thickness.weight[th] for at in xrange(len(axis_theta.weight)): for p in xrange(len(axis_phi.weight)): self.prg.CoreShellCylinderKernel( queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, real(axis_theta.value[at]), real(axis_phi.value[p]), real(thickness.value[th]), real(length.value[l]), real(radius.value[r]), real(pars['scale']), real(radius.weight[r]), real(length.weight[l]), real(thickness.weight[th]), real(axis_theta.weight[at]), real(axis_phi.weight[p]), real(pars['core_sld']), real(pars['shell_sld']), real(pars['solvent_sld']), np.uint32(size), np.uint32(self.qx.size)) norm += radius.weight[r]*length.weight[l]*thickness.weight[th]*axis_theta.weight[at]\ *axis_phi.weight[p] #if size>1: # norm /= math.asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum = self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol / vol return sum / norm + pars['background']
def eval(self, pars): _ctx, queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) semi_axisA, semi_axisB, semi_axisC, axis_theta, axis_phi, axis_psi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuTriEllipse.PD_PARS] semi_axisA.value, semi_axisA.weight = semi_axisA.get_weights( pars['semi_axisA'], 0, 10000, True) semi_axisB.value, semi_axisB.weight = semi_axisB.get_weights( pars['semi_axisB'], 0, 10000, True) semi_axisC.value, semi_axisC.weight = semi_axisC.get_weights( pars['semi_axisC'], 0, 10000, True) axis_theta.value, axis_theta.weight = axis_theta.get_weights( pars['axis_theta'], -90, 180, False) axis_phi.value, axis_phi.weight = axis_phi.get_weights( pars['axis_phi'], -90, 180, False) axis_psi.value, axis_psi.weight = axis_psi.get_weights( pars['axis_psi'], -90, 180, False) sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(axis_theta.weight) sub = pars['sldEll'] - pars['sldSolv'] real = np.float32 if self.qx.dtype == np.dtype( 'float32') else np.float64 for a in xrange(len(semi_axisA.weight)): for b in xrange(len(semi_axisB.weight)): for c in xrange(len(semi_axisC.weight)): vol += semi_axisA.weight[a] * semi_axisB.weight[ b] * semi_axisC.weight[c] * semi_axisA.value[ a] * semi_axisB.value[b] * semi_axisC.value[c] norm_vol += semi_axisA.weight[a] * semi_axisB.weight[ b] * semi_axisC.weight[c] for t in xrange(len(axis_theta.weight)): for i in xrange(len(axis_phi.weight)): for s in xrange(len(axis_psi.weight)): self.prg.TriaxialEllipseKernel( queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, real(sub), real(pars['scale']), real(semi_axisA.value[a]), real(semi_axisB.value[b]), real(semi_axisC.value[c]), real(axis_phi.value[i]), real(axis_theta.value[t]), real(axis_psi.value[s]), real(semi_axisA.weight[a]), real(semi_axisB.weight[b]), real(semi_axisC.weight[c]), real(axis_psi.weight[s]), real(axis_phi.weight[i]), real(axis_theta.weight[t]), np.uint32(self.qx.size), np.uint32(size)) norm += semi_axisA.weight[ a] * semi_axisB.weight[ b] * semi_axisC.weight[ c] * axis_theta.weight[ t] * axis_phi.weight[ i] * axis_psi.weight[s] # if size > 1: # norm /= asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum = self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol / vol return sum / norm + pars['background']
def eval(self, pars): tic() _ctx, queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) radius, length, cyl_theta, cyl_phi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuCylinder.PD_PARS] #Get the weights for each radius.value, radius.weight = radius.get_weights( pars['radius'], 0, 10000, True) length.value, length.weight = length.get_weights( pars['length'], 0, 10000, True) cyl_theta.value, cyl_theta.weight = cyl_theta.get_weights( pars['cyl_theta'], -np.inf, np.inf, False) cyl_phi.value, cyl_phi.weight = cyl_phi.get_weights( pars['cyl_phi'], -np.inf, np.inf, False) #Perform the computation, with all weight points sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(cyl_theta.weight) sub = pars['sldCyl'] - pars['sldSolv'] real = np.float32 if self.qx.dtype == np.dtype( 'float32') else np.float64 #Loop over radius, length, theta, phi weight points for i in xrange(len(radius.weight)): for j in xrange(len(length.weight)): vol += radius.weight[i] * length.weight[j] * pow( radius.value[i], 2) * length.value[j] norm_vol += radius.weight[i] * length.weight[j] for k in xrange(len(cyl_theta.weight)): for l in xrange(len(cyl_phi.weight)): self.prg.CylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, real(sub), real(radius.value[i]), real(length.value[j]), real(pars['scale']), real(radius.weight[i]), real(length.weight[j]), real(cyl_theta.weight[k]), real(cyl_phi.weight[l]), real(cyl_theta.value[k]), real(cyl_phi.value[l]), np.uint32(self.qx.size), np.uint32(size)) norm += radius.weight[i] * length.weight[ j] * cyl_theta.weight[k] * cyl_phi.weight[l] # if size > 1: # norm /= math.asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum = self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol / vol print toc() * 1000, self.qx.shape[0] return sum / norm + pars['background']