Class: DecisionAgent::Simulation::ImpactAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/decision_agent/simulation/impact_analyzer.rb

Overview

Analyzer for quantifying rule change impact

Instance Attribute Summary collapse

Instance Method Summary collapse

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_managerObject (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

Parameters:

  • baseline_version (String, Integer, Hash)

    Baseline rule version

  • proposed_version (String, Integer, Hash)

    Proposed rule version

  • test_data (Array<Hash>)

    Test contexts to evaluate

  • options (Hash) (defaults to: {})

    Analysis options

    • :parallel [Boolean] Use parallel execution (default: true)
    • :thread_count [Integer] Number of threads (default: 4)
    • :calculate_risk [Boolean] Calculate risk score (default: true)

Returns:

  • (Hash)

    Impact analysis report



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: {})
  options = {
    parallel: true,
    thread_count: 4,
    calculate_risk: true
  }.merge(options)

  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, options)

  # Build impact report
  build_impact_report(results, options)
end

#calculate_risk_score(results) ⇒ Float

Calculate risk score for a rule change

Parameters:

  • results (Array<Hash>)

    Comparison results

Returns:

  • (Float)

    Risk score between 0.0 (low risk) and 1.0 (high risk)



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