ICSM / pgmuvi

Python gaussian processes for inference on multi-wavelength light curves
https://pgmuvi.readthedocs.io
GNU General Public License v3.0
12 stars 6 forks source link

[BUG] need more elegant way of dealing with a 1-element light curve #35

Open sundarjhu opened 1 year ago

sundarjhu commented 1 year ago

Describe the bug The current implementation of the Lightcurve object allows the creation of a 1-element light curve, but subsequently throws an error when the set_model method is called:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Volumes/SSD2TBShaanpatiKhan/MovedHomeFolder/sundar/work/SAGE/2308/PGMUVI_2comp/test_pgmuvi_2comp_newest.py", line 287, in driver
    main(runall=True)
  File "/Volumes/SSD2TBShaanpatiKhan/MovedHomeFolder/sundar/work/SAGE/2308/PGMUVI_2comp/test_pgmuvi_2comp_newest.py", line 279, in main
    _ = pgmuvi_2comp(lightcurve_1d, period_guess,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/SSD2TBShaanpatiKhan/MovedHomeFolder/sundar/work/SAGE/2308/PGMUVI_2comp/test_pgmuvi_2comp_newest.py", line 37, in pgmuvi_2comp
    lightcurve.set_model(model="1D", likelihood="learn", num_mixtures=2)
  File "/Volumes/SSD2TBShaanpatiKhan/MovedHomeFolder/sundar/work/pgmuvi/pgmuvi/lightcurve.py", line 493, in set_model
    self.model = model_dic_1[model](self._xdata_transformed,
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Volumes/SSD2TBShaanpatiKhan/MovedHomeFolder/sundar/work/pgmuvi/pgmuvi/gps.py", line 46, in __init__
    self.covar_module.initialize_from_data(train_x, train_y)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/gpytorch/kernels/spectral_mixture_kernel.py", line 244, in initialize_from_data
    min_dist = sorted_dists[..., 0, :]
               ~~~~~~~~~~~~^^^^^^^^^^^
IndexError: index 0 is out of bounds for dimension 1 with size 0

To Reproduce Steps to reproduce the behaviour:

lc = Lightcurve(torch.Tensor([[0.]]), torch.Tensor([[6.9557]]), xtransform='minmax')
lc.set_model(model="1D", likelihood="learn", num_mixtures=2)

Expected behaviour An attempt to create the Lightcurve object should throw an exception in the case of a one-element light curve.

pscicluna commented 1 year ago

We might also want warnings for lightcurves with < N points. Perhaps $5^d$ would be sensible there?

sundarjhu commented 1 year ago

Do we already have theoretical or empirical constraints on what constitutes a "good" GP fit depending on the number of points? e.g., $N{\rm points} > N{\rm pars}$? Or do we need to run some tests to get an empirical bound to return such a warning?

pscicluna commented 1 year ago

I would be surprised if there isn't some literature on that already, but I'm not sure exactly how to find it. Something to look in to. In parallel, we could simply create a few benchmark cases and incrementally increase the number of points, assessing the value and uncertainty of the hyperparameters as it goes? Might also be useful educational material for the astronomy community?

stefanwaterval commented 1 year ago

I found a similar question on stack exchange with a link to this paper. Not sure if that's what you're looking for though.

I think both the exception and the potential warning could be added in the method suggested in #43.