Skip to content

Commit

Permalink
added info functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
sibirrer committed Sep 25, 2024
1 parent b4d2150 commit 9ceecec
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion hierarc/Likelihood/LensLikelihood/base_lens_likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
:param kwargs_likelihood: keyword arguments specifying the likelihood function,
see individual classes for their use
"""
self._name = name
self.name = name
self.z_lens = z_lens
self.z_source = z_source
self.z_source2 = z_source2
Expand Down
15 changes: 14 additions & 1 deletion hierarc/Likelihood/hierarchy_likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ def __init__(
)
self._prior = PriorLikelihood(prior_list=prior_list)

def info(self):
"""
information about the lens
:return: print statement
"""
gamma_pl_index = self._lens_distribution.gamma_pl_index
print("Name: ", self.name)
print("likelihood type: ", self.likelihood_type)
if gamma_pl_index is not None:
print("gamma_pl_index", gamma_pl_index)
print("========")

def lens_log_likelihood(
self,
cosmo,
Expand Down Expand Up @@ -213,7 +226,7 @@ def lens_log_likelihood(
cosmo=cosmo,
)
if verbose:
print("log likelihood of lens %s = %s" % (self._name, a))
print("log likelihood of lens %s = %s" % (self.name, a))
return np.nan_to_num(a)

def hyper_param_likelihood(
Expand Down
9 changes: 9 additions & 0 deletions hierarc/Likelihood/lens_sample_likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ def num_data(self):
num += lens.num_data()
return num

def info(self):
"""
:return:
"""
print("number of lenses: ", self.num_data())
for lens in self._lens_list:
lens.info()

@property
def gamma_pl_num(self):
"""Number of power-law density slope parameters being sampled on individual
Expand Down
6 changes: 3 additions & 3 deletions hierarc/Sampling/Distributions/lens_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def __init__(
), kwargs_max.get("log_m2l", np.inf)
if gamma_pl_index is not None:
self._gamma_pl_model = True
self._gamma_pl_index = gamma_pl_index
self.gamma_pl_index = gamma_pl_index
else:
self._gamma_pl_model = False
self._gamma_pl_index = None
self.gamma_pl_index = None

def draw_lens(
self,
Expand Down Expand Up @@ -224,7 +224,7 @@ def draw_lens(
)
kwargs_return["log_m2l"] = log_m2l_draw
if self._gamma_pl_model is True:
kwargs_return["gamma_pl"] = gamma_pl_list[self._gamma_pl_index]
kwargs_return["gamma_pl"] = gamma_pl_list[self.gamma_pl_index]
elif self._gamma_pl_global_sampling is True:
if self._gamma_pl_global_dist in ["GAUSSIAN"]:
gamma_pl_draw = np.random.normal(gamma_pl_mean, gamma_pl_sigma)
Expand Down
3 changes: 3 additions & 0 deletions test/test_Likelihood/test_hierarchy_likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ def test_lum_dist_likelihood(self):
log_l = likelihood.lens_log_likelihood(cosmo=cosmo, kwargs_source=kwargs_source)
npt.assert_almost_equal(log_l, -24, decimal=0)

def test_info(self):
self.likelihood.info()


if __name__ == "__main__":
pytest.main()
3 changes: 3 additions & 0 deletions test/test_Likelihood/test_lens_sample_likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def test_num_data(self):
num_data = self.likelihood.num_data()
assert num_data == 3

def test_info(self):
self.likelihood.info()

def test_double_source_plane(self):
cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Ob0=0.05)
zl = 0.5
Expand Down

0 comments on commit 9ceecec

Please sign in to comment.