| #ifndef GAIA_CONFIDENCE_CALIBRATION_HPP |
| #define GAIA_CONFIDENCE_CALIBRATION_HPP |
|
|
| #include <vector> |
| #include <cmath> |
| #include <iostream> |
|
|
| namespace gaia { |
| namespace confidence { |
|
|
| struct Prediction { |
| double predicted; |
| double observed; |
| double variance; |
| double confidence; |
| }; |
|
|
| class Calibration { |
| public: |
| Calibration() : brier_score(0.0) {} |
| |
| void add_prediction(double predicted, double observed, double variance) { |
| Prediction p; |
| p.predicted = predicted; |
| p.observed = observed; |
| p.variance = variance; |
| p.confidence = compute_confidence(variance); |
| predictions.push_back(p); |
| } |
| |
| double compute_confidence(double variance) { |
| double max_variance = 1.0; |
| double conf = 1.0 - variance / max_variance; |
| return std::max(0.0, std::min(1.0, conf)); |
| } |
| |
| void calibrate() { |
| double sum = 0.0; |
| for (const auto& p : predictions) { |
| sum += (p.predicted - p.observed) * (p.predicted - p.observed); |
| } |
| brier_score = sum / (predictions.size() + 1e-12); |
| |
| std::cout << "Confidence Calibration:\n"; |
| std::cout << "Brier score: " << brier_score << "\n"; |
| if (brier_score < 0.1) std::cout << "✅ Excellent\n"; |
| else if (brier_score < 0.2) std::cout << "✅ Good\n"; |
| else if (brier_score < 0.3) std::cout << "⚠️ Moderate\n"; |
| else std::cout << "❌ Poor\n"; |
| |
| for (const auto& p : predictions) { |
| if (p.confidence < 0.7) { |
| std::cout << " Flag: confidence " << p.confidence * 100 << "%\n"; |
| } |
| } |
| } |
|
|
| private: |
| double brier_score; |
| std::vector<Prediction> predictions; |
| }; |
|
|
| } |
| } |
|
|
| #endif |
|
|