Class: DecisionAgent::Simulation::ImpactAnalyzer
- Inherits:
-
Object
- Object
- DecisionAgent::Simulation::ImpactAnalyzer
- Defined in:
- lib/decision_agent/simulation/impact_analyzer.rb
Overview
Analyzer for quantifying rule change impact
Instance Attribute Summary collapse
-
#version_manager ⇒ Object
readonly
Returns the value of attribute version_manager.
Instance Method Summary collapse
-
#analyze(baseline_version:, proposed_version:, test_data:, options: {}) ⇒ Hash
Analyze impact of a proposed rule change.
-
#calculate_risk_score(results) ⇒ Float
Calculate risk score for a rule change.
-
#initialize(version_manager: nil) ⇒ ImpactAnalyzer
constructor
A new instance of ImpactAnalyzer.
Constructor Details
#initialize(version_manager: nil) ⇒ ImpactAnalyzer
Returns a new instance of ImpactAnalyzer.
11 12 13 |
# File 'lib/decision_agent/simulation/impact_analyzer.rb', line 11 def initialize(version_manager: nil) @version_manager = version_manager || Versioning::VersionManager.new end |
Instance Attribute Details
#version_manager ⇒ Object (readonly)
Returns the value of attribute version_manager.
9 10 11 |
# File 'lib/decision_agent/simulation/impact_analyzer.rb', line 9 def version_manager @version_manager end |
Instance Method Details
#analyze(baseline_version:, proposed_version:, test_data:, options: {}) ⇒ Hash
Analyze impact of a proposed rule change
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/decision_agent/simulation/impact_analyzer.rb', line 24 def analyze(baseline_version:, proposed_version:, test_data:, options: {}) = { parallel: true, thread_count: 4, calculate_risk: true }.merge() baseline_agent = build_agent_from_version(baseline_version) proposed_agent = build_agent_from_version(proposed_version) # Execute both versions on test data results = execute_comparison(test_data, baseline_agent, proposed_agent, ) # Build impact report build_impact_report(results, ) end |
#calculate_risk_score(results) ⇒ Float
Calculate risk score for a rule change
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/decision_agent/simulation/impact_analyzer.rb', line 44 def calculate_risk_score(results) return 0.0 if results.empty? total = results.size decision_changes = results.count { |r| r[:decision_changed] } large_confidence_shifts = results.count { |r| (r[:confidence_delta] || 0).abs > 0.2 } rejections_increased = count_rejection_increases(results) # Risk factors change_rate = decision_changes.to_f / total confidence_volatility = large_confidence_shifts.to_f / total rejection_risk = rejections_increased.to_f / total # Weighted risk score risk_score = ( (change_rate * 0.4) + (confidence_volatility * 0.3) + (rejection_risk * 0.3) ) [risk_score, 1.0].min # Cap at 1.0 end |