Skip to content

Commit 6f1dba6

Browse files
thompsonsonclaude
andcommitted
refactor: improve clarity of Bayesian update with explicit posterior and marginal variables
- Replace implicit normalization with explicit posterior_unnormalized calculation - Add explicit marginal calculation showing P(evidence) = sum of (prior * likelihood) - Improve pedagogical clarity of Bayes' rule implementation - Maintain identical mathematical behavior with better variable naming 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent f63cf4c commit 6f1dba6

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

domains/belief/belief_domain.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ def update_beliefs(self, evidence: BeliefUpdate) -> None:
7979
)
8080
likelihoods[target_idx] = likelihood
8181

82-
# Apply Bayes' rule: posterior prior * likelihood
83-
self.beliefs = self.beliefs * likelihoods
82+
# Calculate unnormalized posterior: prior * likelihood
83+
posterior_unnormalized = self.beliefs * likelihoods
8484

85-
# Normalize to ensure probabilities sum to 1
86-
total_belief = np.sum(self.beliefs)
87-
if total_belief > 0:
88-
self.beliefs = self.beliefs / total_belief
85+
# Calculate marginal: P(evidence) = sum of (prior * likelihood) for all targets
86+
marginal = np.sum(posterior_unnormalized)
87+
88+
# Apply Bayes' rule: posterior = (prior * likelihood) / marginal
89+
if marginal > 0:
90+
self.beliefs = posterior_unnormalized / marginal
8991
else:
9092
# If all likelihoods are 0 (shouldn't happen with valid evidence),
9193
# reset to uniform distribution

0 commit comments

Comments
 (0)