File size: 1,521 Bytes
e142bc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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.")