RFTSystems commited on
Commit
e142bc5
·
verified ·
1 Parent(s): 0e01585

Upload 7 files

Browse files
Files changed (7) hide show
  1. README.md +51 -209
  2. agent.py +48 -0
  3. app.py +105 -0
  4. requirements.txt +5 -0
  5. simulation.py +55 -0
  6. utils.py +65 -0
  7. visualization.py +65 -0
README.md CHANGED
@@ -1,209 +1,51 @@
1
- ---
2
- title: RFT Agent Simulation Engine
3
- emoji: 🐨
4
- colorFrom: yellow
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 6.6.0
8
- app_file: app.py
9
- pinned: false
10
- license: other
11
- short_description: Multi‑agent drift & stability simulator.
12
- ---
13
-
14
- ---
15
-
16
- RFT Agent Simulation Engine MVP Release
17
-
18
- A symbolic multi‑agent simulation engine built to model drift, stability, coherence, and emergent behaviour in complex systems.
19
- Developed as the first operational software implementation of the Rendered Frame Theory (RFT) agent architecture.
20
-
21
- This MVP provides a clean, modular, reproducible simulation environment that runs entirely in Python and is fully compatible with Google Colab and Hugging Face Spaces.
22
-
23
- ---
24
-
25
- 🚀 Features
26
-
27
- Multi‑Agent Simulation
28
-
29
- Each agent evolves over time through:
30
-
31
- Awareness field updates (Φ)
32
- Collapse‑torque dynamics (τ_eff)
33
- Mutation
34
- Drift
35
- Fitness scoring
36
- • Tier‑independent behaviour
37
-
38
-
39
- System‑Level Metrics
40
-
41
- The engine computes:
42
-
43
- Coherence (average Φ across agents)
44
- Stability (variance of Φ)
45
- Emergent divergence patterns
46
-
47
-
48
- ✔ Full Visualization Suite
49
-
50
- Automatically generates and saves:
51
-
52
- • phi_plot.png
53
- • tau_plot.png
54
- • fitness_plot.png
55
- • coherence_plot.png
56
- • stability_plot.png
57
-
58
-
59
- All plots are high‑resolution (300 dpi).
60
-
61
- ✔ JSON Export
62
-
63
- Final agent states are exported to:
64
-
65
- • final_agent_states.json
66
-
67
-
68
- ✔ One‑Click Packaging
69
-
70
- A built‑in ZIP builder creates:
71
-
72
- • rft_simulation_engine.zip
73
- containing all project files and generated artifacts.
74
-
75
-
76
- ✔ Colab‑Optimized Dev Mode
77
-
78
- When running in Google Colab:
79
-
80
- • Gradio UI is bypassed
81
- • Simulation runs automatically
82
- • Plots display inline
83
- • All files save to disk
84
-
85
-
86
- ---
87
-
88
- 📦 Project Structure
89
-
90
- agent.py # RFTAgent class
91
- simulation.py # RFTSimulation engine
92
- visualization.py # Plotting utilities
93
- utils.py # JSON export + ZIP builder
94
- app.py # Gradio UI + Colab dev mode
95
- test_runner.py # Automated test simulation
96
- requirements.txt # Dependencies
97
- README.md # Documentation
98
-
99
-
100
- ---
101
-
102
- ▶️ Running the Simulation (Colab)
103
-
104
- To run the engine in Google Colab:
105
-
106
- from test_runner import run_test_simulation
107
- run_test_simulation()
108
-
109
-
110
- This will:
111
-
112
- • Run a 3‑agent, 100‑step simulation
113
- • Display all plots inline
114
- • Save all PNGs
115
- • Export final_agent_states.json
116
- • Print file paths
117
-
118
-
119
- ---
120
-
121
- 🌐 Running the Gradio App (Hugging Face Space)
122
-
123
- When deployed on Hugging Face:
124
-
125
- python app.py
126
-
127
-
128
- The UI allows you to configure:
129
-
130
- • Number of agents
131
- • Number of steps
132
- • Mutation rate
133
- • Drift rate
134
- • Random seed
135
-
136
-
137
- And outputs:
138
-
139
- • All plots
140
- • JSON export
141
- • Downloadable results
142
-
143
-
144
- ---
145
-
146
- 🧪 Example Output
147
-
148
- The engine produces:
149
-
150
- • Divergent agent trajectories
151
- • Torque evolution curves
152
- • Fitness progression
153
- • System coherence decay
154
- • Stability variance growth
155
-
156
-
157
- These behaviours emerge naturally from the agent update rules.
158
-
159
- ---
160
-
161
- 📁 Packaging the Project
162
-
163
- To generate a ZIP containing all files and outputs:
164
-
165
- from utils import zip_project
166
- zip_project()
167
-
168
-
169
- This creates:
170
-
171
- • rft_simulation_engine.zip
172
- ready for download or distribution.
173
-
174
-
175
- ---
176
-
177
- 🛠 Requirements
178
-
179
- numpy
180
- matplotlib
181
- gradio
182
-
183
-
184
- ---
185
-
186
- 📣 About This Project
187
-
188
- This MVP demonstrates the first operational implementation of the RFT agent architecture.
189
- It is designed for:
190
-
191
- • AI researchers
192
- • Complex systems modellers
193
- • Simulation engineers
194
- • Worldbuilders
195
- • Anyone exploring emergent behaviour
196
-
197
-
198
- Future versions will introduce:
199
-
200
- • Agent packs
201
- • Mutation packs
202
- • Universe packs
203
- • Codex integration
204
- • Long‑run simulations
205
- • Advanced metrics
206
-
207
-
208
- ---
209
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ # RFT Agent Simulation Engine MVP
2
+
3
+ This project implements a Minimal Viable Product (MVP) of an RFT (Relational Frame Theory) Agent Simulation Engine. It allows for simulating the dynamics of RFT agents, visualizing their behavior, and exporting their states.
4
+
5
+ ## Project Structure
6
+ - `agent.py`: Defines the `RFTAgent` class.
7
+ - `simulation.py`: Defines the `RFTSimulation` class to manage agent interactions over time.
8
+ - `visualization.py`: Contains functions for plotting simulation results using `matplotlib`.
9
+ - `app.py`: Implements a Gradio web interface for running simulations and visualizing results.
10
+ - `utils.py`: Provides utility functions for JSON export and seeding random number generators.
11
+ - `requirements.txt`: Lists all Python package dependencies.
12
+ - `README.md`: This file.
13
+
14
+ ## How to Run in Colab
15
+
16
+ 1. **Open this Colab Notebook:** Ensure you have access to the notebook where these files were generated.
17
+ 2. **Run All Cells:** Execute all cells in the notebook sequentially. This will create all the necessary `.py` files, `requirements.txt`, and `README.md` in your Colab environment.
18
+ 3. **Install Dependencies:** Open a new code cell and run:
19
+ ```bash
20
+ !pip install -r requirements.txt
21
+ ```
22
+ 4. **Run the Gradio App:** To launch the interactive Gradio interface, open a new code cell and run:
23
+ ```python
24
+ import app
25
+ app.iface.launch(debug=True)
26
+ ```
27
+ You will get a public URL (or a local URL if running locally) to access the Gradio interface in your browser.
28
+
29
+ ## How to Deploy to Hugging Face Spaces
30
+
31
+ 1. **Create a New Space:** Go to [Hugging Face Spaces](https://huggingface.co/spaces) and create a new Space. Choose `Gradio` as the SDK.
32
+ 2. **Upload Files:** Upload all the generated files (`agent.py`, `simulation.py`, `visualization.py`, `app.py`, `utils.py`, `requirements.txt`, `README.md`) to your Hugging Face Space repository.
33
+ 3. **Configure `app.py`:** Ensure your `app.py` has the `iface.launch()` call at the end (as provided). Hugging Face Spaces automatically detects and runs Gradio apps.
34
+ 4. **Monitor Build Logs:** Check the build logs in your Space settings for any dependency installation issues or errors.
35
+ 5. **Access the App:** Once successfully built, your Gradio app will be live and accessible via the Space URL.
36
+
37
+ ## Example Usage
38
+
39
+ After running `app.iface.launch()` in Colab, navigate to the provided URL. You will see a Gradio interface where you can adjust parameters:
40
+
41
+ - **Number of Agents:** e.g., 3
42
+ - **Steps:** e.g., 100
43
+ - **Mutation Rate:** e.g., 0.05
44
+ - **Drift Rate:** e.g., 0.02
45
+ - **Random Seed:** e.g., 42
46
+
47
+ Click the 'Submit' button to run the simulation. The interface will display:
48
+
49
+ - Plots for individual agent Phi, Tau Effective, and Fitness over time.
50
+ - Plots for System Coherence (average Phi) and System Stability (variance of Phi) over time.
51
+ - A downloadable JSON file containing the final states of all agents.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
agent.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import random
3
+
4
+ class RFTAgent:
5
+ def __init__(self, phi_init, tier, mutation_rate, drift_rate):
6
+ self.phi = phi_init
7
+ self.tau_eff = 0.0 # Initial tau_eff, will be updated
8
+ self.tier = tier
9
+ self.fitness = 0.0 # Initial fitness, will be updated
10
+ self.mutation_rate = mutation_rate
11
+ self.drift_rate = drift_rate
12
+ self.history = {
13
+ 'phi': [],
14
+ 'tau_eff': [],
15
+ 'tier': [],
16
+ 'fitness': []
17
+ }
18
+
19
+ def update_tau(self):
20
+ # tau_eff = 0.5*phi + random noise (using uniform for simplicity, can be normal)
21
+ self.tau_eff = 0.5 * self.phi + random.uniform(-0.1, 0.1)
22
+
23
+ def mutate(self):
24
+ # phi = phi + random.normal(0, mutation_rate)
25
+ self.phi += np.random.normal(0, self.mutation_rate)
26
+
27
+ def drift(self):
28
+ # phi = phi + drift_rate * tau_eff
29
+ self.phi += self.drift_rate * self.tau_eff
30
+
31
+ def update_fitness(self):
32
+ # fitness = abs(phi) + abs(tau_eff) + tier*0.1
33
+ self.fitness = abs(self.phi) + abs(self.tau_eff) + self.tier * 0.1
34
+
35
+ def step(self):
36
+ self.mutate()
37
+ self.drift()
38
+ self.update_tau()
39
+ self.update_fitness()
40
+ self._log_history()
41
+
42
+ def _log_history(self):
43
+ self.history['phi'].append(self.phi)
44
+ self.history['tau_eff'].append(self.tau_eff)
45
+ self.history['tier'].append(self.tier)
46
+ self.history['fitness'].append(self.fitness)
47
+
48
+ print("agent.py created successfully.")
app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import os
4
+ import matplotlib.pyplot as plt # Kept for potential future gr.Plot use or if figures are handled directly
5
+ from simulation import RFTSimulation
6
+ from utils import export_json, seed_everything
7
+ from IPython.display import Image, display # For Colab dev mode inline image display
8
+
9
+ # Helper function to run simulation and generate plots/export data
10
+ def run_simulation_and_plot(num_agents, steps, mutation_rate, drift_rate, seed=None):
11
+ if seed is not None:
12
+ seed_everything(seed)
13
+
14
+ # Instantiate simulation with save_plots=True, so it saves plots during its run() method
15
+ simulation = RFTSimulation(num_agents, steps, mutation_rate, drift_rate, save_plots=True)
16
+
17
+ # Run the simulation. The internal run method will save plots if save_plots=True.
18
+ # It returns all_agents_history, coherence_list, stability_list.
19
+ all_agents_history, coherence_list, stability_list = simulation.run()
20
+
21
+ # Prepare final agent states for JSON export
22
+ final_agent_states = []
23
+ for i, agent in enumerate(simulation.agents):
24
+ final_agent_states.append({
25
+ 'id': i + 1,
26
+ 'phi': agent.phi,
27
+ 'tau_eff': agent.tau_eff,
28
+ 'tier': agent.tier,
29
+ 'fitness': agent.fitness
30
+ })
31
+
32
+ # Export JSON
33
+ json_filename = "final_agent_states.json"
34
+ export_json(final_agent_states, json_filename)
35
+
36
+ # Return filenames of the generated plots and the JSON for Gradio or dev mode display
37
+ plot_filenames = [
38
+ 'phi_plot.png',
39
+ 'tau_plot.png',
40
+ 'fitness_plot.png',
41
+ 'coherence_plot.png',
42
+ 'stability_plot.png'
43
+ ]
44
+
45
+ return (*plot_filenames, json_filename)
46
+
47
+ # Gradio Interface setup
48
+ iface = gr.Interface(
49
+ fn=run_simulation_and_plot,
50
+ inputs=[
51
+ gr.Slider(1, 10, value=3, step=1, label="Number of Agents"),
52
+ gr.Slider(10, 500, value=100, step=10, label="Steps"),
53
+ gr.Slider(0.01, 0.5, value=0.05, step=0.01, label="Mutation Rate"),
54
+ gr.Slider(0.01, 0.5, value=0.02, step=0.01, label="Drift Rate"),
55
+ gr.Number(value=42, label="Random Seed (optional, leave empty for random)") # Clarified label
56
+ ],
57
+ outputs=[
58
+ gr.Image(label="Phi Plot"), # Changed to gr.Image to display saved PNGs
59
+ gr.Image(label="Tau Effective Plot"),
60
+ gr.Image(label="Fitness Plot"),
61
+ gr.Image(label="Coherence Plot"),
62
+ gr.Image(label="Stability Plot"),
63
+ gr.File(label="Exported Final Agent States (JSON)")
64
+ ],
65
+ title="RFT Agent Simulation Engine MVP",
66
+ description="Simulate RFT Agents and visualize their dynamics."
67
+ )
68
+
69
+ # Colab-friendly "dev mode" or Gradio launch logic
70
+ # Check if running in Colab environment (simple heuristic)
71
+ IN_COLAB = 'COLAB_GPU' in os.environ or 'Google' in os.environ.get('COLAB_CLOUD_PLATFORM', '')
72
+
73
+ if IN_COLAB:
74
+ print("Running in Colab development mode (skipping Gradio launch).")
75
+ # Run the test simulation logic as per requirements
76
+ num_agents = 3
77
+ steps = 100
78
+ mutation_rate = 0.05
79
+ drift_rate = 0.02
80
+ seed = 42
81
+
82
+ print("\n--- Running Test Simulation in Dev Mode ---")
83
+ # Call the core simulation function. It will save plots and JSON.
84
+ plot_files_and_json_file = run_simulation_and_plot(num_agents, steps, mutation_rate, drift_rate, seed)
85
+ plot_files = plot_files_and_json_file[:-1]
86
+ json_file = plot_files_and_json_file[-1]
87
+
88
+ print("\nSimulation complete. Displaying plots and exported JSON path:")
89
+ for plot_file in plot_files:
90
+ print(f" - {os.path.abspath(plot_file)}")
91
+ if os.path.exists(plot_file):
92
+ display(Image(filename=plot_file)) # Display inline in Colab
93
+ else:
94
+ print(f"Warning: Plot file {plot_file} not found for inline display.")
95
+
96
+ print(f" - {os.path.abspath(json_file)}")
97
+ print(f"Final agent states exported to {json_file}")
98
+ print("\n--- End of Test Simulation in Dev Mode ---")
99
+
100
+ else:
101
+ print("Running Gradio interface. Call iface.launch() to start it.")
102
+ # For local development, uncomment this to launch Gradio:
103
+ # iface.launch()
104
+
105
+ print("app.py updated successfully.")
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ matplotlib
2
+ numpy
3
+ gradio
4
+
5
+ print("requirements.txt created successfully.")
simulation.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ from agent import RFTAgent
3
+ import visualization # Added import for visualization
4
+
5
+ class RFTSimulation:
6
+ def __init__(self, num_agents, steps, mutation_rate, drift_rate, save_plots=False): # Added save_plots
7
+ self.agents = []
8
+ self.steps = steps
9
+ self.mutation_rate = mutation_rate
10
+ self.drift_rate = drift_rate
11
+ self.save_plots = save_plots # Stored save_plots
12
+ self.coherence_list = [] # Initialized coherence_list
13
+ self.stability_list = [] # Initialized stability_list
14
+
15
+ for _ in range(num_agents):
16
+ phi_init = np.random.uniform(-1, 1)
17
+ tier = np.random.randint(1, 5)
18
+ agent = RFTAgent(phi_init, tier, mutation_rate, drift_rate)
19
+ self.agents.append(agent)
20
+
21
+ def run(self):
22
+ for _ in range(self.steps):
23
+ for agent in self.agents:
24
+ agent.step()
25
+ # Append current coherence and stability after all agents have stepped
26
+ self.coherence_list.append(self.compute_coherence())
27
+ self.stability_list.append(self.compute_stability())
28
+
29
+ # Conditional plot saving
30
+ if self.save_plots:
31
+ all_agents_history = self.get_history()
32
+ visualization.plot_phi(all_agents_history, filename='phi_plot.png')
33
+ visualization.plot_tau(all_agents_history, filename='tau_plot.png')
34
+ visualization.plot_fitness(all_agents_history, filename='fitness_plot.png')
35
+ visualization.plot_coherence(self.coherence_list, filename='coherence_plot.png')
36
+ visualization.plot_stability(self.stability_list, filename='stability_plot.png')
37
+
38
+ return (self.get_history(), self.coherence_list, self.stability_list) # Modified return value
39
+
40
+ def get_history(self):
41
+ return [agent.history for agent in self.agents]
42
+
43
+ def compute_coherence(self):
44
+ # Average phi across agents at the current step
45
+ if not self.agents:
46
+ return 0.0
47
+ return np.mean([agent.phi for agent in self.agents])
48
+
49
+ def compute_stability(self):
50
+ # Variance of phi across agents at the current step
51
+ if not self.agents:
52
+ return 0.0
53
+ return np.var([agent.phi for agent in self.agents])
54
+
55
+ print("simulation.py updated successfully.")
utils.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import numpy as np
3
+ import random
4
+ import os
5
+ import zipfile
6
+
7
+ def export_json(data, filename):
8
+ with open(filename, 'w') as f:
9
+ json.dump(data, f, indent=4)
10
+ print(f"Data exported to {filename}")
11
+
12
+ def seed_everything(seed):
13
+ random.seed(seed)
14
+ np.random.seed(seed)
15
+ print(f"Random seeds set to {seed}")
16
+
17
+ def zip_project(output_name="rft_simulation_engine.zip"):
18
+ files_to_zip = [
19
+ 'agent.py',
20
+ 'simulation.py',
21
+ 'visualization.py',
22
+ 'app.py',
23
+ 'utils.py',
24
+ 'requirements.txt',
25
+ 'README.md',
26
+ 'test_runner.py',
27
+ 'final_agent_states.json',
28
+ 'phi_plot.png',
29
+ 'tau_plot.png',
30
+ 'fitness_plot.png',
31
+ 'coherence_plot.png',
32
+ 'stability_plot.png'
33
+ ]
34
+
35
+ with zipfile.ZipFile(output_name, 'w') as zf:
36
+ for file in files_to_zip:
37
+ if os.path.exists(file):
38
+ zf.write(file)
39
+ print(f"Added {file} to {output_name}")
40
+ else:
41
+ print(f"Warning: {file} not found, skipping.")
42
+ print(f"Successfully created {output_name} containing all specified files.")
43
+
44
+ def zip_huggingface_repo(output_name='rft_hf_repo.zip'):
45
+ """Creates a zip archive containing only the core project files for Hugging Face deployment."""
46
+ files_to_include = [
47
+ 'agent.py',
48
+ 'simulation.py',
49
+ 'visualization.py',
50
+ 'app.py',
51
+ 'utils.py',
52
+ 'requirements.txt',
53
+ 'README.md'
54
+ ]
55
+
56
+ with zipfile.ZipFile(output_name, 'w') as zf:
57
+ for file in files_to_include:
58
+ if os.path.exists(file):
59
+ zf.write(file)
60
+ print(f"Added {file} to {output_name}")
61
+ else:
62
+ print(f"Warning: {file} not found, skipping for Hugging Face repo zip.")
63
+ print(f"Successfully created Hugging Face repository zip: {output_name}")
64
+
65
+ print("utils.py updated successfully with new zip_huggingface_repo function.")
visualization.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import matplotlib.pyplot as plt
2
+ import numpy as np
3
+
4
+ def plot_phi(all_agents_history, filename=None):
5
+ plt.figure(figsize=(10, 6))
6
+ for i, agent_history in enumerate(all_agents_history):
7
+ plt.plot(agent_history['phi'], label=f'Agent {i+1} Phi')
8
+ plt.xlabel('Step')
9
+ plt.ylabel('Phi')
10
+ plt.title('Agent Phi Over Time')
11
+ plt.legend()
12
+ plt.grid(True)
13
+ if filename is not None:
14
+ plt.savefig(filename, dpi=300, bbox_inches='tight')
15
+ plt.close()
16
+
17
+ def plot_tau(all_agents_history, filename=None):
18
+ plt.figure(figsize=(10, 6))
19
+ for i, agent_history in enumerate(all_agents_history):
20
+ plt.plot(agent_history['tau_eff'], label=f'Agent {i+1} Tau Eff')
21
+ plt.xlabel('Step')
22
+ plt.ylabel('Tau Effective')
23
+ plt.title('Agent Tau Effective Over Time')
24
+ plt.legend()
25
+ plt.grid(True)
26
+ if filename is not None:
27
+ plt.savefig(filename, dpi=300, bbox_inches='tight')
28
+ plt.close()
29
+
30
+ def plot_fitness(all_agents_history, filename=None):
31
+ plt.figure(figsize=(10, 6))
32
+ for i, agent_history in enumerate(all_agents_history):
33
+ plt.plot(agent_history['fitness'], label=f'Agent {i+1} Fitness')
34
+ plt.xlabel('Step')
35
+ plt.ylabel('Fitness')
36
+ plt.title('Agent Fitness Over Time')
37
+ plt.legend()
38
+ plt.grid(True)
39
+ if filename is not None:
40
+ plt.savefig(filename, dpi=300, bbox_inches='tight')
41
+ plt.close()
42
+
43
+ def plot_coherence(coherence_list, filename=None):
44
+ plt.figure(figsize=(10, 6))
45
+ plt.plot(coherence_list)
46
+ plt.xlabel('Step')
47
+ plt.ylabel('Average Phi')
48
+ plt.title('System Coherence Over Time (Average Phi)')
49
+ plt.grid(True)
50
+ if filename is not None:
51
+ plt.savefig(filename, dpi=300, bbox_inches='tight')
52
+ plt.close()
53
+
54
+ def plot_stability(stability_list, filename=None):
55
+ plt.figure(figsize=(10, 6))
56
+ plt.plot(stability_list)
57
+ plt.xlabel('Step')
58
+ plt.ylabel('Variance of Phi')
59
+ plt.title('System Stability Over Time (Variance of Phi)')
60
+ plt.grid(True)
61
+ if filename is not None:
62
+ plt.savefig(filename, dpi=300, bbox_inches='tight')
63
+ plt.close()
64
+
65
+ print("visualization.py updated successfully.")