Skip to content

Commit

Permalink
removed sklog likelihood as deprecated and not used
Browse files Browse the repository at this point in the history
  • Loading branch information
sibirrer committed May 1, 2020
1 parent 6561126 commit cf4c551
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 111 deletions.
77 changes: 0 additions & 77 deletions hierarc/Likelihood/LensLikelihood/lens_likelihood.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
__author__ = 'sibirrer'

from lenstronomy.Cosmo.kde_likelihood import KDELikelihood
from hierarc.Util import likelihood_util
import numpy as np
from scipy import interpolate

Expand Down Expand Up @@ -34,10 +33,6 @@ def __init__(self, z_lens, z_source, likelihood_type, name='name', **kwargs_like
self._lens_type = KinLikelihoodGaussian(z_lens, z_source, **kwargs_likelihood)
elif likelihood_type == 'TDLogNorm':
self._lens_type = TDLikelihoodLogNorm(z_lens, z_source, **kwargs_likelihood)
elif likelihood_type == 'TDKinSkewLogNorm':
self._lens_type = TDKinLikelihoodSklogn(z_lens, z_source, **kwargs_likelihood)
elif likelihood_type == 'TDSkewLogNorm':
self._lens_type = TDLikelihoodSklogn(z_lens, z_source, **kwargs_likelihood)
elif likelihood_type == 'IFUKinCov':
from hierarc.Likelihood.LensLikelihood.kin_likelihood import KinLikelihood
self._lens_type = KinLikelihood(z_lens, z_source, **kwargs_likelihood)
Expand Down Expand Up @@ -163,78 +158,6 @@ def log_likelihood(self, ddt, dd, aniso_scaling=None):
return self._kde_likelihood.logLikelihood(dd_, ddt)[0]


class TDKinLikelihoodSklogn(object):
"""
class for evaluating the 2-d posterior of Ddt vs Dd coming from a lens with time delays and kinematics measurement
with a provided skewed log normal function for both Ddt and Dd
The two distributions are asssumed independant and can be combined.
"""
def __init__(self, z_lens, z_source, mu_ddt, lam_ddt, sigma_ddt, mu_dd, lam_dd, sigma_dd, explim=100):
"""
:param z_lens: lens redshift
:param z_source: source redshift
:param mu_ddt:
:param lam_ddt:
:param sigma_ddt:
:param mu_dd:
:param lam_dd:
:param sigma_dd:
:param explim: exponent limit for evaluating the likelihood
"""
self._mu_ddt, self._lam_ddt, self._sigma_ddt = mu_ddt, lam_ddt, sigma_ddt
self._mu_dd, self._lam_dd, self._sigma_dd = mu_dd, lam_dd, sigma_dd
self._explim = explim
self.num_data = 2

def log_likelihood(self, ddt, dd, aniso_scaling=None):
"""
:param ddt: time-delay distance
:param dd: angular diameter distance to the deflector
:param aniso_scaling: numpy array of anisotropy scaling on prediction of Ds/Dds
:return: log likelihood given the single lens analysis
"""
if aniso_scaling is not None:
dd_ = dd * aniso_scaling[0]
else:
dd_ = dd
logl_ddt = likelihood_util.sklogn_likelihood(ddt, self._mu_ddt, self._lam_ddt, self._sigma_ddt, explim=self._explim)
logl_dd = likelihood_util.sklogn_likelihood(dd_, self._mu_dd, self._lam_dd, self._sigma_dd, explim=self._explim)
return logl_ddt + logl_dd


class TDLikelihoodSklogn(object):
"""
class for evaluating Ddt from a lens with time delays without kinematics measurement
with a provided skewed log normal function for Ddt.
"""

def __init__(self, z_lens, z_source, mu_ddt, lam_ddt, sigma_ddt, explim=100):
"""
:param z_lens: lens redshift
:param z_source: source redshift
:param mu_ddt:
:param lam_ddt:
:param sigma_ddt:
:param explim: exponent limit for evaluating the likelihood
"""
self._mu_ddt, self._lam_ddt, self._sigma_ddt = mu_ddt, lam_ddt, sigma_ddt
self._explim = explim
self.num_data = 1

def log_likelihood(self, ddt, dd=None, aniso_scaling=None):
"""
:param ddt: time-delay distance
:param dd: angular diameter distance to the deflector
:param aniso_scaling: numpy array of anisotropy scaling on prediction of Ds/Dds
:return: log likelihood given the single lens analysis
"""
return likelihood_util.sklogn_likelihood(ddt, self._mu_ddt, self._lam_ddt, self._sigma_ddt, explim=self._explim)


class TDLikelihoodGaussian(object):
"""
class to handle cosmographic likelihood coming from modeling lenses with imaging and kinematic data but no time delays.
Expand Down
34 changes: 0 additions & 34 deletions hierarc/Util/likelihood_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,3 @@ def get_truncated_normal(mean=0, sd=1, low=0, upp=10, size=1):
"""
return truncnorm(
(low - mean) / sd, (upp - mean) / sd, loc=mean, scale=sd).rvs(size)


def sklogn_likelihood(x, mu, lam, sigma, explim=100):
"""
:param x: value to evaluate log(p(x))
:param mu:
:param lam:
:param sigma:
:param explim: exponent limit for evaluating the likelihood
:return: log likelihood
"""
if (x <= lam) or ((-mu + math.log(x - lam)) ** 2 / (2. * sigma ** 2) > explim):
return -np.inf
else:
llh = sklogn(x, mu, lam, sigma)

if np.isnan(llh):
return -np.inf
else:
return np.log(llh)


def sklogn(x, mu, lam, sigma):
"""
skewed log normal distribution
:param x: value to evaluate p(x)
:param mu:
:param lam:
:param sigma:
:return:
"""
return math.exp(-((-mu + math.log(x - lam)) ** 2 / (2. * sigma ** 2))) / (math.sqrt(2 * math.pi) * (x - lam) * sigma)

0 comments on commit cf4c551

Please sign in to comment.