-
Notifications
You must be signed in to change notification settings - Fork 41
Feature 1: AI Confidence & Uncertainty Estimation #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,6 +256,15 @@ function extractGillScore(logitsB, temperature) { | |
| * @param {number[]} gillProbs [P(Fresh_Gills), P(Nonfresh_Gills)] | ||
| * @returns {{ fusedScore: number, label: string, confidence: string }} | ||
| */ | ||
| function calculateConfidence(bodyProbs, eyeProbs, gillProbs) { | ||
| const bodyConf = Math.max(...bodyProbs); | ||
| const eyeSubSum = (eyeProbs[0] + eyeProbs[2]) || 1e-7; | ||
| const gillSubSum = (gillProbs[1] + gillProbs[3]) || 1e-7; | ||
| const eyeConf = Math.max(eyeProbs[0] / eyeSubSum, eyeProbs[2] / eyeSubSum); | ||
| const gillConf = Math.max(gillProbs[1] / gillSubSum, gillProbs[3] / gillSubSum); | ||
| return (0.5 * bodyConf) + (0.25 * eyeConf) + (0.25 * gillConf); | ||
| } | ||
|
Comment on lines
+259
to
+266
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
ast-grep run --pattern 'function extractEyeScore($_, $_) { $$$ }' --lang javascript src/fusionInference.js
ast-grep run --pattern 'function extractGillScore($_, $_) { $$$ }' --lang javascript src/fusionInference.js
rg -nP 'processAndFuse\s*\(' src/fusionInference.js -C2Repository: jpdevhub/FreshScanAi Length of output: 2058 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '180,310p' src/fusionInference.js | cat -nRepository: jpdevhub/FreshScanAi Length of output: 5744 🏁 Script executed: #!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
text = Path('src/fusionInference.js').read_text()
for name in ['extractBodyScore', 'extractEyeScore', 'extractGillScore', 'calculateConfidence', 'processAndFuse']:
idx = text.find(f'function {name}')
print(f'\n### {name} @ {idx}')
if idx != -1:
start = max(0, idx-300)
end = min(len(text), idx+1200)
print(text[start:end])
PYRepository: jpdevhub/FreshScanAi Length of output: 6306 Fix the eye/gill confidence indices
Use indices 🤖 Prompt for AI Agents |
||
|
|
||
| function processAndFuse(bodyProbs, eyeProbs, gillProbs) { | ||
| const bodyFresh = bodyProbs[0]; // P(C1 = Fresh) | ||
| const eyeFresh = eyeProbs[0]; // P(Fresh_Eyes) | ||
|
|
@@ -274,10 +283,14 @@ function processAndFuse(bodyProbs, eyeProbs, gillProbs) { | |
| label = 'Spoiled'; | ||
| } | ||
|
|
||
| const systemConfidence = calculateConfidence(bodyProbs, eyeProbs, gillProbs); | ||
| const isUncertain = systemConfidence < 0.70; | ||
|
|
||
| return { | ||
| fusedScore, | ||
| label, | ||
| confidence: (fusedScore * 100).toFixed(1) + '%', | ||
| confidence: systemConfidence, | ||
| uncertain_flag: isUncertain | ||
| }; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Logic bug:
or 1.0mishandles a stored0.0confidence and contradicts the Line 299 default.(row.get("confidence_score") or 1.0)short-circuits on any falsy value, so a legitimately stored confidence of0.0(maximally uncertain) is replaced with1.0, yieldinguncertain_flag = False— the opposite of intended.It also disagrees with Line 299, where a missing
confidence_scoredefaults to0(→ 0% confidence). So for a row with no score, the payload reportsconfidence: 0.0yetuncertain_flag: False. Use an explicitNonecheck and a consistent default.🐛 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents