Skip to content

fix: confidence of a one-option distribution is 1.0, not a ZeroDivisionError - #11

Merged
razorback16 merged 1 commit into
razorback16:mainfrom
kevin9327:fix/confidence-singleton
Oct 6, 2026
Merged

razorback16 merged 1 commit into
razorback16:mainfrom
kevin9327:fix/confidence-singleton

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

confidence(p) is defined as 1 - H(p)/ln(K). When p has one entry, ln(1) is 0 and the call raises:

>>> from openjev.engine import confidence
>>> confidence([1.0])
ZeroDivisionError: float division by zero

An empty list hits the same division. One-option Choice/Score answers are currently short-circuited as "forced" answers before confidence runs, so the crash is latent, but the helper is part of the public engine API (imported and tested) and a single-outcome distribution is fully certain by definition.

Change: return 1.0 for a one-element distribution and 0.0 for an empty one, matching the docstring ("1 is certain, 0 uniform"). Existing multi-option cases are unchanged.

Test: test_confidence now asserts confidence([1.0]) == 1.0 and confidence([]) == 0.0. Both raise ZeroDivisionError on main and pass with this change.

python3 -m pytest -q tests/test_api.py::test_confidence   # 1 passed

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@razorback16
razorback16 merged commit 4e7fd24 into razorback16:main Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants