Class: DecisionAgent::Simulation::ReplayEngine
- Inherits:
-
Object
- Object
- DecisionAgent::Simulation::ReplayEngine
- Defined in:
- lib/decision_agent/simulation/replay_engine.rb
Overview
Engine for replaying historical decisions and backtesting rule changes
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#version_manager ⇒ Object
readonly
Returns the value of attribute version_manager.
Instance Method Summary collapse
-
#backtest(historical_data:, proposed_version:, baseline_version: nil, options: {}) ⇒ Hash
Backtest a rule change against historical data.
-
#initialize(agent:, version_manager: nil) ⇒ ReplayEngine
constructor
A new instance of ReplayEngine.
-
#replay(historical_data:, rule_version: nil, compare_with: nil, options: {}) ⇒ Hash
Replay historical decisions with a specific rule version.
Constructor Details
#initialize(agent:, version_manager: nil) ⇒ ReplayEngine
Returns a new instance of ReplayEngine.
20 21 22 23 |
# File 'lib/decision_agent/simulation/replay_engine.rb', line 20 def initialize(agent:, version_manager: nil) @agent = agent @version_manager = version_manager || Versioning::VersionManager.new end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
18 19 20 |
# File 'lib/decision_agent/simulation/replay_engine.rb', line 18 def agent @agent end |
#version_manager ⇒ Object (readonly)
Returns the value of attribute version_manager.
18 19 20 |
# File 'lib/decision_agent/simulation/replay_engine.rb', line 18 def version_manager @version_manager end |
Instance Method Details
#backtest(historical_data:, proposed_version:, baseline_version: nil, options: {}) ⇒ Hash
Backtest a rule change against historical data
64 65 66 67 68 69 70 71 72 |
# File 'lib/decision_agent/simulation/replay_engine.rb', line 64 def backtest(historical_data:, proposed_version:, baseline_version: nil, options: {}) baseline_version ||= get_active_version_for_rule(proposed_version) replay( historical_data: historical_data, rule_version: proposed_version, compare_with: baseline_version, options: ) end |
#replay(historical_data:, rule_version: nil, compare_with: nil, options: {}) ⇒ Hash
Replay historical decisions with a specific rule version
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/decision_agent/simulation/replay_engine.rb', line 36 def replay(historical_data:, rule_version: nil, compare_with: nil, options: {}) contexts = load_historical_data(historical_data) = { parallel: true, thread_count: 4, progress_callback: nil }.merge() # Build agent with specified version replay_agent = build_agent_from_version(rule_version) if rule_version replay_agent ||= @agent # Build baseline agent if comparison requested baseline_agent = build_agent_from_version(compare_with) if compare_with # Execute replay results = execute_replay(contexts, replay_agent, baseline_agent, ) # Build comparison report build_comparison_report(results, baseline_agent) end |