Changeset 2d06beb in sasview for pr_inversion/test
- Timestamp:
- May 5, 2008 2:03:39 PM (17 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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- b43a009
- Parents:
- 150c04a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pr_inversion/test/utest_invertor.py
reca05c8 r2d06beb 174 174 print "chi2 =", chi2/51.0 175 175 raise 176 177 def test_lstsq(self): 178 """ 179 Test an inversion for which we know the answer 180 """ 181 x, y, err = load("sphere_80.txt") 182 183 # Choose the right d_max... 184 self.invertor.d_max = 160.0 185 # Set a small alpha 186 self.invertor.alpha = .0007 187 # Set data 188 self.invertor.x = x 189 self.invertor.y = y 190 self.invertor.err = err 191 # Perform inversion 192 #out, cov = self.invertor.invert(10) 193 194 out, cov = self.invertor.lstsq(10) 195 196 197 # This is a very specific case 198 # We should make sure it always passes 199 try: 200 self.assertTrue(self.invertor.chi2/len(x)<200.00) 201 except: 202 print "Chi2(I(q)) =", self.invertor.chi2/len(x) 203 raise 204 205 # Check the computed P(r) with the theory 206 # for shpere of radius 80 207 x = pylab.arange(0.01, self.invertor.d_max, self.invertor.d_max/51.0) 208 y = numpy.zeros(len(x)) 209 dy = numpy.zeros(len(x)) 210 y_true = numpy.zeros(len(x)) 211 212 sum = 0.0 213 sum_true = 0.0 214 for i in range(len(x)): 215 #y[i] = self.invertor.pr(out, x[i]) 216 (y[i], dy[i]) = self.invertor.pr_err(out, cov, x[i]) 217 sum += y[i] 218 if x[i]<80.0: 219 y_true[i] = pr_theory(x[i], 80.0) 220 else: 221 y_true[i] = 0 222 sum_true += y_true[i] 223 224 y = y/sum*self.invertor.d_max/len(x) 225 dy = dy/sum*self.invertor.d_max/len(x) 226 y_true = y_true/sum_true*self.invertor.d_max/len(x) 227 228 chi2 = 0.0 229 for i in range(len(x)): 230 res = (y[i]-y_true[i])/dy[i] 231 chi2 += res*res 232 233 try: 234 self.assertTrue(chi2/51.0<50.0) 235 except: 236 print "chi2(P(r)) =", chi2/51.0 237 raise 176 238 177 239 def test_q_zero(self): … … 239 301 print "Chi2 =", self.invertor.chi2 240 302 raise 303 304 def no_test_time(self): 305 x, y, err = load("sphere_80.txt") 306 307 # Choose the right d_max... 308 self.invertor.d_max = 160.0 309 # Set a small alpha 310 self.invertor.alpha = 1e-7 311 # Set data 312 self.invertor.x = x 313 self.invertor.y = y 314 self.invertor.err = err 315 316 # time scales like nfunc**2 317 # on a Lenovo Intel Core 2 CPU T7400 @ 2.16GHz, 318 # I get time/(nfunc)**2 = 0.022 sec 241 319 242 243 320 out, cov = self.invertor.invert(15) 321 t16 = self.invertor.elapsed 322 323 out, cov = self.invertor.invert(30) 324 t30 = self.invertor.elapsed 325 326 t30s = t30/30.0**2 327 self.assertTrue( (t30s-t16/16.0**2)/t30s <1.2 ) 328 329 def test_clone(self): 330 self.invertor.x = self.x_in 331 clone = self.invertor.clone() 332 333 for i in range(len(self.x_in)): 334 self.assertEqual(self.x_in[i], clone.x[i]) 335 244 336 def pr_theory(r, R): 245 337 """
Note: See TracChangeset
for help on using the changeset viewer.