Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds footprint option to cluster likelihoods #140

Draft
wants to merge 78 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
4449e46
split into two files for binned and unbinned
eunseongleee Jun 28, 2022
e3c50aa
split unbinned / binned cluster likelihoods
itrharrison Jul 13, 2022
b302208
added test yaml
itrharrison Jul 13, 2022
f19d9c3
merge conflicts
itrharrison Jul 13, 2022
d9722e7
Update clusters.py
borisbolliet Jul 13, 2022
203cb91
Update clusters.py
borisbolliet Jul 13, 2022
293d1b0
merging
borisbolliet Jul 14, 2022
46dadab
Update .gitignore
borisbolliet Jul 14, 2022
d2e3752
works with so files and print n(z) from unbinned lkl
borisbolliet Jul 14, 2022
e6488ac
fix to get the unbinned code run fast
borisbolliet Jul 14, 2022
c56aadb
merging in progreess: adding ccl
borisbolliet Sep 2, 2022
3e9cc12
Update test_binned_lkl_ccl.yaml
borisbolliet Sep 2, 2022
b5a779f
merging done
borisbolliet Sep 3, 2022
2afc946
Create DR5-compare-SOLikeT-mocks-sim-kit_NemoCCL_A10tSZ_DR5White_ACT-…
borisbolliet Sep 3, 2022
c199193
starting modifying unbinned lkl
borisbolliet Sep 3, 2022
47cb0c3
in progress (fails)
borisbolliet Sep 4, 2022
6ef757f
unbinned works with dr5 sims but minor bug with ccl unbinned
borisbolliet Sep 4, 2022
7dea653
wip
borisbolliet Sep 6, 2022
a1db65d
working
borisbolliet Sep 6, 2022
c6a8376
deleting unused files
borisbolliet Sep 6, 2022
d1c0b2c
sync in progress
borisbolliet Sep 6, 2022
305b57a
Update clusters.py
borisbolliet Sep 7, 2022
ff2bde4
tidying a bit
borisbolliet Sep 7, 2022
923fa90
fixed discrepancy between binned and unbinned
borisbolliet Sep 7, 2022
15e158d
added directions in yaml file
borisbolliet Sep 7, 2022
dfc798e
instructions
borisbolliet Sep 7, 2022
c7f3198
commented class_sz
borisbolliet Sep 8, 2022
8025b8e
Merge branch 'master' into dev-clusters-both
borisbolliet Sep 8, 2022
596b8ba
vectorized unbinned lkl
borisbolliet Sep 8, 2022
172e145
binned_lkl_camb
borisbolliet Sep 9, 2022
fa7ac43
merging
borisbolliet Sep 9, 2022
f2531bc
Update clusters.py
borisbolliet Sep 9, 2022
769e83b
Added scatter for injection completeness.
anicola Sep 12, 2022
53f80b7
Adding notebooks.
anicola Sep 12, 2022
23b96cd
Injection-based completeness in terms of observed y.
anicola Sep 13, 2022
d692aa2
Adding notebook for more mock comparisons.
anicola Sep 13, 2022
66074a6
Added scatter to Qfit completeness.
anicola Sep 13, 2022
03b8d87
Adapted config files.
anicola Sep 13, 2022
4f00066
Added mass conversion to unbinned likelihood.
anicola Sep 13, 2022
9bb089c
beginning of speeding up binned likelihood
eunseongleee Sep 21, 2022
9fa268f
removing obsolete options
eunseongleee Sep 22, 2022
78ecf4d
Update .gitignore
eunseongleee Sep 22, 2022
9f0ba06
Delete soliket/clusters/data/act directory
eunseongleee Sep 22, 2022
016b5da
speeding up binned lkl
eunseongleee Sep 28, 2022
a9468c5
correcting the average Q computation in an injection method
eunseongleee Oct 18, 2022
401b1bc
added nemo-sz as a requirement
itrharrison Oct 22, 2022
4494e52
Update test_unbinned_lkl_camb_dr5.yaml
borisbolliet Dec 6, 2022
5d8b0c8
synchronising binned and unbinned lkl and tidying up options regardin…
eunseongleee Dec 15, 2022
6e00212
Merge branch 'dev-clusters-both' of https://github.com/simonsobs/SOLi…
eunseongleee Dec 15, 2022
1b1f537
update pytest for both cluster lkl
eunseongleee Dec 20, 2022
035227e
tidying up
eunseongleee Dec 20, 2022
fb8c8ad
speeding up unbinned lkl (no scatter)
eunseongleee Dec 23, 2022
dc7ab7c
speeding up the unbinned lkl (no scatter)
eunseongleee Jan 4, 2023
6ac62a4
switching the error func in completeness to the step func
eunseongleee Jan 19, 2023
74aa92d
tidying up
eunseongleee Feb 13, 2023
41a45f8
tidying up unbinned lkl
eunseongleee Feb 16, 2023
85ebfab
updating the unbinned likelihood
eunseongleee Mar 20, 2023
0ad184d
Adding functionality to compute gof for Poisson statistics.
anicola Mar 21, 2023
f0b7d29
tidying up
eunseongleee Jun 9, 2023
5790c69
note added for cash statistics
eunseongleee Jun 9, 2023
cdc4a21
Merge branch 'master' into dev-clusters-both
mattyowl Jul 11, 2023
1980ed8
Footprints in the clusters likelihood
mattyowl Jul 12, 2023
19c0d16
Resolve conflict
mattyowl Jul 12, 2023
4906ce4
Fix for tile name strings in catalog
mattyowl Jul 13, 2023
35e4ffd
Added nemo-sz >= 0.6.0 to the requirements
mattyowl Jul 18, 2023
db53bbe
Bump required nemo version
mattyowl Jul 19, 2023
7719d67
Merge branch 'master' into dev-clusters-footprints
mattyowl Aug 30, 2023
b7573c4
Fixed up merge issues
mattyowl Aug 30, 2023
2a46821
More fixes for botched merge
mattyowl Aug 30, 2023
9443d1d
Added optimization bias correction in theory side
mattyowl Aug 30, 2023
4ca8b4f
Clean up
mattyowl Aug 30, 2023
8dc9834
Optimization bias model for no scatter case
mattyowl Aug 30, 2023
45c19c1
Working with CCL v3+
mattyowl Aug 31, 2023
8f5719d
Avoiding byteswapping
mattyowl Sep 6, 2023
2d5ffe5
Added theory correct to Ntot in unbinned likelihood
mattyowl Sep 6, 2023
9158ef6
Made opt bias parameters fittable
mattyowl Sep 6, 2023
7bc3f87
Additional parameters for noiseless catalog tests
mattyowl Jan 31, 2024
c3b4181
Fix for Cobaya >= 3.5
mattyowl Feb 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,19 @@ venv.bak/

