-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchitecture.qmd
More file actions
275 lines (209 loc) · 7.97 KB
/
Copy patharchitecture.qmd
File metadata and controls
275 lines (209 loc) · 7.97 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
---
title: "System Architecture"
subtitle: "Three-Way Coupling: Experiment ↔ LLM ↔ Memory"
---
## Overview
The NeuralGraph system implements a closed-loop scientific exploration framework with three tightly coupled components:
```{mermaid}
flowchart TB
subgraph EXP[EXPERIMENT]
E1[Data Generation]
E2[GNN Training]
E3[Evaluation]
E4[Visualization]
end
subgraph LLM[LLM Agent]
L1[Read Inputs]
L2[Analyze Results]
L3[Select Strategy]
L4[Edit Config]
end
subgraph MEM[MEMORY]
M1[Working Memory<br/>memory.md]
M2[Full Log<br/>analysis.md]
end
E3 -->|activity.png<br/>analysis.log<br/>ucb_scores.txt| L1
L4 -->|config.yaml| E1
L2 <-->|read/write| M1
L2 -->|append| M2
style EXP fill:#e3f2fd
style LLM fill:#fff3e0
style MEM fill:#e8f5e9
```
## File Exchange Protocol
The system communicates through a well-defined set of files:
### Experiment → LLM
| File | Format | Contents |
|------|--------|----------|
| `activity.png` | PNG | Neural activity visualization showing simulated dynamics |
| `analysis.log` | Text | Key metrics: connectivity_R², test_R², activity rank, loss |
| `ucb_scores.txt` | Text | UCB exploration tree with node scores and parents |
### LLM → Experiment
| File | Format | Contents |
|------|--------|----------|
| `config/{task}.yaml` | YAML | Updated hyperparameters for next iteration |
### LLM ↔ Memory
| File | Direction | Contents |
|------|-----------|----------|
| `{task}_memory.md` | Read/Write | Working memory: established principles, current block progress |
| `{task}_analysis.md` | Append-only | Full experiment log with iteration details |
| `{task}_reasoning.log` | Append-only | Claude's reasoning trace (for debugging) |
## Component Details
### 1. Experiment Module
The experiment module handles all computational work:
::: {.panel-tabset}
#### Data Generation
```python
# Simulate neural activity with given parameters
data_generate(
config=config,
visualize=True,
device=device
)
```
Generates synthetic neural activity using configurable dynamics:
- **Connectivity types**: Chaotic, low-rank, Dale's law, sparse
- **Network parameters**: n_neurons, n_types, spectral_radius
- **Noise models**: Clean, low, medium, high
#### GNN Training
```python
# Train GNN to recover connectivity matrix W
data_train(
config=config,
n_epochs=config.training.n_epochs,
device=device
)
```
Trains Signal Propagation GNN with:
- Learnable connectivity matrix W
- Embedding vectors for neuron types
- L1 regularization for sparsity
#### Evaluation
```python
# Test connectivity recovery
data_test(
config=config,
best_model=model_path,
device=device
)
```
Outputs key metrics:
- **connectivity_R²**: Correlation between learned and true W
- **test_R²**: Activity prediction accuracy
- **cluster_accuracy**: Neuron type classification (if n_types > 1)
- **activity rank**: SVD rank at 99% variance
:::
### 2. LLM Agent
The LLM (Claude) acts as the scientific reasoning engine:
::: {.callout-note}
## Capabilities
- **Read**: Instruction files, memory, metrics, visualizations
- **Analyze**: Pattern recognition, hypothesis formation
- **Decide**: Strategy selection based on UCB scores
- **Edit**: Config files, memory updates
:::
#### Decision Framework
```
┌─────────────────────────────────────────────────┐
│ 1. READ INPUTS │
│ - instruction.md (exploration protocol) │
│ - memory.md (accumulated knowledge) │
│ - analysis.log (current metrics) │
│ - ucb_scores.txt (exploration tree) │
│ - activity.png (visualization) │
└──────────────────────┬──────────────────────────┘
│
v
┌─────────────────────────────────────────────────┐
│ 2. ANALYZE RESULTS │
│ - Classify: converged / partial / failed │
│ - Compare to predictions │
│ - Identify patterns │
└──────────────────────┬──────────────────────────┘
│
v
┌─────────────────────────────────────────────────┐
│ 3. SELECT STRATEGY │
│ - exploit: follow highest UCB │
│ - explore: try new parameter dimension │
│ - boundary: probe failure limits │
│ - robustness: re-test best configs │
└──────────────────────┬──────────────────────────┘
│
v
┌─────────────────────────────────────────────────┐
│ 4. MUTATE CONFIG │
│ - Change ONE parameter │
│ - Log mutation in analysis.md │
│ - Update memory.md │
└─────────────────────────────────────────────────┘
```
### 3. Memory System
The memory system maintains state across iterations:
#### Working Memory (`memory.md`)
Structured document with sections:
```markdown
## Knowledge Base
### Established Principles
- [Confirmed findings from 3+ tests]
### Open Questions
- [Hypotheses under investigation]
### Failed Configurations
- [What to avoid]
## Current Block
### Block Info
- Regime: [current simulation settings]
- Iterations: N to M
### Iterations This Block
[Logs for current block]
### Emerging Observations
[Patterns noticed during exploration]
```
#### Analysis Log (`analysis.md`)
Append-only log with strict format:
```markdown
## Iter N: [converged/partial/failed]
Node: id=X, parent=Y
Strategy: [exploit/explore/boundary/...]
Config: [key parameters]
Metrics: connectivity_R²=X.XX, test_R²=X.XX, activity_rank=XX
Observation: [what was learned]
Mutation: [param]: [old] -> [new]
Next: parent=Z
```
## UCB Exploration Tree
The system uses Upper Confidence Bound (UCB) for exploration:
$$\text{UCB}(n) = \bar{R}(n) + c \sqrt{\frac{\ln N}{n_{\text{visits}}}}$$
Where:
- $\bar{R}(n)$ = average reward (connectivity_R²) at node n
- $N$ = total iterations in current block
- $n_{\text{visits}}$ = visits to node n
- $c$ = exploration constant (default 1.414)
```{mermaid}
graph TD
A[Root: lr_W=5E-3] --> B[lr_W=1E-2<br/>R²=0.99]
A --> C[lr_W=2E-3<br/>R²=0.97]
B --> D[L1=1E-3<br/>R²=0.85]
B --> E[L1=1E-4<br/>R²=0.99]
C --> F[lr=1E-3<br/>R²=0.95]
style E fill:#90EE90
style D fill:#FFB6C1
```
## Block Structure
Exploration is organized into blocks of `n_iter_block` iterations:
| Scope | Duration | Allowed Changes |
|-------|----------|-----------------|
| **Iteration** | 1 cycle | Training parameters only |
| **Block** | 8 iterations | Training + simulation parameters |
::: {.callout-warning}
## Block Boundary Rules
At the end of each block:
1. Clear UCB scores (fresh exploration tree)
2. LLM may modify instruction file
3. LLM selects next simulation regime
4. Memory snapshot saved for recovery
:::
## Next Steps
- [Experiment Loop Details](experiment-loop.qmd) - Detailed code walkthrough
- [Epistemic Analysis](epistemic-analysis.qmd) - Reasoning mode taxonomy
- [Results](results.qmd) - Findings from signal_landscape experiment