[1]:
# We will start by fixing the seed for reproducibility
seed = 0
import torch
torch.manual_seed(seed)
import numpy as np
np.random.seed(seed)
import random
random.seed(seed)
[2]:
try:
import pgmuvi
except (ImportError, ModuleNotFoundError):
%pip install git+https://github.com/ICSM/pgmuvi.git
import pgmuvi
[3]:
# now generate some data from a more complex case, maybe drawing from a specific PSD to test if pgmuvi reconstructs it
# timestamps_2d = #generate random x data here
# wavelengths_2d = #generate random x data here
# fluxes_2d = #generate random y data here
# flux_err_2d =
P0, P1 = 1000, 220
n_data = 50
n_data1 = n_data
n_data2 = n_data // 2
jd_min, jd_max = 2450000, 2455000
timestamps1_2d = torch.Tensor(np.random.uniform(jd_min, jd_max, size=n_data1))
timestamps2_2d = torch.Tensor(np.random.uniform(jd_min, jd_max, size=n_data2))
timestamps_2d = torch.concat((timestamps1_2d, timestamps2_2d), dim=0)
bands1_2d = torch.Tensor(np.array([0.854] * n_data1))
bands2_2d = torch.Tensor(np.array([2.206] * n_data2))
bands_2d = torch.concat((bands1_2d, bands2_2d), dim=0)
flux1_2d = torch.Tensor(np.sin(timestamps1_2d * (2 * np.pi / P0)))
flux1_2d += 0.1 * torch.randn_like(flux1_2d)
flux1_err_2d = 0.1 * flux1_2d
flux2_2d = torch.Tensor(np.sin(timestamps2_2d * (2 * np.pi / P1) + 0.255 * jd_min))
flux2_2d += 0.18 * torch.randn_like(flux2_2d)
flux2_err_2d = 0.02 * flux2_2d
fluxes_2d = torch.concat((flux1_2d, flux2_2d), dim=0)
flux_err_2d = torch.concat((flux1_err_2d, flux2_err_2d), dim=0)
print(timestamps_2d.shape, bands_2d.shape, fluxes_2d.shape, flux_err_2d.shape)
timestamps_bands_2d = torch.stack((timestamps_2d, bands_2d), 0).T
timestamps_bands_2d.shape
torch.Size([75]) torch.Size([75]) torch.Size([75]) torch.Size([75])
/tmp/ipykernel_2106/2072022025.py:19: DeprecationWarning: __array_wrap__ must accept context and return_scalar arguments (positionally) in the future. (Deprecated NumPy 2.0)
flux1_2d = torch.Tensor(np.sin(timestamps1_2d * (2 * np.pi / P0)))
/tmp/ipykernel_2106/2072022025.py:23: DeprecationWarning: __array_wrap__ must accept context and return_scalar arguments (positionally) in the future. (Deprecated NumPy 2.0)
flux2_2d = torch.Tensor(np.sin(timestamps2_2d * (2 * np.pi / P1) + 0.255 * jd_min))
[3]:
torch.Size([75, 2])
[4]:
from pgmuvi.lightcurve import Lightcurve
lightcurve_2d = Lightcurve(
timestamps_bands_2d, fluxes_2d, yerr=flux_err_2d, xtransform="minmax"
)
/home/docs/checkouts/readthedocs.org/user_builds/pgmuvi/envs/latest/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
[5]:
lightcurve_2d._xdata_transformed
[5]:
tensor([[0.5466, 0.0000],
[0.7183, 0.0000],
[0.6023, 0.0000],
[0.5426, 0.0000],
[0.4176, 0.0000],
[0.6468, 0.0000],
[0.4320, 0.0000],
[0.9004, 0.0000],
[0.9745, 0.0000],
[0.3761, 0.0000],
[0.7972, 0.0000],
[0.5261, 0.0000],
[0.5665, 0.0000],
[0.9353, 0.0000],
[0.0539, 0.0000],
[0.0705, 0.0000],
[0.0014, 0.0000],
[0.8394, 0.0000],
[0.7832, 0.0000],
[0.8779, 0.0000],
[0.9899, 0.0000],
[0.8049, 0.0000],
[0.4566, 0.0000],
[0.7857, 0.0000],
[0.1026, 0.0000],
[0.6406, 0.0000],
[0.1285, 0.0000],
[0.9549, 0.0000],
[0.5188, 0.0000],
[0.4083, 0.0000],
[0.2535, 0.0000],
[0.7792, 0.0000],
[0.4511, 0.0000],
[0.5669, 0.0000],
[0.0000, 0.0000],
[0.6177, 0.0000],
[0.6119, 0.0000],
[0.6169, 0.0000],
[0.9540, 0.0000],
[0.6838, 0.0000],
[0.3514, 0.0000],
[0.4314, 0.0000],
[0.7002, 0.0000],
[0.0428, 0.0000],
[0.6683, 0.0000],
[0.6723, 0.0000],
[0.1976, 0.0000],
[0.1136, 0.0000],
[0.3060, 0.0000],
[0.3557, 0.0000],
[0.5687, 1.0000],
[0.4330, 1.0000],
[1.0000, 1.0000],
[0.0859, 1.0000],
[0.1961, 1.0000],
[0.1470, 1.0000],
[0.6542, 1.0000],
[0.2419, 1.0000],
[0.4616, 1.0000],
[0.2327, 1.0000],
[0.1446, 1.0000],
[0.0945, 1.0000],
[0.6576, 1.0000],
[0.1231, 1.0000],
[0.1834, 1.0000],
[0.3609, 1.0000],
[0.8274, 1.0000],
[0.0808, 1.0000],
[0.8449, 1.0000],
[0.0797, 1.0000],
[0.9877, 1.0000],
[0.4640, 1.0000],
[0.9880, 1.0000],
[0.6045, 1.0000],
[0.7431, 1.0000]])
[6]:
fit_2d = lightcurve_2d.fit(model="2D", likelihood="learn")
/home/docs/checkouts/readthedocs.org/user_builds/pgmuvi/envs/latest/lib/python3.11/site-packages/gpytorch/likelihoods/noise_models.py:150: NumericalWarning: Very small noise values detected. This will likely lead to numerical instabilities. Rounding small noise values up to 0.0001.
warnings.warn(
100%|██████████| 300/300 [00:00<00:00, 320.61it/s]
[7]:
fit_2d["covar_module.mixture_means"][-1][..., 1]
[7]:
array([[863.79974]], dtype=float32)
[8]:
lightcurve_2d.print_results()
loss: [1.1070476]
delta_loss: [-0.00032222]
likelihood.second_noise_covar.noise: [0.5293054]
mean_module.constant: [0.06104934]
covar_module.mixture_weights: [0.07785944]
covar_module.mixture_means: [1.9552399e-01 8.6379974e+02]
covar_module.mixture_scales: [8.9115834e-05 5.8973634e-01]