expert system - VforVitorio/F1_Strat_Manager GitHub Wiki
Expert System
- Overview
- System Architecture
- Installation and Setup
- Streamlit Dashboard
- Strategy Recommendations View
- Gap Analysis View
- Radio Analysis View
- Time Predictions View
- Strategy Chat Interface
- Machine Learning Models
- Lap Time Prediction
- Tire Degradation Modeling
- Vision-based Gap Calculation
- NLP Pipeline
- Radio Transcription
- Sentiment and Intent Analysis
- Named Entity Recognition
- Expert System
- Degradation Rules
- Gap Analysis Rules
- Radio Message Rules
- Integrated Rule Engine
- Developer Guide
- API Reference
- Integration Guide
Expert System
- scripts/IS_agent/N01_agent_setup.ipynb
- scripts/IS_agent/N06_rule_merging.ipynb
- scripts/IS_agent/utils/N01_agent_setup.py
- scripts/IS_agent/utils/N06_rule_merging.py
The F1 Strategy Manager's Expert System is a rule-based decision-making component that evaluates race telemetry, prediction model outputs, and team radio communications to generate strategic recommendations for Formula 1 racing. This page documents the architecture, components, and operation of the Expert System, which serves as the analytical core of the strategy platform.
For information on the machine learning models that feed into this system, see Machine Learning Models. For details on the specific rule types implemented, see Degradation Rules, Gap Analysis Rules, Radio Message Rules, and Integrated Rule Engine.
Expert System Architecture
The Expert System is built on the Experta library, which implements the RETE algorithm for efficient rule matching. The system follows a declarative programming paradigm where race conditions and strategy decisions are expressed as pattern-matching rules operating on a knowledge base of facts.
- scripts/IS_agent/N06_rule_merging.ipynb128-284
- scripts/IS_agent/N01_agent_setup.ipynb438-488
- scripts/IS_agent/utils/N06_rule_merging.py78-235
Core Components and Data Flow
The Expert System processes data through several stages before producing recommendations:
Fact Classes
The Expert System operates on a set of well-defined fact classes that represent different aspects of race state and analysis:
Fact Class | Purpose | Key Fields |
---|---|---|
TelemetryFact |
Car performance data | lap_time , predicted_lap_time , tire_age , compound_id , position , driver_number |
DegradationFact |
Tire condition | degradation_rate , predicted_rates , previous_rates |
GapFact |
Gaps to other cars | gap_ahead , gap_behind , in_undercut_window , consistent_gap_ahead_laps |
RadioFact |
NLP-analyzed team radio | sentiment , intent , entities (WEATHER, PIT_CALL, etc.) |
RaceStatusFact |
Overall race state | lap , total_laps , race_phase (start/mid/end), track_status |
StrategyRecommendation |
Generated advice | action , confidence , explanation , priority |
The fact classes form the data model that rules operate on, with each rule pattern-matching against specific fact attributes.
Specialized Rule Systems
The Expert System is modularized into four specialized rule systems, each focusing on a specific aspect of race strategy:
Degradation Rules System
Evaluates tire performance and degradation patterns to recommend pit stops or stint extensions. Key rules include:
high_degradation_pit_stop
: Triggers when degradation rates exceed safe thresholdsstint_extension_recommendation
: Suggests extending stint when tires perform better than expectedearly_degradation_warning
: Provides early warnings for preparing pit stops
Lap Time Rules System
Analyzes current and predicted lap times to identify performance patterns. Key rules include:
optimal_performance_window
: Identifies periods of peak performance for push strategiesperformance_cliff_detection
: Detects sudden performance drops requiring immediate actionpost_traffic_recovery
: Suggests recovery strategies after being in traffic
Radio Analysis Rules System
Interprets team radio messages using NLP for strategic insights. Key rules include:
grip_issue_response
: Responds to driver reports of grip problemsweather_information_adjustment
: Adjusts strategy based on weather reportsincident_reaction
: Adapts to incidents reported on track
Gap Analysis Rules System
Examines the gaps between cars to identify strategic opportunities. Key rules include:
-
undercut_opportunity
: Identifies potential for undercutting competitors -
defensive_pit_stop
: Suggests defensive pit strategies when under threat -
strategic_overcut
: Recommends overcut strategies in appropriate conditions
Integrated Strategy Engine
The F1CompleteStrategyEngine
class inherits from all specialized rule systems, creating a comprehensive strategy engine that can apply rules from any domain. This integrated approach allows for holistic race strategy evaluation.
The integrated engine also tracks which specialized systems are active during each analysis:
This tracking helps with conflict resolution and understanding which aspects of the strategy are most influential.
Conflict Resolution
A key feature of the F1CompleteStrategyEngine
is its ability to resolve conflicting recommendations. When multiple rules fire and suggest contradictory actions, the conflict resolution system determines the optimal strategy.
The conflict resolution follows these steps:
-
Group recommendations by driver number
-
For each driver's recommendations:
- Identify conflicting action pairs (e.g., can't both extend stint and pit)
- For each conflict, compare priority and confidence values
- Select the recommendation with higher priority/confidence
- Enhance the explanation of selected recommendations
This approach ensures that drivers receive consistent, logical strategy advice even when multiple rules are triggered.
Data Transformation
Before rules can be applied, raw data must be transformed into fact objects. The transform_all_facts()
function converts various data sources into fact instances:
- Tire prediction data: Converted to
DegradationFact
andTelemetryFact
- Lap time prediction data: Primarily affects
TelemetryFact
- Gap data: Transformed into
GapFact
with consistency metrics - Radio analysis: Converted to
RadioFact
- Race status: Creates
RaceStatusFact
Each transformation handles error conditions and ensures data consistency before creating fact objects.
End-to-End System Operation
The complete operation of the Expert System typically follows this sequence:
The analyze_strategy()
function in scripts/IS_agent/utils/N06_rule_merging.py522-639 orchestrates this process, providing a complete pipeline from raw data to strategic recommendations.
Expert System Implementation and Integration
The Expert System is implemented across several Python files with the core components being:
-
Base Engine and Facts: Defined in scripts/IS_agent/utils/N01_agent_setup.py
-
Specialized Rule Systems: Defined in separate modules:
-
Integrated Engine: Defined in scripts/IS_agent/utils/N06_rule_merging.py
The system is designed for flexibility, allowing it to be used with different data sources and in various contexts. It can be run on historical race data for analysis or in real-time during races to provide ongoing strategic guidance.
Strategic Actions and Prioritization
The Expert System generates recommendations with the following key action types:
Action Type | Description | Source Rule System |
---|---|---|
pit_stop |
Immediate pit stop needed | Degradation/Lap Time |
extend_stint |
Continue on current tires | Degradation |
prepare_pit |
Begin preparations for pit | Degradation |
consider_pit |
Evaluate pit stop options | Degradation |
push_strategy |
Increase pace for advantage | Lap Time |
recovery_push |
Push after traffic | Lap Time |
prioritize_pit |
Urgent pit stop | Radio |
prepare_rain_tires |
Ready for weather change | Radio |
perform_undercut |
Pit early to pass | Gap |
defensive_pit |
Pit to defend position | Gap |
perform_overcut |
Stay out longer to pass | Gap |
Each recommendation includes:
- Action: What to do
- Confidence: How certain the system is (0.0-1.0)
- Explanation: Human-readable justification
- Priority: Urgency level (higher = more urgent)
The get_recommendations()
method sorts recommendations by priority and confidence, ensuring the most important actions are considered first.
Benefits of the Expert System Approach
The Expert System offers several advantages for F1 strategy management:
- Explainability: Rules provide clear explanations for recommendations
- Integration of Diverse Inputs: Combines numerical data with natural language information
- Domain Knowledge Encoding: Captures F1 strategic expertise in explicit rules
- Conflict Management: Resolves contradictory advice through principled prioritization
- Modularity: Specialized rule systems can be developed and maintained independently
These characteristics make the Expert System an ideal complement to the machine learning models, combining data-driven predictions with expert knowledge.
On this page
- Expert System
- Expert System Architecture
- Core Components and Data Flow
- Fact Classes
- Specialized Rule Systems
- Degradation Rules System
- Lap Time Rules System
- Radio Analysis Rules System
- Gap Analysis Rules System
- Integrated Strategy Engine
- Conflict Resolution
- Data Transformation
- End-to-End System Operation
- Expert System Implementation and Integration
- Strategic Actions and Prioritization
- Benefits of the Expert System Approach