RTModel 2.2__tar.gz → 2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. rtmodel-2.3/.github/workflows/build_wheels.yml +48 -0
  2. {rtmodel-2.2 → rtmodel-2.3}/.github/workflows/run_tests.yml +1 -1
  3. {rtmodel-2.2 → rtmodel-2.3}/PKG-INFO +3 -3
  4. {rtmodel-2.2 → rtmodel-2.3}/README.md +1 -1
  5. {rtmodel-2.2 → rtmodel-2.3}/RTModel/RTModel.py +6 -1
  6. {rtmodel-2.2 → rtmodel-2.3}/RTModel/include/bumper.h +2 -1
  7. {rtmodel-2.2 → rtmodel-2.3}/RTModel/lib/Finalizer.cpp +83 -53
  8. {rtmodel-2.2 → rtmodel-2.3}/RTModel/lib/LevMarFit.cpp +68 -49
  9. rtmodel-2.3/RTModel/lib/LevMarFit.h +91 -0
  10. {rtmodel-2.2 → rtmodel-2.3}/RTModel/lib/ModelSelector.cpp +68 -28
  11. {rtmodel-2.2 → rtmodel-2.3}/RTModel/lib/Reader.cpp +2 -2
  12. {rtmodel-2.2 → rtmodel-2.3}/RTModel/lib/VBMicrolensingLibrary.cpp +20 -20
  13. rtmodel-2.3/RTModel/lib/bumper.cpp +170 -0
  14. {rtmodel-2.2 → rtmodel-2.3}/RTModel/plotmodel/__init__.py +2 -2
  15. {rtmodel-2.2 → rtmodel-2.3}/RTModel/plotmodel/plotmodel.py +16 -6
  16. {rtmodel-2.2 → rtmodel-2.3}/RTModel/templates/__init__.py +1 -1
  17. {rtmodel-2.2 → rtmodel-2.3}/RTModel/templates/templates.py +8 -14
  18. {rtmodel-2.2 → rtmodel-2.3}/changelog.md +1 -0
  19. {rtmodel-2.2 → rtmodel-2.3}/docs/PlotModel.md +1 -0
  20. {rtmodel-2.2 → rtmodel-2.3}/docs/README.md +6 -6
  21. rtmodel-2.3/docs/Template.png +0 -0
  22. {rtmodel-2.2 → rtmodel-2.3}/docs/TemplateLibraries.md +2 -2
  23. {rtmodel-2.2 → rtmodel-2.3}/pyproject.toml +9 -3
  24. rtmodel-2.2/RTModel/lib/bumper.cpp +0 -168
  25. rtmodel-2.2/docs/Template.png +0 -0
  26. {rtmodel-2.2 → rtmodel-2.3}/.gitignore +0 -0
  27. {rtmodel-2.2 → rtmodel-2.3}/CMakeLists.txt +0 -0
  28. {rtmodel-2.2 → rtmodel-2.3}/LICENSE +0 -0
  29. {rtmodel-2.2 → rtmodel-2.3}/MANIFEST.in +0 -0
  30. {rtmodel-2.2 → rtmodel-2.3}/RTModel/__init__.py +0 -0
  31. {rtmodel-2.2 → rtmodel-2.3}/RTModel/data/ESPL.tbl +0 -0
  32. {rtmodel-2.2 → rtmodel-2.3}/RTModel/data/TemplateLibrary.txt +0 -0
  33. {rtmodel-2.2 → rtmodel-2.3}/RTModel/include/LevMarFit.h +0 -0
  34. {rtmodel-2.2 → rtmodel-2.3}/RTModel/include/VBMicrolensingLibrary.h +0 -0
  35. {rtmodel-2.2 → rtmodel-2.3}/RTModel/lib/InitCond.cpp +0 -0
  36. {rtmodel-2.2 → rtmodel-2.3}/RTModel/lib/LevMar.cpp +0 -0
  37. {rtmodel-2.2 → rtmodel-2.3}/docs/Animation.md +0 -0
  38. {rtmodel-2.2 → rtmodel-2.3}/docs/Archive.md +0 -0
  39. {rtmodel-2.2 → rtmodel-2.3}/docs/Constraints.md +0 -0
  40. {rtmodel-2.2 → rtmodel-2.3}/docs/DataPreparation.md +0 -0
  41. {rtmodel-2.2 → rtmodel-2.3}/docs/DataPreprocessing.md +0 -0
  42. {rtmodel-2.2 → rtmodel-2.3}/docs/FinalAssessment.md +0 -0
  43. {rtmodel-2.2 → rtmodel-2.3}/docs/Fitting.md +0 -0
  44. {rtmodel-2.2 → rtmodel-2.3}/docs/InitCond.md +0 -0
  45. {rtmodel-2.2 → rtmodel-2.3}/docs/LimbDarkening.md +0 -0
  46. {rtmodel-2.2 → rtmodel-2.3}/docs/ModelCategories.md +0 -0
  47. {rtmodel-2.2 → rtmodel-2.3}/docs/ModelSelection.md +0 -0
  48. {rtmodel-2.2 → rtmodel-2.3}/docs/ModelingRun.md +0 -0
  49. {rtmodel-2.2 → rtmodel-2.3}/docs/Satellite.md +0 -0
  50. {rtmodel-2.2 → rtmodel-2.3}/docs/ani.gif +0 -0
  51. {rtmodel-2.2 → rtmodel-2.3}/docs/plotchain.png +0 -0
  52. {rtmodel-2.2 → rtmodel-2.3}/docs/plotmodel_fig1.png +0 -0
  53. {rtmodel-2.2 → rtmodel-2.3}/docs/plotmodel_fig2.png +0 -0
  54. {rtmodel-2.2 → rtmodel-2.3}/events/OB190033.zip +0 -0
  55. {rtmodel-2.2 → rtmodel-2.3}/events/event001.zip +0 -0
  56. {rtmodel-2.2 → rtmodel-2.3}/events/event001done.zip +0 -0
  57. {rtmodel-2.2 → rtmodel-2.3}/events/event002.zip +0 -0
  58. {rtmodel-2.2 → rtmodel-2.3}/events/readme.md +0 -0
  59. {rtmodel-2.2 → rtmodel-2.3}/events/satellite1.txt +0 -0
  60. {rtmodel-2.2 → rtmodel-2.3}/jupyter/Model_event001.ipynb +0 -0
  61. {rtmodel-2.2 → rtmodel-2.3}/tests/build_tests/test_built_executables_exist.py +0 -0
  62. {rtmodel-2.2 → rtmodel-2.3}/tests/end_to_end_tests/test_ps_run.py +0 -0
  63. {rtmodel-2.2 → rtmodel-2.3}/tests/end_to_end_tests/test_ps_run_resources/example_event.zip +0 -0
