Skip to content

Commit 7e6ccc1

Browse files
jucorclaude
andcommitted
Address Copilot review: clarify MAP estimate, centralize PSEUDO_COUNT imports
- Clarify Beta(2,2) comment to specify posterior mode (MAP) estimate - Import PSEUDO_COUNT from repness.py instead of hardcoding in simplified_repness_test.py - Move PSEUDO_COUNT import to module-level in test_repness_unit.py and test_old_format_repness.py Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 164d968 commit 7e6ccc1

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

delphi/polismath/pca_kmeans_rep/repness.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
# Why use pseudocounts?
2525
# - Prevents extreme probabilities (0 or 1) when sample sizes are small
2626
# - With PSEUDO_COUNT = 2.0, we add 1 "virtual" agree and 1 "virtual" disagree
27-
# to each comment's vote count — equivalent to a Beta(2,2) prior
27+
# to each comment's vote count — equivalent to using a Beta(2,2) prior and
28+
# taking the posterior mode (MAP) estimate
2829
# - This pulls probabilities toward 0.5, with the effect diminishing as n grows
29-
# - Formula: p_agree = (n_agree + PSEUDO_COUNT/2) / (n_votes + PSEUDO_COUNT)
30-
# i.e. (n_agree + 1) / (n_votes + 2)
30+
# - Formula (MAP under Beta(2,2)): p_agree = (n_agree + PSEUDO_COUNT/2) / (n_votes + PSEUDO_COUNT)
31+
# i.e. (n_agree + 1) / (n_votes + 2)
3132
#
3233
# Matches Clojure's implementation (repness.clj).
3334
PSEUDO_COUNT = 2.0

delphi/tests/simplified_repness_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
# Constants
1919
Z_90 = 1.645 # Z-score for 90% confidence
20-
PSEUDO_COUNT = 2.0 # Pseudocount for Bayesian smoothing (Beta(2,2) prior, matches Clojure)
20+
21+
from polismath.pca_kmeans_rep.repness import PSEUDO_COUNT
2122

2223
def prop_test(p: float, n: int, p0: float) -> float:
2324
"""One-proportion z-test."""

delphi/tests/test_old_format_repness.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
1515

1616
from polismath.pca_kmeans_rep.repness import (
17+
PSEUDO_COUNT,
1718
z_score_sig_90, z_score_sig_95, prop_test, two_prop_test,
1819
comment_stats, add_comparative_stats, repness_metric, finalize_cmt_stats,
1920
passes_by_test, best_agree, best_disagree, select_rep_comments,
@@ -80,7 +81,6 @@ def test_comment_stats(self):
8081
n_agree = 3
8182
n_disagree = 1
8283
n_votes = 4
83-
from polismath.pca_kmeans_rep.repness import PSEUDO_COUNT
8484
p_agree = (n_agree + PSEUDO_COUNT/2) / (n_votes + PSEUDO_COUNT)
8585
p_disagree = (n_disagree + PSEUDO_COUNT/2) / (n_votes + PSEUDO_COUNT)
8686

delphi/tests/test_repness_unit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
1414

1515
from polismath.pca_kmeans_rep.repness import (
16+
PSEUDO_COUNT,
1617
z_score_sig_90, z_score_sig_95, prop_test, two_prop_test,
1718
comment_stats, add_comparative_stats, repness_metric, finalize_cmt_stats,
1819
passes_by_test, best_agree, best_disagree, select_rep_comments,
@@ -81,7 +82,6 @@ def test_comment_stats(self):
8182
n_agree = 3
8283
n_disagree = 1
8384
n_votes = 4
84-
from polismath.pca_kmeans_rep.repness import PSEUDO_COUNT
8585
p_agree = (n_agree + PSEUDO_COUNT/2) / (n_votes + PSEUDO_COUNT)
8686
p_disagree = (n_disagree + PSEUDO_COUNT/2) / (n_votes + PSEUDO_COUNT)
8787

0 commit comments

Comments
 (0)