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

Address issue 142 #143

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -v .
pip install --no-binary=mpi4py mpi4py astropy pytest pytest-cov
pip install --no-binary=mpi4py mpi4py astropy pytest pytest-cov getdist

- name: Install PocoMC
if: matrix.python-version != '3.7'
Expand Down
23 changes: 21 additions & 2 deletions cosmosis/postprocessing/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,20 @@ def get_gdobj(self):
def compute_basic_statsgd_col(self, gdc, col):
dens1d = gdc.get1DDensity(col,writeDataToFile=False)
if dens1d is None:
return [np.nan for i in range(9)]
return [np.nan for i in range(11)]


post = self.reduced_col("post")

try:
like = self.reduced_col("like")
except ValueError:
like = post - self.reduced_col("prior")

data1 = self.reduced_col(col)
maxlike = data1[like.argmax()]
maxpost = data1[post.argmax()]


def func(x):
return -dens1d.Prob(x)
Expand All @@ -298,6 +311,8 @@ def func(x):
dens1d.getLimits([0.68])[1],
dens1d.getLimits([0.95])[0],
dens1d.getLimits([0.95])[1],
maxlike,
maxpost,
]
return results

Expand Down Expand Up @@ -753,8 +768,12 @@ def compute_basic_statsgd_col(self, gdc, col):
if dens1d is None:
return [np.nan for i in range(11)]

like = self.reduced_col("like")
post = self.reduced_col("post")
try:
like = self.reduced_col("like")
except ValueError:
like = post - self.reduced_col("prior")

data1 = self.reduced_col(col)
maxlike = data1[like.argmax()]
maxpost = data1[post.argmax()]
Expand Down
49 changes: 25 additions & 24 deletions cosmosis/test/test_samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,32 @@ def run(name, check_prior, check_extra=True, can_postprocess=True, do_truth=Fals
if can_postprocess:
pp_class = postprocessor_for_sampler(name)
print(pp_class)
with tempfile.TemporaryDirectory() as dirname:
truth_file = values.name if do_truth else None
pp = pp_class(output, "Chain", 0, outdir=dirname, prefix=name, truth=truth_file, fatal_errors=True)
pp_files = pp.run()
pp.finalize()
pp.save()
for p in pp_files:
print(p)
postprocess_files = ['parameters--p1', 'parameters--p2']
if pp_2d:
postprocess_files.append('2D_parameters--p2_parameters--p1')
if check_extra and pp_extra and not no_extra:
postprocess_files.append('parameters--p3')
for getdist in [True, False]:
with tempfile.TemporaryDirectory() as dirname:
truth_file = values.name if do_truth else None
pp = pp_class(output, "Chain", 0, outdir=dirname, prefix=name, truth=truth_file, fatal_errors=True, getdist=getdist)
pp_files = pp.run()
pp.finalize()
pp.save()
for p in pp_files:
print(p)
postprocess_files = ['parameters--p1', 'parameters--p2']
if pp_2d:
postprocess_files += ['2D_parameters--p3_parameters--p2', '2D_parameters--p3_parameters--p1']
for p in postprocess_files:
filename = f"{dirname}{os.path.sep}{name}_{p}.png"
print("WANT ", filename)
assert filename in pp_files
assert os.path.exists(filename)
for p in os.listdir(dirname):
p = os.path.join(dirname, p)
if p.endswith(".txt"):
Table.read(p, format='ascii.commented_header')
print(f"Read file {p} as a table")
postprocess_files.append('2D_parameters--p2_parameters--p1')
if check_extra and pp_extra and not no_extra:
postprocess_files.append('parameters--p3')
if pp_2d:
postprocess_files += ['2D_parameters--p3_parameters--p2', '2D_parameters--p3_parameters--p1']
for p in postprocess_files:
filename = f"{dirname}{os.path.sep}{name}_{p}.png"
print("WANT ", filename)
assert filename in pp_files
assert os.path.exists(filename)
for p in os.listdir(dirname):
p = os.path.join(dirname, p)
if p.endswith(".txt"):
Table.read(p, format='ascii.commented_header')
print(f"Read file {p} as a table")


return output
Expand Down
Loading