Skip to content

Commit

Permalink
add reminder to handle edge cases when pi = 0 or 1 more thoroughly
Browse files Browse the repository at this point in the history
  • Loading branch information
ashuaibi7 committed Dec 12, 2024
1 parent c0f3687 commit ebd45fa
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/dialect/models/gene.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def verify_pi_is_valid(self, pi):
raise ValueError("Estimated pi is out of bounds.")
if pi == 0 or pi == 1:
logging.info(f"Pi for gene {self.name} is 0 or 1")
return np.inf if pi else -np.inf

# ---------------------------------------------------------------------------- #
# Likelihood & Metric Evaluation #
Expand Down Expand Up @@ -101,6 +100,9 @@ def compute_log_likelihood(self, pi):
self.verify_bmr_pmf_and_counts_exist()
self.verify_bmr_pmf_contains_all_count_keys()

# ? should we skip zero valued terms in log likelihood summation
# ? should we deal with log(0) issues in some other way (pi = 0 or 1)
# TODO: validate mathematical approach to this computation
log_likelihood = sum(
np.log(self.bmr_pmf.get(c, 0) * (1 - pi) + self.bmr_pmf.get(c - 1, 0) * pi)
for c in self.counts
Expand Down

0 comments on commit ebd45fa

Please sign in to comment.