# mypy
.mypy_cache/


# clusters
soliket/clusters/data/selFn*
soliket/clusters/data/*zip
soliket/clusters/data/*fits
soliket/clusters/chains
soliket/clusters/notebooks/figures
soliket/clusters/data/act/*
soliket/clusters/data/advact/*
.DS_Store
soliket/ymap
soliket/cosmopower
soliket/clusters/checks/*
soliket/clusters/notebooks/figs/*
soliket/clusters/notebooks/ongoing/*
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ pyccl
sacc
fgspectra>=1.1.0
syslibrary
nemo-sz>=0.6.1
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ install_requires =
sacc
fgspectra>=1.1.0
syslibrary
nemo-sz>=0.6.1

[options.package_data]
soliket = *.yaml,*.bibtex,clusters/data/*,clusters/data/selFn_equD56/*,lensing/data/*.txt,lensing/data/*.fits,mflike/*.yaml,tests/*.yaml,data/xcorr_simulated/*.txt,data/CosmoPower/CP_paper/CMB/*.pkl,tests/data/test_bandpass/*,cross_correlation/*.yaml
Expand Down
5 changes: 3 additions & 2 deletions soliket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .gaussian import GaussianLikelihood, MultiGaussianLikelihood # noqa: F401
# from .studentst import StudentstLikelihood # noqa: F401
from .ps import PSLikelihood, BinnedPSLikelihood # noqa: F401
from .clusters import BinnedClusterLikelihood, UnbinnedClusterLikelihood # noqa: F401
from .mflike import MFLike # noqa: F401
from .mflike import TheoryForge_MFLike
from .cross_correlation import GalaxyKappaLikelihood, ShearKappaLikelihood # noqa: F401, E501
Expand All @@ -12,7 +13,7 @@
from .ccl import CCL # noqa: F401

try:
from .clusters import ClusterLikelihood # noqa: F401
from .clusters import BinnedClusterLikelihood, UnbinnedClusterLikelihood # noqa: F401
except ImportError:
print('Skipping cluster likelihood (is pyCCL installed?)')
pass
pass
19 changes: 7 additions & 12 deletions soliket/cash.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
import numpy as np
from typing import Optional

from cobaya.likelihood import Likelihood
from .cash_data import CashCData


class CashCLikelihood(Likelihood):
name: str = "Cash-C"
datapath = Optional[str]

def initialize(self):

x, N = self._get_data()
N = self._get_data()
self.data = CashCData(self.name, N)

def _get_data(self):
data = np.loadtxt(self.datapath, unpack=False)
N = data[:, -1] # assume data stored like column_stack([z, q, N])
x = data[:, :-1]
return x, N
raise NotImplementedError

def _get_theory(self, **kwargs):
if ("cash_test_logp" in kwargs):
return np.arange(kwargs["cash_test_logp"])
else:
raise NotImplementedError

def logp(self, **params_values):
theory = self._get_theory(**params_values)
def logp(self, **kwargs):
pk_intp = self.provider.get_Pk_interpolator()
theory = self._get_theory(pk_intp, **kwargs)
return self.data.loglike(theory)


55 changes: 39 additions & 16 deletions soliket/cash_data.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,62 @@
import numpy as np
from scipy.special import factorial
import math as m


def cash_c_logpdf(theory, data, usestirling=True):
def cash_c_logpdf(theory, data, usestirling=True, name="binned"):

data = np.asarray(data, dtype=int)
__, __, delN2Dcat, zcut = data

ln_fac = np.zeros_like(data, dtype=float)
obs = np.asarray(delN2Dcat, dtype=int)
ln_fac = np.zeros_like(obs, dtype=float)
zcut_arr = np.arange(zcut)

# print("WARNING: Zapped some S/N bins as a test")
# theory=theory[:, 1:]
# obs=obs[:, 1:]
# ln_fac=ln_fac[:, 1:]

if zcut > 0:
theory = np.delete(theory, zcut_arr, 0)
obs = np.delete(obs, zcut_arr, 0)
ln_fac = np.delete(ln_fac, zcut_arr, 0)
print("\r ::: Excluding first {} redshift bins in likelihood.".format(zcut))

for i in range(theory.shape[0]):
print('\r Number of clusters in redshift bin {}: {}.'.format(i, theory[i,:].sum()))
print('------------')
for i in range(theory.shape[1]):
print('\r Number of clusters in SNR bin {}: {}.'.format(i, theory[:,i].sum()))
print('------------')
print('\r Total predicted N = {}'.format(theory.sum()))
print('\r Total observed N = {}'.format(obs.sum()))

if usestirling: # use Stirling's approximation for N > 10
ln_fac[data > 10] = 0.918939 + (data[data > 10] + 0.5) \
* np.log(data[data > 10]) - data[data > 10]
ln_fac[data <= 10] = np.log(factorial(data[data <= 10]))
else:
ln_fac[data > 0] = np.log(factorial(data[data > 0]))
ln_fac[data == 0] = 0.
ln_fac[obs > 10] = 0.918939 + (obs[obs > 10] + 0.5) * np.log(obs[obs > 10]) - obs[obs > 10]
ln_fac[obs <= 10] = np.log(factorial(obs[obs <= 10]))
else: # direct compuation of factorial
ln_fac[obs > 0] = np.log(factorial(obs[obs > 0]))
ln_fac[obs == 0] = 0.

log_theory = np.zeros_like(theory, dtype=float)
log_theory[theory > 0] = np.log(theory[theory > 0])
log_theory[theory == 0] = 0.

loglike = data * np.log(theory) - theory - ln_fac
loglike = obs * log_theory - theory - ln_fac

print("\r ::: 2D ln likelihood = ", np.nansum(loglike[np.isfinite(loglike)]))

return np.nansum(loglike[np.isfinite(loglike)])



class CashCData:
"""Named multi-dimensional Cash-C distributed data
"""

def __init__(self, name, N, usestirling=True):

self.name = str(name)
self.data = N
self.usestirling = usestirling

def __len__(self):
return len(self.data)

def loglike(self, theory):
return cash_c_logpdf(theory, self.data)
return cash_c_logpdf(theory, self.data, name=self.name)
3 changes: 2 additions & 1 deletion soliket/clusters/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .clusters import ClusterLikelihood # noqa: F401
from .clusters import BinnedClusterLikelihood, UnbinnedClusterLikelihood # noqa: F401
from .ccl_th import CCL
Loading
Loading