Using the likelihood¶
To fit the noise together with other parameters, for example those of a signal, build the noise model and call the likelihood from your own sampler. The noise parameters are the log10 PSDs at the spline knots (see The modelled pipeline).
Build the noise model¶
from lisa_noise.io import load_segment
from lisa_noise.pipeline.modelled import setup_model
segment = load_segment("processed_segments.h5", 0, science_band=(1e-4, 1e-1))
setup = setup_model(segment)
noise_model, x0 = setup.model_callable, setup.x0
lower, upper = setup.bounds
setup_model uses the package defaults; pass load_config("conf.yaml") as
its second argument to change any option in Configuration reference.
segment.data_xyzis the FFT of the three channels in the band,(Nf, 3).noise_model(None, params)is the covariance of those data,(Nf, 3, 3), with the conditioning and taper recorded in the file included.x0is the starting value of the noise parameters,loweranduppertheir prior box, andsetup.param_namestheir names.setup.maskmarks the bins to use; those around the TDI nulls are left out.
Add your own parameters¶
Subtract the signal from the data and pass the residual to the likelihood:
from lisa_noise.likelihood.likelihood import log_likelihood
def log_like(theta):
noise, signal = theta[: x0.size], theta[x0.size :]
residual = segment.data_xyz - my_signal(segment.freq, signal)
return log_likelihood(
noise,
segment.freq,
residual,
noise_model,
segment.n_samples,
segment.delta_t,
mask=setup.mask,
)
my_signal returns the signal in the same form as the data: (Nf, 3), the
unnormalised FFT of the XYZ time series after the same filter, decimation and
taper. The value is the Whittle log-likelihood up to a constant that does not
depend on the parameters.
With JAX¶
Pass jax.numpy to the model and the likelihood to compile it and get
gradients:
import jax
import jax.numpy as jnp
jax.config.update("jax_enable_x64", True)
setup = setup_model(segment, xp=jnp)
data, mask = jnp.asarray(segment.data_xyz), jnp.asarray(setup.mask)
@jax.jit
def log_like(noise):
return log_likelihood(
noise,
None,
data,
setup.model_callable,
segment.n_samples,
segment.delta_t,
mask=mask,
xp=jnp,
)
gradient = jax.grad(log_like)(jnp.asarray(setup.x0))