Changeset 0763009 in sasmodels for compare.py
- Timestamp:
- Oct 29, 2015 6:08:10 PM (9 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:
- 381ac85
- Parents:
- 3d5c6f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
compare.py
r3e6aaad r0763009 100 100 model = sasview_model(name, **pars) 101 101 smearer = smear_selection(data, model=model) 102 value = None # silence the linter 102 103 toc = tic() 103 for _ in range( Nevals):104 for _ in range(max(Nevals, 1)): # make sure there is at least one eval 104 105 if hasattr(data, 'qx_data'): 105 106 q = np.sqrt(data.qx_data**2 + data.qy_data**2) … … 120 121 return value, average_time 121 122 122 def eval_opencl(model_definition, pars, data, dtype='single', Nevals=1, cutoff=0 ):123 def eval_opencl(model_definition, pars, data, dtype='single', Nevals=1, cutoff=0.): 123 124 try: 124 125 model = core.load_model(model_definition, dtype=dtype, platform="ocl") … … 128 129 model = core.load_model(model_definition, dtype='single', platform="ocl") 129 130 problem = Experiment(data, Model(model, **pars), cutoff=cutoff) 131 value = None # silence the linter 130 132 toc = tic() 131 for _ in range( Nevals):133 for _ in range(max(Nevals, 1)): # force at least one eval 132 134 #pars['scale'] = np.random.rand() 133 135 problem.update() … … 136 138 return value, average_time 137 139 138 def eval_ctypes(model_definition, pars, data, dtype='double', Nevals=1, cutoff=0 ):140 def eval_ctypes(model_definition, pars, data, dtype='double', Nevals=1, cutoff=0.): 139 141 model = core.load_model(model_definition, dtype=dtype, platform="dll") 140 142 problem = Experiment(data, Model(model, **pars), cutoff=cutoff) 143 value = None # silence the linter 141 144 toc = tic() 142 for _ in range( Nevals):145 for _ in range(max(Nevals, 1)): # force at least one eval 143 146 problem.update() 144 147 value = problem.theory() … … 224 227 #bad = (relerr>1e-4) 225 228 #print relerr[bad],cpu[bad],ocl[bad],data.qx_data[bad],data.qy_data[bad] 226 def stats(label,err): 227 sorted_err = np.sort(abs(err)) 228 p50 = int((len(err)-1)*0.50) 229 p98 = int((len(err)-1)*0.98) 230 data = [ 231 "max:%.3e"%sorted_err[-1], 232 "median:%.3e"%sorted_err[p50], 233 "98%%:%.3e"%sorted_err[p98], 234 "rms:%.3e"%np.sqrt(np.mean(err**2)), 235 "zero-offset:%+.3e"%np.mean(err), 236 ] 237 print label," ".join(data) 238 stats("|ocl-%s|"%comp+(" "*(3+len(comp))), resid) 239 stats("|(ocl-%s)/%s|"%(comp,comp), relerr) 229 _print_stats("|ocl-%s|"%comp+(" "*(3+len(comp))), resid) 230 _print_stats("|(ocl-%s)/%s|"%(comp,comp), relerr) 240 231 241 232 # Plot if requested … … 277 268 plt.show() 278 269 270 def _print_stats(label, err): 271 sorted_err = np.sort(abs(err)) 272 p50 = int((len(err)-1)*0.50) 273 p98 = int((len(err)-1)*0.98) 274 data = [ 275 "max:%.3e"%sorted_err[-1], 276 "median:%.3e"%sorted_err[p50], 277 "98%%:%.3e"%sorted_err[p98], 278 "rms:%.3e"%np.sqrt(np.mean(err**2)), 279 "zero-offset:%+.3e"%np.mean(err), 280 ] 281 print label," ".join(data) 282 283 284 279 285 # =========================================================================== 280 286 #
Note: See TracChangeset
for help on using the changeset viewer.