Skip to content

feat(scoring): Bayesian belief propagation over trust signals (salvaged from #90) - #153

Open
cryptoxdog wants to merge 1 commit into
mainfrom
feat/belief-propagation-scoring
Open

feat(scoring): Bayesian belief propagation over trust signals (salvaged from #90)#153
cryptoxdog wants to merge 1 commit into
mainfrom
feat/belief-propagation-scoring

Conversation

@cryptoxdog

Copy link
Copy Markdown
Collaborator

Salvages the two genuinely novel files from #90 and leaves the other 106 behind.

What lands

engine/scoring/belief_propagation.py — pure functions, no side effects, deterministic, outputs bounded [0, 1]. Sits beside pareto.py and calibration.py.

Function Purpose
bayesian_update Single-step update, symmetric likelihood — evidence = 0.5 is uninformative
belief_entropy Binary Shannon entropy in bits
propagate_chain Sequential updating over an ordered hop chain
hop_trust_from_entry GATE HopEntry status → trust, degraded by timeout proximity

tests/unit/test_belief_propagation.py — 31 tests. Plus 4 doctests in the module.

What was dropped, and why

composite_score, chain_composite, and rescore_candidates are not included.

Their penalty term computed mean_belief - mean_entropy, subtracting bits from a probability. That is dimensionally incoherent, and it produced values contradicting the functions' own docstring examples — the docstring for composite_score([0.9, 0.85, 0.8]) claimed 0.87; the code returned 0.44.

The accompanying tests could not be repaired because they asserted two incompatible semantics simultaneously:

  • composite_score([0.9], 0.5) > 0.85 — a lone strong signal should score high (Bayesian accumulation)
  • chain_composite([0.95, 0.6, 0.95], 0.6) < 0.7 — one mediocre signal should cap the result despite two strong ones (weakest-link)

No single formula satisfies both. 8 of the original 38 tests failed for this reason.

The module also cited a "Theory of Trust for Trust-Aware Recommender Systems" paper attributed to Zhang et al. 2015. That work does not resolve to any published paper — the closest real result, Sun/Yu/Han/Liu 2006, uses entropy as a trust metric, not as a subtractive penalty. The citation is removed rather than reproduced.

Choosing between Bayesian accumulation and weakest-link changes candidate ordering on mixed inputs, so it is a product decision. Recorded as DEFERRED-005 rather than guessed at.

Not taken from #90

File Overlaps
traversal/graph_query.py multihop.py, pseudo_query.py
compliance/validator.py compliance/engine.py
gates/packet_bridge.py engine/packet/bridge.py

Verification

pytest tests/unit/test_belief_propagation.py --doctest-modules engine/scoring/belief_propagation.py
35 passed

ruff check          All checks passed
ruff format --check clean
mypy                no issues
contract_scanner    no violations
verify_contracts    all 20 present and wired

Closes #90

Made with Cursor

Salvaged from #90, which carried 108 files and could not merge. Two of
them are novel and drop in cleanly beside pareto.py and calibration.py;
the rest overlap existing modules (multihop.py, compliance/engine.py,
engine/packet/bridge.py) and are left behind.

Ships the parts that are mathematically sound and pass their own tests:

  bayesian_update      single-step update, symmetric likelihood
  belief_entropy       binary Shannon entropy in bits
  propagate_chain      sequential updating over an ordered hop chain
  hop_trust_from_entry GATE HopEntry status -> trust, timeout-degraded

Pure functions, no side effects, deterministic, outputs bounded [0, 1].

Drops composite_score, chain_composite, and rescore_candidates. Their
penalty term subtracted entropy (bits) from a belief (probability), which
is dimensionally incoherent and returned values contradicting the
functions' own docstring examples. The accompanying tests asserted two
incompatible scoring semantics at once -- Bayesian accumulation on one
input, weakest-link on another -- so no formula could satisfy them; 8 of
38 failed. The module's citation to a "Theory of Trust" paper does not
resolve to any published work and is removed rather than reproduced.

Choosing between the two fusion semantics is a product decision, so
composite scoring is recorded as DEFERRED-005 instead of guessed at.

31 unit tests + 4 doctests green. ruff, ruff format, mypy, contract
scanner clean.

Closes #90

Co-authored-by: Cursor <[email protected]>
@github-actions

Copy link
Copy Markdown

⚠️ Large PR Warning
Reviewable lines changed: 415
Warning threshold: 300 lines
Consider splitting for easier review

📋 Best Practices for Large Changes

  1. Refactoring + Features: Separate into 2 PRs
  2. Multiple Features: One PR per feature
  3. Database + Code: Separate migration from logic
  4. Generated Code: Exclude it from reviewable-size accounting

This PR passes the blocking limit but is larger than recommended.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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.

1 participant