anky2002 commited on
Commit
b8e7248
·
verified ·
1 Parent(s): 89b6e5c

Upload bayesian_engine.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. bayesian_engine.py +23 -5
bayesian_engine.py CHANGED
@@ -299,11 +299,29 @@ def bayesian_synthesis(agent_results: List[AgentEvidence]) -> ForensicVerdict:
299
  # Compute confidence based on agreement strength and active agent count
300
  non_failed = [s for s, f in zip(scores, failure_probs) if f < 0.5]
301
  if non_failed:
302
- score_magnitudes = [abs(s) for s in non_failed]
303
- avg_magnitude = float(np.mean(score_magnitudes))
304
- agreement = float(np.mean([1 if (s > 0) == (np.mean(non_failed) > 0) else 0 for s in non_failed]))
305
- agent_coverage = len(non_failed) / 7.0
306
- confidence_numeric = min(1.0, avg_magnitude * agreement * agent_coverage + 0.1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
  else:
308
  confidence_numeric = 0.1
309
 
 
299
  # Compute confidence based on agreement strength and active agent count
300
  non_failed = [s for s, f in zip(scores, failure_probs) if f < 0.5]
301
  if non_failed:
302
+ avg_score = float(np.mean(non_failed))
303
+ n_agents = len(non_failed)
304
+
305
+ # Count agents agreeing with the majority direction
306
+ signs = [1 if s > 0.02 else (-1 if s < -0.02 else 0) for s in non_failed]
307
+ n_pos = sum(1 for s in signs if s > 0)
308
+ n_neg = sum(1 for s in signs if s < 0)
309
+ n_agreeing = max(n_pos, n_neg)
310
+ n_directional = n_pos + n_neg
311
+
312
+ if n_directional == 0:
313
+ confidence_numeric = 0.15
314
+ elif n_pos > 0 and n_neg > 0:
315
+ # Mixed — penalize
316
+ agreement_ratio = max(n_pos, n_neg) / n_directional
317
+ confidence_numeric = min(1.0, 0.1 + 0.3 * abs(avg_score) * agreement_ratio)
318
+ else:
319
+ # All agree — compound with agent count
320
+ agent_bonus = min(1.0, np.sqrt(n_agreeing / 2.0))
321
+ coverage = n_agents / 7.0
322
+ confidence_numeric = min(1.0, 0.15 + 0.6 * abs(avg_score) * agent_bonus * coverage)
323
+ if n_agreeing >= 4:
324
+ confidence_numeric = min(1.0, confidence_numeric + 0.1)
325
  else:
326
  confidence_numeric = 0.1
327