Spaces:
Build error
Build error
| import numpy as np | |
| import random | |
| class RFTAgent: | |
| def __init__(self, phi_init, tier, mutation_rate, drift_rate): | |
| self.phi = phi_init | |
| self.tau_eff = 0.0 # Initial tau_eff, will be updated | |
| self.tier = tier | |
| self.fitness = 0.0 # Initial fitness, will be updated | |
| self.mutation_rate = mutation_rate | |
| self.drift_rate = drift_rate | |
| self.history = { | |
| 'phi': [], | |
| 'tau_eff': [], | |
| 'tier': [], | |
| 'fitness': [] | |
| } | |
| def update_tau(self): | |
| # tau_eff = 0.5*phi + random noise (using uniform for simplicity, can be normal) | |
| self.tau_eff = 0.5 * self.phi + random.uniform(-0.1, 0.1) | |
| def mutate(self): | |
| # phi = phi + random.normal(0, mutation_rate) | |
| self.phi += np.random.normal(0, self.mutation_rate) | |
| def drift(self): | |
| # phi = phi + drift_rate * tau_eff | |
| self.phi += self.drift_rate * self.tau_eff | |
| def update_fitness(self): | |
| # fitness = abs(phi) + abs(tau_eff) + tier*0.1 | |
| self.fitness = abs(self.phi) + abs(self.tau_eff) + self.tier * 0.1 | |
| def step(self): | |
| self.mutate() | |
| self.drift() | |
| self.update_tau() | |
| self.update_fitness() | |
| self._log_history() | |
| def _log_history(self): | |
| self.history['phi'].append(self.phi) | |
| self.history['tau_eff'].append(self.tau_eff) | |
| self.history['tier'].append(self.tier) | |
| self.history['fitness'].append(self.fitness) | |
| print("agent.py created successfully.") | |