Changeset 9a5097c in sasview for src/sas/sascalc/fit
- Timestamp:
- Mar 26, 2017 11:33:16 PM (8 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- ed2276f
- Parents:
- 9146ed9
- Location:
- src/sas/sascalc/fit
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/fit/AbstractFitEngine.py
ra9f579c r9a5097c 4 4 import sys 5 5 import math 6 import numpy 6 import numpy as np 7 7 8 8 from sas.sascalc.dataloader.data_info import Data1D … … 162 162 # constant, or dy data 163 163 if dy is None or dy == [] or dy.all() == 0: 164 self.dy = n umpy.ones(len(y))164 self.dy = np.ones(len(y)) 165 165 else: 166 self.dy = n umpy.asarray(dy).copy()166 self.dy = np.asarray(dy).copy() 167 167 168 168 ## Min Q-value 169 169 #Skip the Q=0 point, especially when y(q=0)=None at x[0]. 170 170 if min(self.x) == 0.0 and self.x[0] == 0 and\ 171 not n umpy.isfinite(self.y[0]):171 not np.isfinite(self.y[0]): 172 172 self.qmin = min(self.x[self.x != 0]) 173 173 else: … … 188 188 # Skip Q=0 point, (especially for y(q=0)=None at x[0]). 189 189 # ToDo: Find better way to do it. 190 if qmin == 0.0 and not n umpy.isfinite(self.y[qmin]):190 if qmin == 0.0 and not np.isfinite(self.y[qmin]): 191 191 self.qmin = min(self.x[self.x != 0]) 192 192 elif qmin != None: … … 239 239 """ 240 240 # Compute theory data f(x) 241 fx = n umpy.zeros(len(self.x))241 fx = np.zeros(len(self.x)) 242 242 fx[self.idx_unsmeared] = fn(self.x[self.idx_unsmeared]) 243 243 … … 247 247 self._last_unsmeared_bin) 248 248 ## Sanity check 249 if n umpy.size(self.dy) != numpy.size(fx):249 if np.size(self.dy) != np.size(fx): 250 250 msg = "FitData1D: invalid error array " 251 msg += "%d <> %d" % (n umpy.shape(self.dy), numpy.size(fx))251 msg += "%d <> %d" % (np.shape(self.dy), np.size(fx)) 252 252 raise RuntimeError, msg 253 253 return (self.y[self.idx] - fx[self.idx]) / self.dy[self.idx], fx[self.idx] … … 300 300 ## new error image for fitting purpose 301 301 if self.err_data == None or self.err_data == []: 302 self.res_err_data = n umpy.ones(len(self.data))302 self.res_err_data = np.ones(len(self.data)) 303 303 else: 304 304 self.res_err_data = copy.deepcopy(self.err_data) 305 305 #self.res_err_data[self.res_err_data==0]=1 306 306 307 self.radius = n umpy.sqrt(self.qx_data**2 + self.qy_data**2)307 self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) 308 308 309 309 # Note: mask = True: for MASK while mask = False for NOT to mask … … 311 311 (self.radius <= self.qmax)) 312 312 self.idx = (self.idx) & (self.mask) 313 self.idx = (self.idx) & (n umpy.isfinite(self.data))314 self.num_points = n umpy.sum(self.idx)313 self.idx = (self.idx) & (np.isfinite(self.data)) 314 self.num_points = np.sum(self.idx) 315 315 316 316 def set_smearer(self, smearer): … … 334 334 if qmax != None: 335 335 self.qmax = qmax 336 self.radius = n umpy.sqrt(self.qx_data**2 + self.qy_data**2)336 self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) 337 337 self.idx = ((self.qmin <= self.radius) &\ 338 338 (self.radius <= self.qmax)) 339 339 self.idx = (self.idx) & (self.mask) 340 self.idx = (self.idx) & (n umpy.isfinite(self.data))340 self.idx = (self.idx) & (np.isfinite(self.data)) 341 341 self.idx = (self.idx) & (self.res_err_data != 0) 342 342 … … 351 351 Number of measurement points in data set after masking, etc. 352 352 """ 353 return n umpy.sum(self.idx)353 return np.sum(self.idx) 354 354 355 355 def residuals(self, fn): -
src/sas/sascalc/fit/BumpsFitting.py
r1a30720 r9a5097c 6 6 import traceback 7 7 8 import numpy 8 import numpy as np 9 9 10 10 from bumps import fitters … … 97 97 try: 98 98 p = history.population_values[0] 99 n,p = len(p), n umpy.sort(p)99 n,p = len(p), np.sort(p) 100 100 QI,Qmid, = int(0.2*n),int(0.5*n) 101 101 self.convergence.append((best, p[0],p[QI],p[Qmid],p[-1-QI],p[-1])) … … 194 194 195 195 def numpoints(self): 196 return n umpy.sum(self.data.idx) # number of fitted points196 return np.sum(self.data.idx) # number of fitted points 197 197 198 198 def nllf(self): 199 return 0.5*n umpy.sum(self.residuals()**2)199 return 0.5*np.sum(self.residuals()**2) 200 200 201 201 def theory(self): … … 295 295 if R.success: 296 296 if result['stderr'] is None: 297 R.stderr = n umpy.NaN*numpy.ones(len(param_list))297 R.stderr = np.NaN*np.ones(len(param_list)) 298 298 else: 299 R.stderr = n umpy.hstack((result['stderr'][fitted_index],300 numpy.NaN*numpy.ones(len(fitness.computed_pars))))301 R.pvec = n umpy.hstack((result['value'][fitted_index],299 R.stderr = np.hstack((result['stderr'][fitted_index], 300 np.NaN*np.ones(len(fitness.computed_pars)))) 301 R.pvec = np.hstack((result['value'][fitted_index], 302 302 [p.value for p in fitness.computed_pars])) 303 R.fitness = n umpy.sum(R.residuals**2)/(fitness.numpoints() - len(fitted_index))303 R.fitness = np.sum(R.residuals**2)/(fitness.numpoints() - len(fitted_index)) 304 304 else: 305 R.stderr = n umpy.NaN*numpy.ones(len(param_list))306 R.pvec = n umpy.asarray( [p.value for p in fitness.fitted_pars+fitness.computed_pars])307 R.fitness = n umpy.NaN305 R.stderr = np.NaN*np.ones(len(param_list)) 306 R.pvec = np.asarray( [p.value for p in fitness.fitted_pars+fitness.computed_pars]) 307 R.fitness = np.NaN 308 308 R.convergence = result['convergence'] 309 309 if result['uncertainty'] is not None: … … 336 336 max_step = steps + options.get('burn', 0) 337 337 pars = [p.name for p in problem._parameters] 338 #x0 = n umpy.asarray([p.value for p in problem._parameters])338 #x0 = np.asarray([p.value for p in problem._parameters]) 339 339 options['monitors'] = [ 340 340 BumpsMonitor(handler, max_step, pars, problem.dof), … … 351 351 errors = [] 352 352 except Exception as exc: 353 best, fbest = None, n umpy.NaN353 best, fbest = None, np.NaN 354 354 errors = [str(exc), traceback.format_exc()] 355 355 finally: … … 358 358 359 359 convergence_list = options['monitors'][-1].convergence 360 convergence = (2*n umpy.asarray(convergence_list)/problem.dof361 if convergence_list else n umpy.empty((0,1),'d'))360 convergence = (2*np.asarray(convergence_list)/problem.dof 361 if convergence_list else np.empty((0,1),'d')) 362 362 363 363 success = best is not None -
src/sas/sascalc/fit/Loader.py
rb699768 r9a5097c 2 2 #import wx 3 3 #import string 4 import numpy 4 import numpy as np 5 5 6 6 class Load: … … 52 52 self.y.append(y) 53 53 self.dy.append(dy) 54 self.dx = n umpy.zeros(len(self.x))54 self.dx = np.zeros(len(self.x)) 55 55 except: 56 56 print "READ ERROR", line -
src/sas/sascalc/fit/MultiplicationModel.py
r68669da r9a5097c 1 1 import copy 2 2 3 import numpy 3 import numpy as np 4 4 5 5 from sas.sascalc.calculator.BaseComponent import BaseComponent … … 52 52 ## Parameter details [units, min, max] 53 53 self._set_details() 54 self.details['scale_factor'] = ['', 0.0, n umpy.inf]55 self.details['background'] = ['',-n umpy.inf,numpy.inf]54 self.details['scale_factor'] = ['', 0.0, np.inf] 55 self.details['background'] = ['',-np.inf,np.inf] 56 56 57 57 #list of parameter that can be fitted -
src/sas/sascalc/fit/expression.py
rb699768 r9a5097c 271 271 272 272 def test_deps(): 273 import numpy 273 import numpy as np 274 274 275 275 # Null case … … 279 279 _check("test1",[(2,7),(1,5),(1,4),(2,1),(3,1),(5,6)]) 280 280 _check("test1 renumbered",[(6,1),(7,3),(7,4),(6,7),(5,7),(3,2)]) 281 _check("test1 numpy",n umpy.array([(2,7),(1,5),(1,4),(2,1),(3,1),(5,6)]))281 _check("test1 numpy",np.array([(2,7),(1,5),(1,4),(2,1),(3,1),(5,6)])) 282 282 283 283 # No dependencies … … 291 291 292 292 # large test for gross speed check 293 A = n umpy.random.randint(4000,size=(1000,2))293 A = np.random.randint(4000,size=(1000,2)) 294 294 A[:,1] += 4000 # Avoid cycles 295 295 _check("test-large",A) … … 297 297 # depth tests 298 298 k = 200 299 A = n umpy.array([range(0,k),range(1,k+1)]).T299 A = np.array([range(0,k),range(1,k+1)]).T 300 300 _check("depth-1",A) 301 301 302 A = n umpy.array([range(1,k+1),range(0,k)]).T302 A = np.array([range(1,k+1),range(0,k)]).T 303 303 _check("depth-2",A) 304 304
Note: See TracChangeset
for help on using the changeset viewer.