@@ -0,0 +1,48 @@
1
+ name: Build
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build_wheels:
7
+ name: Build wheels on ${{ matrix.os }}
8
+ runs-on: ${{ matrix.os }}
9
+ strategy:
10
+ matrix:
11
+ # macos-13 is an intel runner, macos-14 is apple silicon
12
+ os: [ubuntu-latest, windows-latest, macos-latest]
13
+
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - name: Build wheels
18
+ uses: pypa/cibuildwheel@v2.22.0
19
+ # env:
20
+ # CIBW_SOME_OPTION: value
21
+ # ...
22
+ #with:
23
+ # package-dir: .
24
+ # output-dir: wheelhouse
25
+ # config-file: "{package}/pyproject.toml
26
+ - uses: actions/upload-artifact@v4
27
+ with:
28
+ name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
29
+ path: ./wheelhouse/*.whl
30
+ build_sdist:
31
+ name: Build source distribution
32
+ runs-on: ubuntu-latest
33
+ steps:
34
+ - uses: actions/checkout@v4
35
+
36
+ - name: Build sdist
37
+ run: pipx run build --sdist
38
+
39
+ - uses: actions/upload-artifact@v4
40
+ with:
41
+ name: cibw-sdist
42
+ path: dist/*.tar.gz
43
+
44
+
45
+ - uses: actions/upload-artifact@v4
46
+ with:
47
+ name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
48
+ path: ./wheelhouse/*.whl
@@ -1,6 +1,6 @@
1
1
  name: run_tests
2
2
 
3
- on: [push, pull_request]
3
+ on: [push]
4
4
 
5
5
  jobs:
6
6
  run_tests:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: RTModel
3
- Version: 2.2
3
+ Version: 2.3
4
4
  Summary: RTModel is a tool for microlensing event interpretation.
5
5
  Keywords: Microlensing analysis and fitting
6
6
  Author-Email: Valerio Bozza <valboz@sa.infn.it>
@@ -10,7 +10,7 @@ Classifier: Intended Audience :: Science/Research
10
10
  Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Project-URL: Homepage, https://github.com/valboz/RTModel
13
- Requires-Python: <4,>=3.6
13
+ Requires-Python: <4,>=3.7
14
14
  Requires-Dist: numpy
15
15
  Requires-Dist: pytest
16
16
  Requires-Dist: matplotlib
@@ -40,7 +40,7 @@ A second subpackage **`RTModel.templates`** helps the user in the visualization
40
40
 
41
41
  Any scientific use of `RTModel` should be acknowledged by citing the paper [V.Bozza, A&A 688 (2024) 83](https://ui.adsabs.harvard.edu/abs/2024A%26A...688A..83B/abstract), describing all the algorithms behind the code.
42
42
 
43
- We are grateful to Greg Olmschenk, who revised the package installation in order to make it as cross-platform as possible.
43
+ We are grateful to Greg Olmschenk, who revised the package installation in order to make it as cross-platform as possible. We also thank all the users who are providing suggestions, reporting bugs or failures: Etienne Bachelet, David Bennett, Jonathan Brashear, Stela Ishitani Silva, Yiannis Tsapras, Keto Zhang.
44
44
 
45
45
  ## Installation
46
46
 
@@ -20,7 +20,7 @@ A second subpackage **`RTModel.templates`** helps the user in the visualization
20
20
 
21
21
  Any scientific use of `RTModel` should be acknowledged by citing the paper [V.Bozza, A&A 688 (2024) 83](https://ui.adsabs.harvard.edu/abs/2024A%26A...688A..83B/abstract), describing all the algorithms behind the code.
22
22
 
23
- We are grateful to Greg Olmschenk, who revised the package installation in order to make it as cross-platform as possible.
23
+ We are grateful to Greg Olmschenk, who revised the package installation in order to make it as cross-platform as possible. We also thank all the users who are providing suggestions, reporting bugs or failures: Etienne Bachelet, David Bennett, Jonathan Brashear, Stela Ishitani Silva, Yiannis Tsapras, Keto Zhang.
24
24
 
25
25
  ## Installation
26
26
 
@@ -142,8 +142,9 @@ class RTModel:
142
142
  print(f'{float(f.readline().split()[0]):.4f}',end = ' ')
143
143
  print('\n OK')
144
144
 
145
- def config_LevMar(self, nfits = 5, timelimit = 600.0, maxsteps = 50, bumperpower = 2.0):
145
+ def config_LevMar(self, nfits = 6, offsetdegeneracy = 3, timelimit = 600.0, maxsteps = 50, bumperpower = 2.0):
146
146
  self.LevMar_nfits = nfits # Number of models to be calculated from the same initial condition using the bumper method
147
+ self.LevMar_offsetdegeneracy = offsetdegeneracy # Number of models to be fit after applying offset degeneracy to best model found so far
147
148
  self.LevMar_maxsteps = maxsteps # Maximum number of steps in each fit
148
149
  self.LevMar_timelimit = timelimit # Maximum time in seconds for total execution
149
150
  self.LevMar_bumperpower = bumperpower # Repulsion factor of bumpers
@@ -160,6 +161,7 @@ class RTModel:
160
161
  f.write(line)
161
162
  with open(self.eventname + '/' + self.inidir + '/LevMar.ini','w') as f:
162
163
  f.write('nfits = ' + str(self.LevMar_nfits) + '\n')
164
+ f.write('offsetdegeneracy = ' + str(self.LevMar_offsetdegeneracy) + '\n')
163
165
  f.write('maxsteps = ' + str(self.LevMar_maxsteps) + '\n')
164
166
  f.write('timelimit = ' + str(self.LevMar_timelimit) + '\n')
165
167
  f.write('bumperpower = ' + str(self.LevMar_bumperpower) + '\n')
@@ -179,6 +181,7 @@ class RTModel:
179
181
  os.makedirs(self.eventname + '/' + self.inidir)
180
182
  with open(self.eventname + '/' + self.inidir + '/LevMar.ini','w') as f:
181
183
  f.write('nfits = ' + str(self.LevMar_nfits) + '\n')
184
+ f.write('offsetdegeneracy = ' + str(self.LevMar_offsetdegeneracy) + '\n')
182
185
  f.write('maxsteps = ' + str(self.LevMar_maxsteps) + '\n')
183
186
  f.write('timelimit = ' + str(self.LevMar_timelimit) + '\n')
184
187
  f.write('bumperpower = ' + str(self.LevMar_bumperpower) + '\n')
@@ -435,6 +438,8 @@ class RTModel:
435
438
  chunks = line.split()
436
439
  if(chunks[0]=='nfits'):
437
440
  self.LevMar_nfits = int(chunks[2])
441
+ if(chunks[0]=='offsetdegeneracy'):
442
+ self.LevMar_offsetdegeneracy = int(chunks[2])
438
443
  elif(chunks[0]=='maxsteps'):
439
444
  self.LevMar_maxsteps = int(chunks[2])
440
445
  elif(chunks[0]=='timelimit'):
@@ -14,6 +14,7 @@ public:
14
14
  int nps;
15
15
  char modelcode[16];
16
16
  int il;
17
+ bool duplicate;
17
18
  bumper(double *,int);
18
19
  ~bumper();
19
20
  void SetCurvature(double *,double);
@@ -29,4 +30,4 @@ double Determinant(double *,int);
29
30
  void Inverse(double*, double*, int);
30
31
  void CombineCovariances(bumper*, bumper*, double *Cov, double * Curv, int);
31
32
 
32
- #endif
33
+ #endif
@@ -285,69 +285,99 @@ int main(int argc, char* argv[]) {
285
285
  }
286
286
 
287
287
  // Making assessment. Each category is tested against nested ones
288
+ vector<int> dependencies[] = { {},
289
+ {0},
290
+ {0},
291
+ {0,1,2},
292
+ {0},
293
+ {0,1,4},
294
+ {0,1,4,5},
295
+ {0,1,4,5,6},
296
+ {0,4},
297
+ {0,1,4,5},
298
+ };
299
+ double modelthrs[ncategories];
288
300
 
289
- if (chis[1] > chis[0] - thrs[npss[1] - npss[0]]) {
290
- chis[1] = 1.e100;
291
- }
292
- if (chis[2] > chis[0] - thrs[npss[2] - npss[0]]) {
293
- chis[2] = 1.e100;
294
- }
295
- if (chis[3] > chis[0] - thrs[npss[3] - npss[0]] || chis[3] > chis[1] - thrs[npss[3] - npss[1]] || chis[3] > chis[2] - thrs[npss[3] - npss[2]]) {
296
- chis[3] = 1.e100;
297
- }
298
- if (chis[4] > chis[0] - thrs[npss[4] - npss[0]]) {
299
- chis[4] = 1.e100;
300
- }
301
- if (chis[5] > chis[0] - thrs[npss[5] - npss[0]] || chis[5] > chis[1] - thrs[npss[5] - npss[1]] || chis[5] > chis[4] - thrs[npss[5] - npss[4]]) {
302
- chis[5] = 1.e100;
303
- }
304
- if (chis[6] > chis[0] - thrs[npss[6] - npss[0]] || chis[6] > chis[1] - thrs[npss[6] - npss[1]] || chis[6] > chis[4] - thrs[npss[6] - npss[4]] || chis[6] > chis[5] - thrs[npss[6] - npss[5]]) {
305
- chis[6] = 1.e100;
306
- }
307
- if (chis[7] > chis[0] - thrs[npss[7] - npss[0]] || chis[7] > chis[1] - thrs[npss[7] - npss[1]] || chis[7] > chis[4] - thrs[npss[7] - npss[4]] || chis[7] > chis[5] - thrs[npss[7] - npss[5]] || chis[7] > chis[6] - thrs[npss[7] - npss[6]]) {
308
- chis[7] = 1.e100;
309
- }
310
- if (chis[8] > chis[0] - thrs[npss[8] - npss[0]] || chis[8] > chis[4] - thrs[npss[8] - npss[4]]) {
311
- chis[8] = 1.e100;
312
- }
313
- if (chis[9] > chis[0] - thrs[npss[9] - npss[0]] || chis[9] > chis[1] - thrs[npss[9] - npss[1]] || chis[9] > chis[4] - thrs[npss[9] - npss[4]] || chis[9] > chis[5] - thrs[npss[9] - npss[5]]) {
314
- chis[9] = 1.e100;
301
+ for (int icat = 0; icat < ncategories; icat++) {
302
+ modelthrs[icat] = thsigma;
303
+ for (int jdep = 0; jdep < dependencies[icat].size(); jdep++) {
304
+ double thr= chis[dependencies[icat][jdep]] - thrs[npss[icat] - npss[dependencies[icat][jdep]]];
305
+ if (thr < modelthrs[icat]) modelthrs[icat] = thr;
306
+ }
307
+ if (chis[icat] > modelthrs[icat]) {
308
+ chis[icat] = 1.e100;
309
+ }
315
310
  }
316
311
 
312
+ //if (chis[1] > chis[0] - thrs[npss[1] - npss[0]]) {
313
+ // chis[1] = 1.e100;
314
+ //}
315
+ //if (chis[2] > chis[0] - thrs[npss[2] - npss[0]]) {
316
+ // chis[2] = 1.e100;
317
+ //}
318
+ //if (chis[3] > chis[0] - thrs[npss[3] - npss[0]] || chis[3] > chis[1] - thrs[npss[3] - npss[1]] || chis[3] > chis[2] - thrs[npss[3] - npss[2]]) {
319
+ // chis[3] = 1.e100;
320
+ //}
321
+ //if (chis[4] > chis[0] - thrs[npss[4] - npss[0]]) {
322
+ // chis[4] = 1.e100;
323
+ //}
324
+ //if (chis[5] > chis[0] - thrs[npss[5] - npss[0]] || chis[5] > chis[1] - thrs[npss[5] - npss[1]] || chis[5] > chis[4] - thrs[npss[5] - npss[4]]) {
325
+ // chis[5] = 1.e100;
326
+ //}
327
+ //if (chis[6] > chis[0] - thrs[npss[6] - npss[0]] || chis[6] > chis[1] - thrs[npss[6] - npss[1]] || chis[6] > chis[4] - thrs[npss[6] - npss[4]] || chis[6] > chis[5] - thrs[npss[6] - npss[5]]) {
328
+ // chis[6] = 1.e100;
329
+ //}
330
+ //if (chis[7] > chis[0] - thrs[npss[7] - npss[0]] || chis[7] > chis[1] - thrs[npss[7] - npss[1]] || chis[7] > chis[4] - thrs[npss[7] - npss[4]] || chis[7] > chis[5] - thrs[npss[7] - npss[5]] || chis[7] > chis[6] - thrs[npss[7] - npss[6]]) {
331
+ // chis[7] = 1.e100;
332
+ //}
333
+ //if (chis[8] > chis[0] - thrs[npss[8] - npss[0]] || chis[8] > chis[4] - thrs[npss[8] - npss[4]]) {
334
+ // chis[8] = 1.e100;
335
+ //}
336
+ //if (chis[9] > chis[0] - thrs[npss[9] - npss[0]] || chis[9] > chis[1] - thrs[npss[9] - npss[1]] || chis[9] > chis[4] - thrs[npss[9] - npss[4]] || chis[9] > chis[5] - thrs[npss[9] - npss[5]]) {
337
+ // chis[9] = 1.e100;
338
+ //}
339
+
317
340
  // If more complicated category has survived, all nested categories are removed
318
341
 
319
- if (chis[9] < 1.e99) {
320
- chis[5] = chis[4] = chis[1] = chis[0] = 1.e100;
321
- }
322
- if (chis[8] < 1.e99) {
323
- chis[4] = chis[0] = 1.e100;
324
- }
325
- if (chis[7] < 1.e99) {
326
- chis[6] = chis[5] = chis[4] = chis[1] = chis[0] = 1.e100;
327
- }
328
- if (chis[6] < 1.e99) {
329
- chis[5] = chis[4] = chis[1] = chis[0] = 1.e100;
330
- }
331
- if (chis[5] < 1.e99) {
332
- chis[4] = chis[1] = chis[0] = 1.e100;
333
- }
334
- if (chis[4] < 1.e99) {
335
- chis[0] = 1.e100;
336
- }
337
- if (chis[3] < 1.e99) {
338
- chis[2] = chis[1] = chis[0] = 1.e100;
339
- }
340
- if (chis[2] < 1.e99) {
341
- chis[0] = 1.e100;
342
- }
343
- if (chis[1] < 1.e99) {
344
- chis[0] = 1.e100;
342
+ for (int icat = ncategories - 1; icat > 0; icat--) {
343
+ if (chis[icat] < 1.e99) {
344
+ for (int jdep = 0; jdep < dependencies[icat].size(); jdep++) {
345
+ chis[dependencies[icat][jdep]] = 1.e100;
346
+ }
347
+ }
345
348
  }
349
+ //if (chis[9] < 1.e99) {
350
+ // chis[5] = chis[4] = chis[1] = chis[0] = 1.e100;
351
+ //}
352
+ //if (chis[8] < 1.e99) {
353
+ // chis[4] = chis[0] = 1.e100;
354
+ //}
355
+ //if (chis[7] < 1.e99) {
356
+ // chis[6] = chis[5] = chis[4] = chis[1] = chis[0] = 1.e100;
357
+ //}
358
+ //if (chis[6] < 1.e99) {
359
+ // chis[5] = chis[4] = chis[1] = chis[0] = 1.e100;
360
+ //}
361
+ //if (chis[5] < 1.e99) {
362
+ // chis[4] = chis[1] = chis[0] = 1.e100;
363
+ //}
364
+ //if (chis[4] < 1.e99) {
365
+ // chis[0] = 1.e100;
366
+ //}
367
+ //if (chis[3] < 1.e99) {
368
+ // chis[2] = chis[1] = chis[0] = 1.e100;
369
+ //}
370
+ //if (chis[2] < 1.e99) {
371
+ // chis[0] = 1.e100;
372
+ //}
373
+ //if (chis[1] < 1.e99) {
374
+ // chis[0] = 1.e100;
375
+ //}
346
376
 
347
377
  // Models of discarded categories or with chi square higher than threshold are removed
348
378
 
349
379
  for (scanbumper = bumperlist; scanbumper; scanbumper = scanbumper->next) {
350
- if (scanbumper->Amp > thsigma || chis[scanbumper->il] > 1.e99) scanbumper->modelcode[0] = 'N';
380
+ if (scanbumper->Amp > modelthrs[scanbumper->il] || chis[scanbumper->il] > 1.e99) scanbumper->modelcode[0] = 'N';
351
381
  }
352
382
 
353
383
  // Counting good models
@@ -18,7 +18,8 @@
18
18
  using namespace std;
19
19
  using namespace std::filesystem;
20
20
 
21
- int nlc = 5; // Number of models to be calculated from the same initial condition using the bumper method
21
+ int nlc = 6; // Number of models to be calculated from the same initial condition using the bumper method
22
+ int offsetdegeneracy = 3; // Number of models to be calculated with offset degeneracy
22
23
  int maxsteps = 50; // Maximum number of steps in each fit
23
24
  double maxtime = 1.e100; // 600.0; // Maximum time in seconds for total execution (no longer controlled within LevMar)
24
25
  double bumperpower = 2.0; // Repulsion factor of bumpers
@@ -193,7 +194,7 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
193
194
  model = &VBMicrolensing::ESPLLightCurveParallax;
194
195
  nps = 6;
195
196
  ReadOptions();
196
- double presigmapr[] = { .5,.5,5.,4.6,1,1 };
197
+ double presigmapr[] = { .5,1.0,5.,2.3,0.1,0.1 };
197
198
  double preleftlim[] = { -13.,-6.9,-10.e100,-11.5,-10.,-10. };
198
199
  double prerightlim[] = { .7,6.9,10.e100,0.0,10.,10. };
199
200
  error = InitCond(presigmapr, preleftlim, prerightlim);
@@ -207,7 +208,7 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
207
208
  model = &VBMicrolensing::ESPLLightCurve;
208
209
  nps = 4;
209
210
  ReadOptions();
210
- double presigmapr[] = { .5,.5,5.,4.6 };
211
+ double presigmapr[] = { 1.15,1.0,5.,2.3 };
211
212
  double preleftlim[] = { -13.,-6.9,-10.e100,-11.5 };
212
213
  double prerightlim[] = { .7,6.9,10.e100,0.0 };
213
214
  error = InitCond(presigmapr, preleftlim, prerightlim);
@@ -229,7 +230,7 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
229
230
  model = &VBMicrolensing::BinSourceSingleLensXallarap;
230
231
  nps = 10;
231
232
  ReadOptions();
232
- double presigmapr[] = { 1,1,1,15,3,3,1,3,6,3 };
233
+ double presigmapr[] = { 0.1,1,1,0.5,0.3,0.3,0.1,0.3,0.3, 2.3};
233
234
  double preleftlim[] = { -3.,-1.e100,-6.9,-11.5,-3.,-3.,0,-3,-6,-4.6 };
234
235
  double prerightlim[] = { 3.,1.e100,6.9,0.,3.,3.,1,3,6,1,+4.6 };
235
236
  error = InitCond(presigmapr, preleftlim, prerightlim);
@@ -244,7 +245,7 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
244
245
  model = &VBMicrolensing::BinSourceExtLightCurve;
245
246
  nps = 7;
246
247
  ReadOptions();
247
- double presigmapr[] = { .1,.4,1,1,1,1,4.6 };
248
+ double presigmapr[] = { 1.0,.5,0.5,0.5,1,1,0.5 };
248
249
  double preleftlim[] = { -6.9,-11.5,0.,0.,-10.e100,-10.e100,-11.5 };
249
250
  double prerightlim[] = { 6.9,11.5,3.,3.,10.e100,10.e100,0.0 };
250
251
  error = InitCond(presigmapr, preleftlim, prerightlim);
@@ -266,7 +267,7 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
266
267
  model = &VBMicrolensing::BinaryLightCurveParallax;
267
268
  nps = 9;
268
269
  ReadOptions();
269
- double presigmapr[] = { .1,.4,.1,.1,4.6,.1,1.,1.,1. };
270
+ double presigmapr[] = { .1,0.5,.1,.1,0.3,.6,5.,0.03,0.03};
270
271
  double preleftlim[] = { -4.0,-11.5,-3.,-12.56,-11.5,-6.9,-10.e100,-3.,-3. };
271
272
  double prerightlim[] = { 3.0,11.5,3.,12.56,-2.5,7.6,10.e100,3.,3. };
272
273
  error = InitCond(presigmapr, preleftlim, prerightlim);
@@ -283,7 +284,7 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
283
284
  model = &VBMicrolensing::BinaryLightCurveOrbital;
284
285
  nps = 12;
285
286
  ReadOptions();
286
- double presigmapr[] = { 1.,2.,1.,5.,15.6,2.,10.,3.,3.,1.,1.,3. };
287
+ double presigmapr[] = { .1,0.5,.1,.1,0.3,.6,5.,0.03,0.03,0.01,0.01,0.01 };
287
288
  double preleftlim[] = { -4.0,-11.5,-3.,-12.56,-11.5,-6.9,-10.e100,-3.,-3.,-1,-1,1.e-7 };
288
289
  double prerightlim[] = { 3.0,11.5,3.,12.56,-2.5,7.6,10.e100,3.,3.,1,1,1 };
289
290
  error = InitCond(presigmapr, preleftlim, prerightlim);
@@ -300,7 +301,7 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
300
301
  model = &VBMicrolensing::BinaryLightCurveKepler;
301
302
  nps = 14;
302
303
  ReadOptions();
303
- double presigmapr[] = { 1.,2.,1.,5.,15.6,2.,10.,3.,3.,1.,1.,3., 3., 3. };
304
+ double presigmapr[] = { .1,0.5,.1,.1,0.3,.6,5.,0.03,0.03,0.1, 0.1 };
304
305
  double preleftlim[] = { -4.0,-11.5,-3.,-12.56,-11.5,-6.9,-10.e100,-3.,-3.,-1,-1,1.e-7, -10,0.5001 };
305
306
  double prerightlim[] = { 3.0,11.5,3.,12.56,-2.5,7.6,10.e100,3.,3.,1,1,1,10,10 };
306
307
  error = InitCond(presigmapr, preleftlim, prerightlim);
@@ -316,7 +317,7 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
316
317
  model = &VBMicrolensing::BinaryLightCurve;
317
318
  nps = 7;
318
319
  ReadOptions();
319
- double presigmapr[] = { .1,.4,.1,.1,4.6,.1,1. };
320
+ double presigmapr[] = { .1,0.5,.1,.1,0.3,.6,5.};
320
321
  double preleftlim[] = { -4.0,-11.5,-3.,-12.56,-11.5,-6.9,-10.e100 };
321
322
  double prerightlim[] = { 3.0,11.5,3.,12.56,-2.5,7.6,10.e100 };
322
323
  error = InitCond(presigmapr, preleftlim, prerightlim);
@@ -354,7 +355,7 @@ void LevMar::ReadFiles(int argc, char* argv[]) {
354
355
  model = &VBMicrolensing::TripleLightCurve;
355
356
  nps = 10;
356
357
  ReadOptions();
357
- double presigmapr[] = { .1,.4,.1,.1,4.6,.1,1.,.1,.4,.1};
358
+ double presigmapr[] = { .1,0.5,.1,.1,0.3,.6,5., 0.3, 0.5, 0.3};
358
359
  double preleftlim[] = { -4.0,-11.5,-3.,-12.56,-11.5,-6.9,-10.e100,-4.0,-11.5,-12.56};
359
360
  double prerightlim[] = { 3.0,11.5,3.,12.56,-2.5,7.6,10.e100,3.0, 11.5, 12.56 };
360
361
  error = InitCond(presigmapr, preleftlim, prerightlim);
@@ -503,6 +504,9 @@ void LevMar::ReadOptions() {
503
504
  if (strcmp(command, "nfits") == 0) {
504
505
  sscanf(value, "%d", &nlc);
505
506
  }
507
+ if (strcmp(command, "offsetdegeneracy") == 0) {
508
+ sscanf(value, "%d", &offsetdegeneracy);
509
+ }
506
510
  if (strcmp(command, "maxsteps") == 0) {
507
511
  sscanf(value, "%d", &maxsteps);
508
512
  }
@@ -925,7 +929,7 @@ void LevMar::Run() {
925
929
 
926
930
  if (ichi < 4) {
927
931
  // Final chi square of this model
928
- c0 = c1;//ChiSquared(pr);
932
+ c0 = ChiSquared(pr);
929
933
  printf("\nFinal chi square = %lf\n", c0);
930
934
 
931
935
  //Check if this is the best model with this initial condition
@@ -937,50 +941,13 @@ void LevMar::Run() {
937
941
  // Add a new bumper at the position of this model
938
942
  scanbumper = bumperlist;
939
943
  bumperlist = new bumper(pr, nps);
944
+ bumperlist->Amp = c0;
940
945
  bumperlist->next = scanbumper;
941
946
  // Calculate covariance matrix
942
947
  Grad();
943
948
  Covariance();
944
949
  bumperlist->SetCurvature(Curv, np / c0);
945
950
 
946
-
947
- // Saving the steps done to this model
948
- // sprintf(filename, "stepchain%d.dat", il);
949
- //f = fopen(filename, "w");
950
- //for (scanbumper = stepchain; scanbumper; scanbumper = scanbumper->next) {
951
- // fprintf(f, "%.16le", scanbumper->p0[0]);
952
- // for (int j = 1; j < nps; j++) {
953
- // fprintf(f, " %.16le", scanbumper->p0[j]);
954
- // }
955
- // fprintf(f, "\n");
956
- //}
957
- //fclose(f);
958
-
959
- // Finding the last step outside any bumper
960
- k = 1;
961
- for (scanbumper = stepchain; scanbumper && (scanbumper->next); scanbumper = scanbumper->next) {
962
- k++;
963
- fac = 1.e100;
964
- for (scanbumper2 = bumperlist; scanbumper2; scanbumper2 = scanbumper2->next) {
965
- fac2 = scanbumper2->distance(scanbumper->next->p0);
966
- if (fac2 < fac) fac = fac2;
967
- }
968
- printf("\n%d %lf", k, fac);
969
- if (fac < 1.) {
970
- laststep = scanbumper;
971
- k--;
972
- scanbumper2 = scanbumper->next;
973
- while (scanbumper2) {
974
- scanbumper = scanbumper2->next;
975
- delete scanbumper2;
976
- scanbumper2 = scanbumper;
977
- }
978
- laststep->next = 0;
979
- scanbumper = laststep;
980
- }
981
- }
982
-
983
-
984
951
  // Check if the model makes sense, otherwise set negative chi square for
985
952
  // processing by subsequent programs.
986
953
  if ((c0 > 2) && (c0 < 1.e100) && flagblending < np / 2) {
@@ -1021,6 +988,58 @@ void LevMar::Run() {
1021
988
  fclose(f);
1022
989
 
1023
990
 
991
+ if (modelcode[0]=='L' && il == nlc - offsetdegeneracy - 1) {
992
+ // Find best model found so far and fit offset degeneracy model
993
+ scanbumper2 = bumperlist;
994
+ for (scanbumper = bumperlist; scanbumper; scanbumper = scanbumper->next) {
995
+ if (scanbumper->Amp < scanbumper2->Amp) scanbumper2 = scanbumper;
996
+ }
997
+ for (int i = 0; i < nps; i++) {
998
+ pr[i] = scanbumper2->p0[i];
999
+ }
1000
+
1001
+ if (sin(pr[3]) != 0) {
1002
+ double s = exp(pr[0]);
1003
+ double xc = pr[2] / sin(pr[3]);
1004
+ double ac = 2 * s;
1005
+ double b = 1 - s * s + ac * xc;
1006
+ pr[0] = log((b + sqrt(ac * ac + b * b)) / ac);
1007
+ }
1008
+ scanbumper2 = stepchain;
1009
+ while (scanbumper2) {
1010
+ scanbumper = scanbumper2->next;
1011
+ delete scanbumper2;
1012
+ scanbumper2 = scanbumper;
1013
+ }
1014
+
1015
+ stepchain = laststep = new bumper(pr, nps);
1016
+ }
1017
+ else {
1018
+
1019
+ // Finding the last step outside any bumper
1020
+ k = 1;
1021
+ for (scanbumper = stepchain; scanbumper && (scanbumper->next); scanbumper = scanbumper->next) {
1022
+ k++;
1023
+ fac = 1.e100;
1024
+ for (scanbumper2 = bumperlist; scanbumper2; scanbumper2 = scanbumper2->next) {
1025
+ fac2 = scanbumper2->distance(scanbumper->next->p0);
1026
+ if (fac2 < fac) fac = fac2;
1027
+ }
1028
+ printf("\n%d %lf", k, fac);
1029
+ if (fac < 1.) {
1030
+ laststep = scanbumper;
1031
+ k--;
1032
+ scanbumper2 = scanbumper->next;
1033
+ while (scanbumper2) {
1034
+ scanbumper = scanbumper2->next;
1035
+ delete scanbumper2;
1036
+ scanbumper2 = scanbumper;
1037
+ }
1038
+ laststep->next = 0;
1039
+ scanbumper = laststep;
1040
+ }
1041
+ }
1042
+ }
1024
1043
  // Updating time count
1025
1044
  //printf("\npartial time=%lf secs\n",(Environment::TickCount-tm)/1000.0);
1026
1045
  //printf("total time = %lf mins\n",(Environment::TickCount-tim0)/60000.0);
@@ -0,0 +1,91 @@
1
+ // LevMarFit.h
2
+ // Definition of the LevMar and bumper classes for Levenberg-Marquardt fitting
3
+
4
+ #include <cstdio>
5
+ #include "bumper.h"
6
+ #include <regex>
7
+ #include <filesystem>
8
+
9
+ using namespace std;
10
+ using namespace std::filesystem;
11
+
12
+ #ifndef _LevMarFit
13
+ #define _LevMarFit
14
+ #define __unmanaged
15
+
16
+ #include <VBMicrolensingLibrary.h>
17
+
18
+ class LevMar {
19
+
20
+ VBMicrolensing* VBM;
21
+
22
+ char eventname[512], filename[30], filnum[10], outdir[30], satellitedir[256];
23
+ char modelcode[16];
24
+ int error;
25
+ int flagblending;
26
+ path exedir;
27
+
28
+ double tim0, tm;
29
+
30
+ double (VBMicrolensing::* model)(double*, double);
31
+ int nps;
32
+ double* sigmapr, * leftlim, * rightlim;
33
+
34
+ int* filter, * satel, nfil, np, OGLE;
35
+ double* t, * y, * w, * delta, * maxdelta, * Curv, * A, * B, * B0, * Cov, * fb, ** Gr, * dFdp, * errs;
36
+ double* pr, * prn, * sumy, * sumy2, * sumsigma, * sumfy, * sumf, * sumf2, * limbdarks;
37
+
38
+ int consnumber, *consindex;
39
+ double* constraints, * consleft, * consright, *consvars;
40
+ int modnumber;
41
+
42
+ double Tol;
43
+
44
+ void (LevMar::* PrintOut)(double*);
45
+ void (LevMar::* PrintFile)(FILE*, double, bool);
46
+
47
+ bumper* stepchain, * bumperlist, * laststep;
48
+
49
+
50
+ public:
51
+ LevMar(int, char**);
52
+ ~LevMar();
53
+
54
+ void ReadFiles(int, char**);
55
+ int InitCond(double* presigmapr, double* preleftlim, double* prerightlim);
56
+ void ReadCurve();
57
+ void ReadOptions();
58
+ void Run();
59
+ double ChiSquared(double*);
60
+ void Grad();
61
+ void Covariance();
62
+ double ComputeConstraint(double *pr, int i);
63
+
64
+ void PrintOutPS(double*);
65
+ void PrintOutPX(double*);
66
+ void PrintOutBS(double*);
67
+ void PrintOutBO(double*);
68
+ void PrintOutLS(double*);
69
+ void PrintOutLX(double*);
70
+ void PrintOutLO(double*);
71
+ void PrintOutLK(double*);
72
+ void PrintOutTS(double*);
73
+ void PrintOutTX(double*);
74
+
75
+ void PrintFilePS(FILE*, double, bool);
76
+ void PrintFilePX(FILE*, double, bool);
77
+ void PrintFileBS(FILE*, double, bool);
78
+ void PrintFileBO(FILE*, double, bool);
79
+ void PrintFileLS(FILE*, double, bool);
80
+ void PrintFileLX(FILE*, double, bool);
81
+ void PrintFileLO(FILE*, double, bool);
82
+ void PrintFileLK(FILE*, double, bool);
83
+ void PrintFileTS(FILE*, double, bool);
84
+ void PrintFileTX(FILE*, double, bool);
85
+
86
+ };
87
+
88
+ double Determinant(double*, int);
89
+ void Inverse(double*, double*, int);
90
+
91
+ #endif