Spaces:
Running
Running
Update backend/agents/reflection_agent.py
Browse files
backend/agents/reflection_agent.py
CHANGED
|
@@ -73,7 +73,7 @@ class ReflectionAgent:
|
|
| 73 |
if all_low and avg_crowd > self.CROWD_LOW_THRESH:
|
| 74 |
bias_detected = True
|
| 75 |
corrected_level = 'MEDIUM'
|
| 76 |
-
corrected_score = max(rr.risk_score, 0.
|
| 77 |
critique.append(
|
| 78 |
f'CHRONIC_LOW_BIAS: {self.BIAS_WINDOW} consecutive LOW '
|
| 79 |
f'with avg crowd={avg_crowd:.0f} persons. Upgraded to MEDIUM.'
|
|
@@ -83,7 +83,7 @@ class ReflectionAgent:
|
|
| 83 |
if rr.trend == 'rising' and rr.risk_level == 'LOW' and fr.person_count > 20:
|
| 84 |
bias_detected = True
|
| 85 |
corrected_level = 'MEDIUM'
|
| 86 |
-
corrected_score = max(corrected_score, 0.
|
| 87 |
critique.append(
|
| 88 |
f'RISING_TREND_IGNORED: trend=rising, persons={fr.person_count}, '
|
| 89 |
f'but risk=LOW. Upgraded to MEDIUM.'
|
|
@@ -91,20 +91,20 @@ class ReflectionAgent:
|
|
| 91 |
|
| 92 |
# Bias 3: Count-risk mismatch (enhanced with critical threshold)
|
| 93 |
if fr.person_count >= self.CRITICAL_CROWD_THRESH and rr.risk_level == 'LOW':
|
| 94 |
-
#
|
| 95 |
bias_detected = True
|
| 96 |
corrected_level = 'HIGH'
|
| 97 |
-
corrected_score = max(corrected_score, 0.
|
| 98 |
critique.append(
|
| 99 |
f'CRITICAL_COUNT_RISK_MISMATCH: {fr.person_count} persons but risk=LOW. '
|
| 100 |
-
f'This is a severe inconsistency
|
| 101 |
f'Upgraded to HIGH (corrected_score={corrected_score:.3f}).'
|
| 102 |
)
|
| 103 |
elif fr.person_count > self.HIGH_CROWD_THRESH and rr.risk_level == 'LOW':
|
| 104 |
-
#
|
| 105 |
bias_detected = True
|
| 106 |
corrected_level = 'MEDIUM'
|
| 107 |
-
corrected_score = max(corrected_score, 0.
|
| 108 |
critique.append(
|
| 109 |
f'COUNT_RISK_MISMATCH: {fr.person_count} persons but risk=LOW. '
|
| 110 |
f'Thresholds may need recalibration. Upgraded to MEDIUM.'
|
|
@@ -114,7 +114,7 @@ class ReflectionAgent:
|
|
| 114 |
if rr.risk_level == 'HIGH' and fr.person_count < config.REFLECTION_OVER_EST_THRESH:
|
| 115 |
bias_detected = True
|
| 116 |
corrected_level = 'MEDIUM'
|
| 117 |
-
corrected_score = min(corrected_score, 0.
|
| 118 |
critique.append(
|
| 119 |
f'OVER_ESTIMATION: HIGH risk but only {fr.person_count} persons. '
|
| 120 |
f'Downgraded to MEDIUM β possible empty-frame or detection artifact.'
|
|
|
|
| 73 |
if all_low and avg_crowd > self.CROWD_LOW_THRESH:
|
| 74 |
bias_detected = True
|
| 75 |
corrected_level = 'MEDIUM'
|
| 76 |
+
corrected_score = max(rr.risk_score, 0.30) # push into MEDIUM zone (>0.20)
|
| 77 |
critique.append(
|
| 78 |
f'CHRONIC_LOW_BIAS: {self.BIAS_WINDOW} consecutive LOW '
|
| 79 |
f'with avg crowd={avg_crowd:.0f} persons. Upgraded to MEDIUM.'
|
|
|
|
| 83 |
if rr.trend == 'rising' and rr.risk_level == 'LOW' and fr.person_count > 20:
|
| 84 |
bias_detected = True
|
| 85 |
corrected_level = 'MEDIUM'
|
| 86 |
+
corrected_score = max(corrected_score, 0.25) # push into MEDIUM zone (>0.20)
|
| 87 |
critique.append(
|
| 88 |
f'RISING_TREND_IGNORED: trend=rising, persons={fr.person_count}, '
|
| 89 |
f'but risk=LOW. Upgraded to MEDIUM.'
|
|
|
|
| 91 |
|
| 92 |
# Bias 3: Count-risk mismatch (enhanced with critical threshold)
|
| 93 |
if fr.person_count >= self.CRITICAL_CROWD_THRESH and rr.risk_level == 'LOW':
|
| 94 |
+
# 70+ persons with LOW risk β CRITICAL inconsistency β upgrade to HIGH
|
| 95 |
bias_detected = True
|
| 96 |
corrected_level = 'HIGH'
|
| 97 |
+
corrected_score = max(corrected_score, 0.85) # push into HIGH zone (>0.80)
|
| 98 |
critique.append(
|
| 99 |
f'CRITICAL_COUNT_RISK_MISMATCH: {fr.person_count} persons but risk=LOW. '
|
| 100 |
+
f'This is a severe inconsistency. '
|
| 101 |
f'Upgraded to HIGH (corrected_score={corrected_score:.3f}).'
|
| 102 |
)
|
| 103 |
elif fr.person_count > self.HIGH_CROWD_THRESH and rr.risk_level == 'LOW':
|
| 104 |
+
# 50+ persons with LOW risk β upgrade to MEDIUM
|
| 105 |
bias_detected = True
|
| 106 |
corrected_level = 'MEDIUM'
|
| 107 |
+
corrected_score = max(corrected_score, 0.30) # push into MEDIUM zone (>0.20)
|
| 108 |
critique.append(
|
| 109 |
f'COUNT_RISK_MISMATCH: {fr.person_count} persons but risk=LOW. '
|
| 110 |
f'Thresholds may need recalibration. Upgraded to MEDIUM.'
|
|
|
|
| 114 |
if rr.risk_level == 'HIGH' and fr.person_count < config.REFLECTION_OVER_EST_THRESH:
|
| 115 |
bias_detected = True
|
| 116 |
corrected_level = 'MEDIUM'
|
| 117 |
+
corrected_score = min(corrected_score, 0.50) # pull down to MEDIUM zone
|
| 118 |
critique.append(
|
| 119 |
f'OVER_ESTIMATION: HIGH risk but only {fr.person_count} persons. '
|
| 120 |
f'Downgraded to MEDIUM β possible empty-frame or detection artifact.'
|