Skip to content
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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file.

## [1.0.2] - 2026-04-08

### Bug Fixes

- Correct TI evaluation and leave out uncertainty reporting. Fixes [#81].

### Miscellaneous Tasks

- Change email addresses.

## [1.0.1] - 2025-09-10

### Bug Fixes
Expand Down Expand Up @@ -915,6 +925,7 @@ returns `None` instead. Fixes [#11]
## [0.5.3] - 2022-08-22

<!-- markdownlint-disable-file MD024 -->
[1.0.2]: https://github.com/lycosystem/lyscripts/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/lycosystem/lyscripts/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/lycosystem/lyscripts/compare/1.0.0rc3...1.0.0
[1.0.0rc3]: https://github.com/lycosystem/lyscripts/compare/1.0.0rc2...1.0.0rc3
Expand Down Expand Up @@ -979,6 +990,7 @@ returns `None` instead. Fixes [#11]
[#72]: https://github.com/lycosystem/lyscripts/issues/72
[#74]: https://github.com/lycosystem/lyscripts/issues/74
[#75]: https://github.com/lycosystem/lyscripts/issues/75
[#81]: https://github.com/lycosystem/lyscripts/issues/81

[`emcee`]: https://emcee.readthedocs.io/en/stable/
[`rich`]: https://rich.readthedocs.io/en/latest/
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ build-backend = "setuptools.build_meta"
name = "lyscripts"
description = "Package to interact with lymphatic progression data and models."
authors = [
{name = "Roman Ludwig", email = "roman.ludwig@usz.ch"}
{name = "Roman Ludwig", email = "gygqdstu3@mozmail.com"},
{name = "Yoel Pérez Haas", email = "yoel.perezhaas@usz.ch"},
{name = "Noemi Bührer", email = "noemi.buehrer@usz.ch"},
]
readme = "README.md"
requires-python = ">=3.10"
Expand Down
2 changes: 1 addition & 1 deletion src/lyscripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
__version__ = version
__description__ = "Package to interact with lymphatic progression data and models."
__author__ = "Roman Ludwig"
__email__ = "roman.ludwig@usz.ch"
__email__ = "gygqdstu3@mozmail.com"
__uri__ = "https://github.com/lycosystem/lyscripts"

# activate copy on write in pandas.
Expand Down
25 changes: 9 additions & 16 deletions src/lyscripts/compute/evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,17 @@ def comp_bic(log_probs: np.ndarray, num_params: int, num_data: int) -> float:
def compute_evidence(
temp_schedule: np.ndarray,
log_probs: np.ndarray,
num: int = 1000,
) -> tuple[float, float]:
"""Compute the evidence and its standard deviation.
) -> float:
"""Compute the evidence.

Given a ``temp_schedule`` of inverse temperatures and corresponding sets of
``log_probs``, draw ``num`` "paths" of log-probabilities and compute the evidence
for each using trapezoidal integration.

The evidence is then the mean of those ``num`` integrations, while the error is
their standard deviation.
``log_probs``, we calculate the mean ``log_prob`` over all samples to approximate
the expectation value under the corresponding power posterior for each step in the
``temp_schedule``. The evidence is evaluated using trapezoidal integration of the
expectation values over the ``temp_schedule``.
"""
integrals = np.zeros(shape=num)
for i in range(num):
rand_idx = RNG.choice(log_probs.shape[1], size=log_probs.shape[0])
drawn_accuracy = log_probs[np.arange(log_probs.shape[0]), rand_idx].copy()
integrals[i] = trapezoid(y=drawn_accuracy, x=temp_schedule)
return np.mean(integrals), np.std(integrals)
a_mc = np.mean(log_probs, axis=1)
return trapezoid(y=a_mc, x=temp_schedule)


def compute_ti_results(
Expand Down Expand Up @@ -95,9 +89,8 @@ def compute_ti_results(
)
ti_log_probs[i] = reader.get_blobs(flat=True)["log_prob"]

evidence, evidence_std = compute_evidence(temp_schedule, ti_log_probs)
evidence = compute_evidence(temp_schedule, ti_log_probs)
metrics["evidence"] = evidence
metrics["evidence_std"] = evidence_std

return temp_schedule, ti_log_probs

Expand Down
25 changes: 9 additions & 16 deletions src/lyscripts/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,17 @@ def comp_bic(log_probs: np.ndarray, num_params: int, num_data: int) -> float:
def compute_evidence(
temp_schedule: np.ndarray,
log_probs: np.ndarray,
num: int = 1000,
) -> tuple[float, float]:
"""Compute the evidence and its standard deviation.
) -> float:
"""Compute the evidence.

Given a ``temp_schedule`` of inverse temperatures and corresponding sets of
``log_probs``, draw ``num`` "paths" of log-probabilities and compute the evidence
for each using trapezoidal integration.

The evidence is then the mean of those ``num`` integrations, while the error is
their standard deviation.
``log_probs``, we calculate the mean ``log_prob`` over all samples to approximate
the expectation value under the corresponding power posterior for each step in the
``temp_schedule``. The evidence is evaluated using trapezoidal integration of the
expectation values over the ``temp_schedule``.
"""
integrals = np.zeros(shape=num)
for i in range(num):
rand_idx = RNG.choice(log_probs.shape[1], size=log_probs.shape[0])
drawn_accuracy = log_probs[np.arange(log_probs.shape[0]), rand_idx].copy()
integrals[i] = trapezoid(y=drawn_accuracy, x=temp_schedule)
return np.mean(integrals), np.std(integrals)
a_mc = np.mean(log_probs, axis=1)
return trapezoid(y=a_mc, x=temp_schedule)


def compute_ti_results(
Expand Down Expand Up @@ -134,9 +128,8 @@ def compute_ti_results(
reader = emcee.backends.HDFBackend(model, name=f"ti/{run}", read_only=True)
ti_log_probs[i] = reader.get_blobs(flat=True)

evidence, evidence_std = compute_evidence(temp_schedule, ti_log_probs)
evidence = compute_evidence(temp_schedule, ti_log_probs)
metrics["evidence"] = evidence
metrics["evidence_std"] = evidence_std

return temp_schedule, ti_log_probs

Expand Down
Loading