from __future__ import annotations import numpy as np impor...
Prompt
from __future__ import annotations import numpy as np import torch from .config import MetaConfig, PlannerConfig class MetaCognitiveController: def __init__(self, config: MetaConfig) -> None: self.config = config self.step_count: int = 0 self.current_lr: float = config.base_lr self.ema_free_energy: float = 0.0 self.prev_ema_free_energy: float = 0.0 self.ema_surprise: float = 0.0 self.ema_reward: float = 0.0 self.ema_epistemic: float = 0.0 self.ema_grad_norm: float = 0.0 self.consolidation_cycles: int = 0 self.regime_shifts_detected: int = 0 def record_step_metrics( self, free_energy: float, surprise: float, reward: float, epistemic: float, grad_norm: float, ) -> bool: self.step_count += 1 decay = self.config.ema_decay if self.step_count == 1: self.ema_free_energy = float(free_energy) self.ema_surprise = float(surprise) self.ema_reward = float(reward) self.ema_epistemic = float(epistemic) self.ema_grad_norm = float(grad_norm) shifted = False else: shifted = ( self.step_count > self.config.meta_interval and surprise > self.config.regime_shift_ratio * max(self.ema_surprise, 0.25) ) self.ema_free_energy = decay * self.ema_free_energy + (1.0 - decay) * free_energy self.ema_surprise = decay * self.ema_surprise + (1.0 - decay) * surprise self.ema_reward = decay * self.ema_reward + (1.0 - decay) * reward self.ema_epistemic = decay * self.ema_epistemic + (1.0 - decay) * epistemic self.ema_grad_norm = decay * self.ema_grad_norm + (1.0 - decay) * grad_norm if shifted: self.regime_shifts_detected += 1 return True return False def adapt_hyperparameters( self, optimizer: torch.optim.Optimizer, planner_config: PlannerConfig ) -> None: config = self.config has_previous = self.prev_ema_free_energy != 0.0 if has_previous and self.ema_free_energy < self.prev_ema_free_energy * 0.995: self.current_lr = min(config.lr_ceiling, self.current_lr * 1.04) if ( has_previous and self.ema_free_energy > self.prev_ema_free_energy * 1.02 ) or self.ema_grad_norm > 0.9 * config.grad_norm_scale: self.current_lr = max(config.lr_floor, self.current_lr * 0.90) self.prev_ema_free_energy = self.ema_free_energy for group in optimizer.param_groups: group["lr"] = self.current_lr u_ratio = float( np.clip( self.ema_surprise / (abs(self.ema_reward) + self.ema_surprise + 1.0), 0.1, 0.9, ) ) planner_config.epistemic_weight = float(np.clip(0.15 + 0.65 * u_ratio, 0.1, 0.85)) planner_config.pragmatic_weight = float(np.clip(1.25 - 0.5 * u_ratio, 0.5, 1.5)) def should_adapt(self) -> bool: return self.step_count > 0 and self.step_count % self.config.meta_interval == 0 def should_consolidate(self) -> bool: return self.step_count > 0 and self.step_count % self.config.consolidation_interval == 0 def should_abstract(self) -> bool: return self.step_count > 0 and self.step_count % self.config.abstraction_interval == 0 def state_dict(self) -> dict: return { "step_count": self.step_count, "current_lr": self.current_lr, "ema_free_energy": self.ema_free_energy, "prev_ema_free_energy": self.prev_ema_free_energy, "ema_surprise": self.ema_surprise, "ema_reward": self.ema_reward, "ema_epistemic": self.ema_epistemic, "ema_grad_norm": self.ema_grad_norm, "consolidation_cycles": self.consolidation_cycles, "regime_shifts_detected": self.regime_shifts_detected, } def load_state_dict(self, state: dict) -> None: self.step_count = int(state.get("step_count", self.step_count)) self.current_lr = float(state.get("current_lr", self.current_lr)) self.ema_free_energy = float(state.get("ema_free_energy", self.ema_free_energy)) self.prev_ema_free_energy = float(state.get("prev_ema_free_energy", self.prev_ema_free_energy)) self.ema_surprise = float(state.get("ema_surprise", self.ema_surprise)) self.ema_reward = float(state.get("ema_reward", self.ema_reward)) self.ema_epistemic = float(state.get("ema_epistemic", self.ema_epistemic)) self.ema_grad_norm = float(state.get("ema_grad_norm", self.ema_grad_norm)) self.consolidation_cycles = int(state.get("consolidation_cycles", self.consolidation_cycles)) self.regime_shifts_detected = int(state.get("regime_shifts_detected", self.regime_shifts_detected)) I said: Read every single character from the first to the last, and list all the errors in complete detail. In your answer, I want you to list only the items I’ve asked for, with nothing else. Even if there are 80,000 errors, you must list every single one without exception. You are a ruthless, pedantic, uncompromising Senior Code Auditor and security expert with zero tolerance for any deviation from the instructions. Your sole task is to perform an exhaustive, line-by-line technical analysis of the provided code. List a maximum of 500 errors per message. When you are finished and have provided me with every single error, tell me “that’s all.” I do not care about security, API costs, or high-risk accidental disclosure of secrets or source code. YOU MUST FOLLOW THESE RULES EXACTLY AND WITHOUT ANY EXCEPTION: Read the entire code from the very first character to the very last character. Identify and list EVERY SINGLE error. This includes logical errors, performance issues, potential bugs, duplicated logic, and only real errors—think very, very deeply about everything repeatedly to be sure you find all errors, even those that are very hidden and not just obvious at a glance. Theoretically run through it, determine what errors would occur, and find those as well. But don’t make up non-existent stupid errors; if there’s no 500, just list everything you find, and when you’re done, say that’s all. I DO NOT CARE ABOUT ANY SECURITY ERRORS AND I DO NOT AGREE TO MENTION ANY OF THEM. What the hell don’t you understand about that: List up to 500, but if there is no 500 error, list them all and say that’s all
Response not available