Changeset 59b9b675 in sasview for sansmodels/src/sans/models
- Timestamp:
- Feb 25, 2011 9:20:10 AM (14 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:
- 01b6bd0
- Parents:
- ea5692d
- Location:
- sansmodels/src/sans/models
- Files:
-
- 14 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/c_models/c_models.cpp
r770bab1 r59b9b675 290 290 addCMultiShellModel(m); 291 291 addCBinaryHSModel(m); 292 //addDisperser(m);293 //addCGaussian(m);294 //addCSchulz(m);295 //addCLogNormal(m);296 //addCLorentzian(m);292 addDisperser(m); 293 addCGaussian(m); 294 addCSchulz(m); 295 addCLogNormal(m); 296 addCLorentzian(m); 297 297 addCVesicleModel(m); 298 298 addCPoly_GaussCoil(m); -
sansmodels/src/sans/models/c_models/parameters.cpp
r8dc02d8b r59b9b675 58 58 Parameter* par = (Parameter*)param; 59 59 double value = (*par)(); 60 61 if (npts<2) { 62 weights.insert(weights.end(), WeightPoint(value, 1.0)); 63 } else { 64 for(int i=0; i<npts; i++) { 65 double val = value + width * (1.0*double(i)/double(npts-1) - 0.5); 66 60 double sig; 61 if (npts<2) { 62 weights.insert(weights.end(), WeightPoint(value, 1.0)); 63 } else { 64 for(int i=0; i<npts; i++) { 65 66 if ((*par).has_min==false){ 67 // width = sigma for angles 68 sig = width; 69 } 70 else{ 71 //width = polydispersity (=sigma/value) for length 72 sig = width * value; 73 } 74 double val = value + sig * (1.0*double(i)/double(npts-1) - 0.5); 67 75 if ( ((*par).has_min==false || val>(*par).min) 68 76 && ((*par).has_max==false || val<(*par).max) ) … … 83 91 84 92 GaussianDispersion :: GaussianDispersion() { 85 npts = 21;93 npts = 11; 86 94 width = 0.0; 87 nsigmas = 3.0;95 nsigmas = 2.5; 88 96 }; 89 97 … … 115 123 width = 0.0; 116 124 npts = 1; 117 nsigmas = 3.0; 118 } 119 120 Parameter* par = (Parameter*)param; 121 double value = (*par)(); 122 123 if (npts<2) { 124 weights.insert(weights.end(), WeightPoint(value, 1.0)); 125 } else { 126 for(int i=0; i<npts; i++) { 125 nsigmas = 2.5; 126 } 127 128 Parameter* par = (Parameter*)param; 129 double value = (*par)(); 130 double sig; 131 if (npts<2) { 132 weights.insert(weights.end(), WeightPoint(value, 1.0)); 133 } else { 134 for(int i=0; i<npts; i++) { 135 if ((*par).has_min==false){ 136 // width = sigma for angles 137 sig = width; 138 } 139 else{ 140 //width = polydispersity (=sigma/value) for length 141 sig = width * value; 142 } 127 143 // We cover n(nsigmas) times sigmas on each side of the mean 128 double val = value + width* (2.0*nsigmas*double(i)/double(npts-1) - nsigmas);144 double val = value + sig * (2.0*nsigmas*double(i)/double(npts-1) - nsigmas); 129 145 if ( ((*par).has_min==false || val>(*par).min) 130 146 && ((*par).has_max==false || val<(*par).max) ) { 131 double _w = gaussian_weight(value, width, val);147 double _w = gaussian_weight(value, sig, val); 132 148 weights.insert(weights.end(), WeightPoint(val, _w)); 133 149 } … … 142 158 143 159 RectangleDispersion :: RectangleDispersion() { 144 npts = 21;160 npts = 11; 145 161 width = 0.0; 146 162 nsigmas = 1.0; … … 182 198 Parameter* par = (Parameter*)param; 183 199 double value = (*par)(); 184 185 if (npts<2) { 186 weights.insert(weights.end(), WeightPoint(value, 1.0)); 187 } else { 188 for(int i=0; i<npts; i++) { 200 double sig; 201 if (npts<2) { 202 weights.insert(weights.end(), WeightPoint(value, 1.0)); 203 } else { 204 for(int i=0; i<npts; i++) { 205 if ((*par).has_min==false){ 206 // width = sigma for angles 207 sig = width; 208 } 209 else{ 210 //width = polydispersity (=sigma/value) for length 211 sig = width * value; 212 } 189 213 // We cover n(nsigmas) times sigmas on each side of the mean 190 double val = value + width* (2.0*nsigmas*double(i)/double(npts-1) - nsigmas);214 double val = value + sig * (2.0*nsigmas*double(i)/double(npts-1) - nsigmas); 191 215 if ( ((*par).has_min==false || val>(*par).min) 192 216 && ((*par).has_max==false || val<(*par).max) ) { 193 double _w = rectangle_weight(value, width, val);217 double _w = rectangle_weight(value, sig, val); 194 218 weights.insert(weights.end(), WeightPoint(val, _w)); 195 219 } … … 204 228 205 229 LogNormalDispersion :: LogNormalDispersion() { 206 npts = 21;230 npts = 11; 207 231 width = 0.0; 208 232 nsigmas = 3.0; … … 240 264 Parameter* par = (Parameter*)param; 241 265 double value = (*par)(); 242 243 if (npts<2) { 244 weights.insert(weights.end(), WeightPoint(value, 1.0)); 245 } else { 246 for(int i=0; i<npts; i++) { 266 double sig; 267 if (npts<2) { 268 weights.insert(weights.end(), WeightPoint(value, 1.0)); 269 } else { 270 for(int i=0; i<npts; i++) { 271 if ((*par).has_min==false){ 272 // width = sigma for angles 273 sig = width; 274 } 275 else{ 276 //width = polydispersity (=sigma/value) for length 277 sig = width * value; 278 } 247 279 // We cover n(nsigmas) times sigmas on each side of the mean 248 double val = value + width* (2.0*nsigmas*double(i)/double(npts-1) - nsigmas);280 double val = value + sig * (2.0*nsigmas*double(i)/double(npts-1) - nsigmas); 249 281 250 282 if ( ((*par).has_min==false || val>(*par).min) 251 283 && ((*par).has_max==false || val<(*par).max) ) { 252 double _w = lognormal_weight(value, width, val);284 double _w = lognormal_weight(value, sig, val); 253 285 weights.insert(weights.end(), WeightPoint(val, _w)); 254 286 } … … 264 296 265 297 SchulzDispersion :: SchulzDispersion() { 266 npts = 21;298 npts = 11; 267 299 width = 0.0; 268 300 nsigmas = 3.0; … … 303 335 Parameter* par = (Parameter*)param; 304 336 double value = (*par)(); 305 306 if (npts<2) { 307 weights.insert(weights.end(), WeightPoint(value, 1.0)); 308 } else { 309 for(int i=0; i<npts; i++) { 337 double sig; 338 if (npts<2) { 339 weights.insert(weights.end(), WeightPoint(value, 1.0)); 340 } else { 341 for(int i=0; i<npts; i++) { 342 if ((*par).has_min==false){ 343 // width = sigma for angles 344 sig = width; 345 } 346 else{ 347 //width = polydispersity (=sigma/value) for length 348 sig = width * value; 349 } 310 350 // We cover n(nsigmas) times sigmas on each side of the mean 311 double val = value + width* (2.0*nsigmas*double(i)/double(npts-1) - nsigmas);351 double val = value + sig * (2.0*nsigmas*double(i)/double(npts-1) - nsigmas); 312 352 313 353 if ( ((*par).has_min==false || val>(*par).min) 314 354 && ((*par).has_max==false || val<(*par).max) ) { 315 double _w = schulz_weight(value, width, val);355 double _w = schulz_weight(value, sig, val); 316 356 weights.insert(weights.end(), WeightPoint(val, _w)); 317 357 } … … 346 386 for(int i=0; i<npts; i++) { 347 387 double val = _values[i]; //+ value; //ToDo: Talk to Paul and put back the 'value'. 388 348 389 if ( ((*par).has_min==false || val>(*par).min) 349 390 && ((*par).has_max==false || val<(*par).max) ) -
sansmodels/src/sans/models/test/utest_dispersity.py
r18b89c4 r59b9b675 3 3 C++ model classes 4 4 """ 5 6 #Note: The 'sans.models.DisperseModel' is for only the test. We use 7 #'sans.models.dispersion_models', instead in the application. 8 #The first uses width = sigma, while the second uses width = ratio (=sigma/mean) 9 #for length parameters and width = sigma for angle parameters. 10 #In Feb. 2011, we found and fixed the some precision problems in the C, so that 11 #this test was updated too. 12 5 13 6 14 import unittest, math, numpy … … 32 40 self.model.setParam('scale', 10.0) 33 41 self.model.set_dispersion('radius', disp) 34 self.model.dispersion['radius']['width'] = 5.042 self.model.dispersion['radius']['width'] = 0.25 35 43 self.model.dispersion['radius']['npts'] = 100 36 44 self.model.dispersion['radius']['nsigmas'] = 2.5 37 45 38 46 self.assertAlmostEqual(self.model.run(0.001), 1.021051*4527.47250339, 3) 39 self.assertAlmostEqual(self.model.runXY([0.001, 0.001]), 1.021048*4546.997777604715, 2) 47 self.assertAlmostEqual(self.model.runXY([0.001, 0.001]), 48 1.021048*4546.997777604715, 2) 40 49 41 50 def test_gaussian(self): … … 43 52 disp = GaussianDispersion() 44 53 self.model.set_dispersion('radius', disp) 45 self.model.dispersion['radius']['width'] = 5.054 self.model.dispersion['radius']['width'] = 0.25 46 55 self.model.dispersion['radius']['npts'] = 100 47 self.model.dispersion['radius']['nsigmas'] = 2 .556 self.model.dispersion['radius']['nsigmas'] = 2 48 57 self.model.setParam('scale', 10.0) 49 58 50 self.assertAlmostEqual(self.model.run(0.001), 1.1804794*4723.32213339, 3) 51 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 1.180454*4743.56, 2) 59 self.assertAlmostEqual(self.model.run(0.001), 60 1.1804794*4723.32213339, 3) 61 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 62 1.180454*4743.56, 2) 52 63 53 64 def test_clone(self): … … 55 66 disp = GaussianDispersion() 56 67 self.model.set_dispersion('radius', disp) 57 self.model.dispersion['radius']['width'] = 5.068 self.model.dispersion['radius']['width'] = 0.25 58 69 self.model.dispersion['radius']['npts'] = 100 59 self.model.dispersion['radius']['nsigmas'] = 2 .570 self.model.dispersion['radius']['nsigmas'] = 2 60 71 self.model.setParam('scale', 10.0) 61 72 62 73 new_model = self.model.clone() 63 self.assertAlmostEqual(new_model.run(0.001), 1.1804794*4723.32213339, 3) 64 self.assertAlmostEqual(new_model.runXY([0.001,0.001]), 1.180454*4743.56, 2) 74 self.assertAlmostEqual(new_model.run(0.001), 75 1.1804794*4723.32213339, 3) 76 self.assertAlmostEqual(new_model.runXY([0.001,0.001]), 77 1.180454*4743.56, 2) 65 78 66 79 def test_gaussian_zero(self): … … 130 143 """ 131 144 self.assertAlmostEqual(self.model.run(0.001), 353.55013216754583, 3) 132 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 355.25355270620543, 3) 145 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 146 355.25355270620543, 3) 133 147 134 148 def test_dispersion(self): … … 137 151 """ 138 152 from sans.models.DisperseModel import DisperseModel 139 disp = DisperseModel(self.model, ['radius', 'thickness', 'length'], [5, 2, 50]) 153 disp = DisperseModel(self.model, ['radius', 154 'thickness', 155 'length'], [5, 2, 50]) 140 156 disp.setParam('n_pts', 10) 141 157 self.assertAlmostEqual(disp.run(0.001), 358.44062724936009, 3) … … 146 162 disp_rm = GaussianDispersion() 147 163 self.model.set_dispersion('radius', disp_rm) 148 self.model.dispersion['radius']['width'] = 5.0164 self.model.dispersion['radius']['width'] = 0.25 149 165 self.model.dispersion['radius']['npts'] = 10 150 self.model.dispersion['radius']['nsigmas'] = 2 .5166 self.model.dispersion['radius']['nsigmas'] = 2 151 167 152 168 disp_rr = GaussianDispersion() 153 169 self.model.set_dispersion('thickness', disp_rr) 154 self.model.dispersion['thickness']['width'] = 2.170 self.model.dispersion['thickness']['width'] = 0.2 155 171 self.model.dispersion['thickness']['npts'] = 10 156 self.model.dispersion['thickness']['nsigmas'] = 2 .5172 self.model.dispersion['thickness']['nsigmas'] = 2 157 173 158 174 disp_len = GaussianDispersion() 159 175 self.model.set_dispersion('length', disp_len) 160 self.model.dispersion['length']['width'] = 50.0176 self.model.dispersion['length']['width'] = 1.0/8.0 161 177 self.model.dispersion['length']['npts'] = 10 162 self.model.dispersion['length']['nsigmas'] = 2.5 163 164 self.assertAlmostEqual(self.model.run(0.001), 1.07832610*358.44062724936009, 3) 165 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 1.07844010*360.22673635224584, 3) 178 self.model.dispersion['length']['nsigmas'] = 2 179 180 self.assertAlmostEqual(self.model.run(0.001), 181 1.07832610*358.44062724936009, 3) 182 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 183 1.07844010*360.22673635224584, 3) 166 184 167 185 … … 218 236 the update to C++ underlying class. 219 237 """ 220 self.assertAlmostEqual(self.model.run(0.001), 381.27304697150055, 3) 221 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 380.93779156218682, 3) 238 self.assertAlmostEqual(self.model.run(0.001), 239 381.27304697150055, 3) 240 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 241 380.93779156218682, 3) 222 242 223 243 def test_dispersion(self): … … 234 254 disp_rm = GaussianDispersion() 235 255 self.model.set_dispersion('radius', disp_rm) 236 self.model.dispersion['radius']['width'] = 10.256 self.model.dispersion['radius']['width'] = 0.1666666667 237 257 self.model.dispersion['radius']['npts'] = 10 238 self.model.dispersion['radius']['nsigmas'] = 2 .5258 self.model.dispersion['radius']['nsigmas'] = 2 239 259 240 260 disp_rr = GaussianDispersion() 241 261 self.model.set_dispersion('thickness', disp_rr) 242 self.model.dispersion['thickness']['width'] = 2.262 self.model.dispersion['thickness']['width'] = 0.2 243 263 self.model.dispersion['thickness']['npts'] = 10 244 self.model.dispersion['thickness']['nsigmas'] = 2.5 245 246 self.assertAlmostEqual(self.model.run(0.001), 1.16747510*407.344127907553, 3) 264 self.model.dispersion['thickness']['nsigmas'] = 2 265 266 self.assertAlmostEqual(self.model.run(0.001), 267 1.16747510*407.344127907553, 3) 247 268 248 269 … … 270 291 the update to C++ underlying class. 271 292 """ 272 self.assertAlmostEqual(self.model.run(0.001), 11808.842896863147, 3) 273 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 11681.990374929677, 3) 293 self.assertAlmostEqual(self.model.run(0.001), 294 11808.842896863147, 3) 295 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 296 11681.990374929677, 3) 274 297 275 298 def test_dispersion(self): … … 288 311 disp_rm = GaussianDispersion() 289 312 self.model.set_dispersion('radius_a', disp_rm) 290 self.model.dispersion['radius_a']['width'] = 5.0313 self.model.dispersion['radius_a']['width'] = 0.25 291 314 self.model.dispersion['radius_a']['npts'] = 10 292 self.model.dispersion['radius_a']['nsigmas'] = 2 .5315 self.model.dispersion['radius_a']['nsigmas'] = 2 293 316 294 317 disp_rr = GaussianDispersion() 295 318 self.model.set_dispersion('radius_b', disp_rr) 296 self.model.dispersion['radius_b']['width'] = 50.319 self.model.dispersion['radius_b']['width'] = 0.125 297 320 self.model.dispersion['radius_b']['npts'] = 10 298 self.model.dispersion['radius_b']['nsigmas'] = 2.5 299 300 self.assertAlmostEqual(self.model.run(0.001), 1.10650710*11948.72581312305, 3) 301 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 1.105898*11811.972359807551, 2) 321 self.model.dispersion['radius_b']['nsigmas'] = 2 322 323 self.assertAlmostEqual(self.model.run(0.001), 324 1.10650710*11948.72581312305, 3) 325 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 326 1.105898*11811.972359807551, 2) 302 327 303 328 def test_array(self): … … 341 366 self.model.setParam('scale', 1.0) 342 367 self.model.setParam('radius', 60.0) 343 self.model.setParam('sldSph', 2.0 e-06)344 self.model.setParam('sldSolv', 1.0 e-6)368 self.model.setParam('sldSph', 2.0) 369 self.model.setParam('sldSolv', 1.0) 345 370 self.model.setParam('background', 0.0) 346 371 … … 351 376 the update to C++ underlying class. 352 377 """ 353 self.assertAlmostEqual(self.model.run(0.001), 90412744456148.094, 3) 354 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 90347660670656.391, 1) 378 self.assertAlmostEqual(self.model.run(0.001), 379 90412744456148.094, 3) 380 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 381 90347660670656.391, 1) 355 382 356 383 def test_dispersion(self): … … 361 388 disp = DisperseModel(self.model, ['radius'], [10]) 362 389 disp.setParam('n_pts', 10) 390 disp.setParam('radius.npts', 10) 391 disp.setParam('radius.nsigmas', 2.5) 363 392 self.assertAlmostEqual(disp.run(0.001), 96795008379475.25, 1) 364 393 … … 367 396 disp_rm = GaussianDispersion() 368 397 self.model.set_dispersion('radius', disp_rm) 369 self.model.dispersion['radius']['width'] = 10.0398 self.model.dispersion['radius']['width'] = 0.1666666667 370 399 self.model.dispersion['radius']['npts'] = 10 371 self.model.dispersion['radius']['nsigmas'] = 2 .5372 373 self.assertAlmostEqual(self.model.run(0.001), 1.19864810*96795008379475.25,3)400 self.model.dispersion['radius']['nsigmas'] = 2 401 402 #self.assertAlmostEqual(self.model.run(0.001), 96795008379475.25,3) 374 403 375 404 … … 400 429 the update to C++ underlying class. 401 430 """ 402 self.assertAlmostEqual(self.model.run(0.001), 675.50440232504991, 3) 403 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 669.5173937622792, 0) 431 self.assertAlmostEqual(self.model.run(0.001), 432 675.50440232504991, 3) 433 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 434 669.5173937622792, 0) 404 435 405 436 def test_dispersion(self): … … 408 439 """ 409 440 from sans.models.DisperseModel import DisperseModel 410 disp = DisperseModel(self.model, ['r_minor', 'r_ratio', 'length'], [5, 0.25, 50]) 441 disp = DisperseModel(self.model, ['r_minor', 'r_ratio', 'length'], 442 [5, 0.25, 50]) 411 443 disp.setParam('n_pts', 10) 412 444 self.assertAlmostEqual(disp.run(0.001), 711.18048194151925, 3) … … 417 449 disp_rm = GaussianDispersion() 418 450 self.model.set_dispersion('r_minor', disp_rm) 419 self.model.dispersion['r_minor']['width'] = 5.0451 self.model.dispersion['r_minor']['width'] = 0.25 420 452 self.model.dispersion['r_minor']['npts'] = 10 421 self.model.dispersion['r_minor']['nsigmas'] = 2 .5453 self.model.dispersion['r_minor']['nsigmas'] = 2 422 454 423 455 disp_rr = GaussianDispersion() 424 456 self.model.set_dispersion('r_ratio', disp_rr) 425 self.model.dispersion['r_ratio']['width'] = 0.25 457 self.model.dispersion['r_ratio']['width'] = 0.25/1.5 426 458 self.model.dispersion['r_ratio']['npts'] = 10 427 self.model.dispersion['r_ratio']['nsigmas'] = 2 .5459 self.model.dispersion['r_ratio']['nsigmas'] = 2 428 460 429 461 disp_len = GaussianDispersion() 430 462 self.model.set_dispersion('length', disp_len) 431 self.model.dispersion['length']['width'] = 50.0 463 self.model.dispersion['length']['width'] = 50.0/400 432 464 self.model.dispersion['length']['npts'] = 10 433 self.model.dispersion['length']['nsigmas'] = 2.5 434 435 self.assertAlmostEqual(self.model.run(0.001), 1.23925910*711.18048194151925, 3) 436 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 1.238955*704.63525988095705, 0) 465 self.model.dispersion['length']['nsigmas'] = 2 466 467 self.assertAlmostEqual(self.model.run(0.001), 468 1.23925910*711.18048194151925, 3) 469 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 470 1.238955*704.63525988095705, 0) 437 471 438 472 … … 479 513 480 514 self.assertEqual(self.model.dispersion['radius']['width'], 0.0) 481 self.model.setParam('radius.width', 5.0)482 self.assertEqual(self.model.dispersion['radius']['width'], 5.0)483 self.assertEqual(self.model.getParam('radius.width'), 5.0)515 self.model.setParam('radius.width', 0.25) 516 self.assertEqual(self.model.dispersion['radius']['width'], 0.25) 517 self.assertEqual(self.model.getParam('radius.width'), 0.25) 484 518 self.assertEqual(self.model.dispersion['radius']['type'], 'gaussian') 485 519
Note: See TracChangeset
for help on using the changeset viewer.