| |
| """ |
| EvoRM Configuration — Paper Section IV-A |
| ========================================= |
| Centralized hyperparameter configuration for the EvoRM framework. |
| All values follow the paper's experimental setup (Section IV-A). |
| |
| Usage: |
| from evorm_config import EvoRMConfig |
| config = EvoRMConfig() |
| plugin = EvoRMPlugin(client=client, config=config) |
| """ |
|
|
| from dataclasses import dataclass, field, asdict |
| from typing import Dict, Optional |
| import json |
| import os |
|
|
|
|
| @dataclass |
| class EvoRMConfig: |
| """Centralized configuration for all EvoRM components.""" |
| |
| |
| |
| |
| alpha: float = 0.6 |
| beta: float = 0.4 |
| merge_threshold: float = 0.5 |
| K: int = 5 |
| |
| |
| |
| |
| theta_hi: float = 0.7 |
| theta_prune: float = 0.5 |
| theta_gate: float = 0.5 |
| |
| |
| |
| |
| mlp_input_dim: int = 64 |
| mlp_hidden_dims: list = field(default_factory=lambda: [256, 128, 64]) |
| mlp_n_warmup: int = 500 |
| mlp_epochs: int = 50 |
| mlp_batch_size: int = 32 |
| mlp_learning_rate: float = 0.001 |
| |
| |
| |
| |
| decay_lambda: float = 0.01 |
| freshness_threshold: float = 0.1 |
| confidence_threshold: float = 0.2 |
| eval_triggers: int = 10 |
| merge_similarity: float = 0.7 |
| max_rules: int = 10000 |
| evict_percentile: float = 0.1 |
| optimization_interval: int = 300 |
| |
| |
| |
| |
| demb: int = 1024 |
| n_features: int = 8192 |
| |
| |
| |
| |
| model: str = "gpt-3.5-turbo-1106" |
| mlight_temperature: float = 0.1 |
| mheavy_temperature: float = 0.0 |
| api_timeout: int = 30 |
| api_max_retries: int = 3 |
| |
| |
| |
| |
| max_workers: int = 5 |
| ablation_mode: Optional[str] = None |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| persistence_dir: Optional[str] = None |
| |
| def to_dict(self) -> Dict: |
| """Convert to dictionary for serialization.""" |
| d = asdict(self) |
| |
| d['mlp_hidden_dims'] = list(self.mlp_hidden_dims) |
| return d |
| |
| @classmethod |
| def from_dict(cls, d: Dict) -> 'EvoRMConfig': |
| """Create config from dictionary.""" |
| return cls(**{k: v for k, v in d.items() if k in cls.__dataclass_fields__}) |
| |
| def save(self, path: str): |
| """Save config to JSON file.""" |
| os.makedirs(os.path.dirname(path) or '.', exist_ok=True) |
| with open(path, 'w', encoding='utf-8') as f: |
| json.dump(self.to_dict(), f, indent=2, ensure_ascii=False) |
| print(f"Config saved to {path}") |
| |
| @classmethod |
| def load(cls, path: str) -> 'EvoRMConfig': |
| """Load config from JSON file.""" |
| with open(path, 'r', encoding='utf-8') as f: |
| d = json.load(f) |
| return cls.from_dict(d) |
| |
| def __repr__(self) -> str: |
| return (f"EvoRMConfig(alpha={self.alpha}, beta={self.beta}, " |
| f"theta_hi={self.theta_hi}, theta_prune={self.theta_prune}, " |
| f"model={self.model}, ablation={self.ablation_mode})") |
|
|
|
|
| |
| |
| |
|
|
| def get_default_config() -> EvoRMConfig: |
| """Default configuration matching paper's experimental setup.""" |
| return EvoRMConfig() |
|
|
|
|
| def get_ablation_configs() -> Dict[str, EvoRMConfig]: |
| """Get all ablation configurations for Table VI experiments.""" |
| configs = {} |
| |
| |
| configs['full'] = EvoRMConfig() |
| |
| |
| configs['no_stage1'] = EvoRMConfig(ablation_mode='no_stage1') |
| |
| |
| configs['no_maintenance'] = EvoRMConfig(ablation_mode='no_maintenance') |
| |
| |
| configs['no_mlp_gate'] = EvoRMConfig(ablation_mode='no_mlp_gate') |
| |
| |
| configs['no_hypergraph'] = EvoRMConfig(ablation_mode='no_hypergraph') |
| |
| |
| configs['no_mlight'] = EvoRMConfig(ablation_mode='no_mlight') |
| |
| return configs |
|
|
|
|
| def get_efficiency_configs() -> Dict[str, EvoRMConfig]: |
| """Get configurations for efficiency experiments (varying theta_hi).""" |
| configs = {} |
| for theta in [0.5, 0.6, 0.7, 0.8, 0.9]: |
| configs[f'theta_hi_{theta}'] = EvoRMConfig(theta_hi=theta) |
| return configs |
|
|
|
|
| |
| |
| |
|
|
| if __name__ == "__main__": |
| print("EvoRM Configuration - Self Test") |
| print("=" * 60) |
| |
| |
| config = get_default_config() |
| print(f"\n1. Default config: {config}") |
| |
| |
| config.save('/tmp/evorm_test_config.json') |
| loaded = EvoRMConfig.load('/tmp/evorm_test_config.json') |
| print(f"2. Loaded config: {loaded}") |
| print(f" Match: {config.to_dict() == loaded.to_dict()}") |
| |
| |
| print(f"\n3. Ablation configs:") |
| for name, cfg in get_ablation_configs().items(): |
| print(f" {name}: ablation={cfg.ablation_mode}") |
| |
| |
| print(f"\n4. Efficiency configs:") |
| for name, cfg in get_efficiency_configs().items(): |
| print(f" {name}: theta_hi={cfg.theta_hi}") |
| |
| print("\n✅ All config tests passed!") |
|
|