Skip to content

Commit

Permalink
tests improvements and base model for gamma_pl adapted
Browse files Browse the repository at this point in the history
  • Loading branch information
sibirrer committed Jul 6, 2024
1 parent 314b6fb commit d36c598
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions hierarc/LensPosterior/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,5 @@ def __init__(
gamma_in_scaling=gamma_in_scaling,
log_m2l_scaling=log_m2l_scaling,
gamma_pl_scaling=gamma_pl_scaling,
gamma_pl_mean=gamma,
)
5 changes: 4 additions & 1 deletion hierarc/LensPosterior/kin_scaling_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(
gamma_in_scaling=None,
log_m2l_scaling=None,
gamma_pl_scaling=None,
gamma_pl_mean=None,
):
"""
Expand All @@ -22,6 +23,7 @@ def __init__(
:param gamma_in_scaling: array of gamma_in parameter to be interpolated (optional, otherwise None)
:param log_m2l_scaling: array of log_m2l parameter to be interpolated (optional, otherwise None)
:param gamma_pl_scaling: array of power-law density profile slopes to be interpolated (optional, otherwise None)
:param gamma_pl_mean: mean gamma_pl upon which the covariances are calculated
"""
self._r_eff = r_eff
self._anisotropy_model = anisotropy_model
Expand Down Expand Up @@ -51,6 +53,7 @@ def __init__(
self._gamma_in_scaling = gamma_in_scaling
self._log_m2l_scaling = log_m2l_scaling
self._gamma_pl_scaling = gamma_pl_scaling
self._gamma_pl_mean = gamma_pl_mean

if gamma_in_scaling is not None:
self._param_name_list.append("gamma_in")
Expand Down Expand Up @@ -101,7 +104,7 @@ def kwargs_lens_base(self):
if "log_m2l" in self._param_name_list:
kwargs_base["log_m2l"] = np.mean(self._log_m2l_scaling)
if "gamma_pl" in self._param_name_list:
kwargs_base["gamma_pl"] = np.mean(self._gamma_pl_scaling)
kwargs_base["gamma_pl"] = self._gamma_pl_mean
return kwargs_base

@property
Expand Down
2 changes: 1 addition & 1 deletion hierarc/Likelihood/hierarchy_likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def log_likelihood_single(
kwargs_kin_draw = self._aniso_distribution.draw_anisotropy(**kwargs_kin)
kwargs_param = {**kwargs_lens_draw, **kwargs_kin_draw}
kin_scaling = self.kin_scaling(kwargs_param)

print(kwargs_lens_draw, 'test kwargs_lens_draw')
lnlikelihood = self.log_likelihood(
ddt_,
dd_,
Expand Down
7 changes: 5 additions & 2 deletions test/test_LensPosterior/test_kin_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from lenstronomy.Analysis.kinematics_api import KinematicsAPI
from hierarc.Likelihood.hierarchy_likelihood import LensLikelihood
import numpy.testing as npt
import numpy as np
import pytest
import unittest

Expand Down Expand Up @@ -105,15 +106,17 @@ def test_likelihoodconfiguration_om(self):
kwargs_aperture=kwargs_aperture,
kwargs_seeing=kwargs_seeing,
anisotropy_model=anisotropy_model,
gamma_pl_scaling=np.linspace(1.8, 2.2, 5),
**kwargs_kin_api_settings
)

kwargs_likelihood = kin_constraints.hierarchy_configuration(num_sample_model=5)
kwargs_likelihood["normalized"] = False
ln_class = LensLikelihood(**kwargs_likelihood)
ln_class = LensLikelihood(gamma_pl_index=0, **kwargs_likelihood)
kwargs_kin = {"a_ani": 1}
kwargs_lens = {"gamma_pl_list": [gamma]}
ln_likelihood = ln_class.lens_log_likelihood(
cosmo, kwargs_lens={}, kwargs_kin=kwargs_kin
cosmo, kwargs_lens=kwargs_lens, kwargs_kin=kwargs_kin
)
npt.assert_almost_equal(ln_likelihood, 0, decimal=1)

Expand Down

0 comments on commit d36c598

Please sign in to comment.