🧠 LLM Strategies

MAT-HPO Library includes cutting-edge LLM-enhanced hyperparameter optimization based on the research paper arXiv:2507.13712. Large Language Models provide intelligent, domain-aware parameter suggestions that complement traditional reinforcement learning approaches.

Research-Based: All LLM strategies implement the exact methods described in the academic paper, ensuring scientific rigor and reproducibility.

LLM Strategies

1. Fixed Alpha Strategy

Description: Uses a fixed mixing ratio to combine LLM and RL suggestions.

✅ Best For

  • New users seeking stable results
  • Production environments
  • Known optimal mixing ratios
  • Predictable behavior requirements

⚙️ Key Parameters

  • alpha: Mixing ratio (0.0-1.0)
  • 0.3 = 30% LLM + 70% RL
  • Recommended: 0.2-0.4
python
from MAT_HPO_LIB import EasyHPO

optimizer = EasyHPO(
    task_type="time_series_classification",
    max_trials=30,
    llm_enabled=True,
    llm_strategy="fixed_alpha",
    llm_config={
        'alpha': 0.3,  # 30% LLM + 70% RL
        'model': 'llama3.2:3b'
    }
)

2. Adaptive Strategy (⭐ Recommended)

Description: Monitors RL performance improvement slope and triggers LLM intervention when slope falls below threshold. This is the core method from the research paper.

✅ Best For

  • Research and experimentation
  • Optimal performance pursuit
  • Unknown optimal intervention timing
  • Intelligent auto-adjustment needs

⚙️ Key Parameters

  • performance_threshold: RL slope threshold
  • Recommended: 0.005-0.02
  • Lower = more sensitive/frequent LLM use
  • Higher = more conservative/less LLM use
python
from MAT_HPO_LIB import EasyHPO

optimizer = EasyHPO(
    task_type="time_series_classification",
    max_trials=30,
    llm_enabled=True,
    llm_strategy="adaptive",  #  Intelligent adaptive strategy
    llm_config={
        'performance_threshold': 0.01,  # RL slope threshold
        'min_episodes': 5,              # Start monitoring after 5 episodes
        'cooldown': 3,                  # Cooldown period after LLM intervention
        'model': 'llama3.2:3b'
    }
)

Strategy Comparison

Strategy Predictability Performance Resource Usage Best Use Case
Fixed Alpha High Good Medium Production, Stability
Adaptive Medium Excellent Efficient Research, Optimization

Parameter Tuning Guide

Adaptive Strategy Tuning

python
#  Conservative approach (less LLM usage)
llm_config = {
    'performance_threshold': 0.02,  # Higher threshold
    'min_episodes': 8,               # Wait longer before monitoring
    'cooldown': 5                     # Longer cooldown
}

#  Aggressive approach (more LLM usage)
llm_config = {
    'performance_threshold': 0.005, # Lower threshold
    'min_episodes': 3,               # Start monitoring earlier
    'cooldown': 2                     # Shorter cooldown
}

#  Balanced approach (recommended starting point)
llm_config = {
    'performance_threshold': 0.01,
    'min_episodes': 5,
    'cooldown': 3
}

Fixed Alpha Strategy Tuning

python
# ️ Conservative strategy (20% LLM)
'alpha': 0.2

# ⚖️ Balanced strategy (30% LLM) - Recommended
'alpha': 0.3

#  Aggressive strategy (40% LLM)
'alpha': 0.4

Practical Examples

SPNV2 ECG Classification with LLM

bash
# 🩺 Using fixed mixing ratio for stable ECG classification
python "2. SPL_HPO_Complete.py" --dataset ICBEB --fold 1 --steps 20 --gpu 0 \
  --llm_enabled --llm_strategy fixed_alpha --llm_alpha 0.3

#  Using adaptive strategy for optimal performance
python "2. SPL_HPO_Complete.py" --dataset ICBEB --fold 1 --steps 20 --gpu 0 \
  --llm_enabled --llm_strategy adaptive

Complete Python Example

python
from MAT_HPO_LIB import EasyHPO
import numpy as np

#  Create sample time series data
n_samples, sequence_length = 1000, 100
X = np.random.randn(n_samples, sequence_length, 1)
y = np.random.randint(0, 3, n_samples)

from sklearn.model_selection import train_test_split
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2)

#  Advanced adaptive strategy with custom configuration
advanced_llm_config = {
    'performance_threshold': 0.008,  # Sensitive threshold
    'min_episodes': 3,               # Early monitoring
    'cooldown': 2,                   # Short cooldown
    'model': 'llama3.2:3b',
    'buffer_size': 1000,             # RL parameter
    'learning_rate': 0.001             # RL parameter
}

optimizer = EasyHPO(
    task_type="time_series_classification",
    max_trials=30,
    llm_enabled=True,
    llm_strategy="adaptive",
    llm_config=advanced_llm_config,
    verbose=True  # See LLM decisions in real-time
)

#  Run optimization
results = optimizer.optimize(X_train, y_train, X_val, y_val)

print(f" Best F1 Score: {results['best_performance']['f1']:.4f}")
print(f" LLM Interventions: {results.get('llm_interventions', 0)}")

❓ Troubleshooting & FAQ

Common Issues

Q: Adaptive strategy not triggering LLM?
A: Lower the performance_threshold to 0.005 or reduce min_episodes to 3.
Q: How to verify LLM is working?
A: Set verbose=True and look for "LLM decision" and "RL decision" in the logs.
Q: Which strategy should I choose?
A: Use adaptive for research/optimal performance, fixed_alpha for production/stability.

Performance Monitoring

python
#  Enable detailed logging to monitor LLM behavior
optimizer = EasyHPO(
    task_type="time_series_classification",
    llm_enabled=True,
    llm_strategy="adaptive",
    verbose=True,  #  See real-time decisions
    llm_config={
        'log_decisions': True,  # Log every LLM/RL decision
        'save_history': True    # Save decision history
    }
)

Academic Reference

Citation: This implementation strictly follows the methodology described in research paper arXiv:2507.13712, ensuring academic rigor and reproducibility.

The adaptive trigger mechanism monitors the slope of reinforcement learning performance improvement and intelligently decides when to incorporate Large Language Model suggestions, leading to more efficient and effective hyperparameter optimization.

Next Steps

EasyHPO Interface

Learn the simplified interface for LLM-enhanced optimization

Working Examples

See complete LLM strategy examples in action

Quick Start Guide

Get started with basic HPO before adding LLM enhancement