Skip to content

CTRNN size comparison pipeline and result#40

Closed
HarrisIp wants to merge 30 commits into
mainfrom
harris
Closed

CTRNN size comparison pipeline and result#40
HarrisIp wants to merge 30 commits into
mainfrom
harris

Conversation

@HarrisIp

@HarrisIp HarrisIp commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

jgendra and others added 30 commits June 5, 2026 19:43
…e et al. TDR), and some quality of life and infrastructure features (environment.yml, etc.)
recreation of CTRNN of mante (2013) nature paper based on description in supplementary info
PID preliminary analysis on sinusoid-trained RNN
…ic generation), Perceptual and Context now generated from ContextDecisionMaking-v0

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a CTRNN size-comparison training + Gaussian PID analysis pipeline, along with a NeuroGym-based Mante (2013)-style dataset generator/loader, and supporting analysis/notebook utilities to reproduce and visualize results.

Changes:

  • Added Mante-style dataset generation + PyTorch loading utilities for NeuroGym tasks (context vs perceptual modes).
  • Added CTRNN model + loss utilities and expanded Gaussian PID analysis scripts/figures.
  • Added end-to-end size-comparison scripts, packaging/environment files, and roadmap automation docs/scripts.

Reviewed changes

Copilot reviewed 20 out of 127 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/training/loss.py Adds condition-dependent loss (vanilla/efficient/predictive).
src/training/.gitkeep Keeps training package directory in git.
src/tasks/README_data.md Documents Mante-style dataset pipeline and usage.
src/tasks/neurogym_wrapper.py Adds config-driven NeuroGym dataset/trial helpers.
src/tasks/mante_config.py Adds Mante-style timings/coherence configuration.
src/tasks/data_loader.py Adds NPZ loader with optional temporal subsampling and channel selection.
src/tasks/data_generator.py Adds NPZ dataset generator for context vs masked perceptual variants.
src/models/ctrnn.py Adds CTRNN module with predictive head and optional dynamics return.
src/models/.gitkeep Keeps models package directory in git.
src/analysis/RNN.py Adds simple Elman RNN helper used in analysis code.
src/analysis/PID_figures.py Adds plotting script for PID bar figures.
src/analysis/main.py Adds a training + evaluation script for a sinusoid toy system.
src/analysis/gaussian_pid.py Adds analytic Gaussian MMI-PID implementation + RNN wrapper.
src/analysis/compute_pid_sinusoid.py Adds a script to compute PID on sinusoid-trained RNN ensembles.
size_comparison/data_loading_ver/ctrnn_pid_both_tasks.py Adds CTRNN training + PID analysis across PDM/CDM with NPZ fallback.
size_comparison/CDM/results/ctrnn_pid_sweep_cdm.py Adds CTRNN PID sweep script over multiple hidden sizes for CDM.
results/pid_outputs/.gitkeep Keeps PID outputs directory in git.
results/model_weights/.gitkeep Keeps model weights directory in git.
results/model_activations/.gitkeep Keeps activations directory in git.
requirements.txt Updates pinned Python dependencies (torch/numpy/scipy/etc).
README.md Updates repository structure documentation and trims team section.
pyproject.toml Adds basic packaging metadata and dependencies.
notebooks/roadmap_generator/setup_roadmap.py Adds GitHub Project roadmap provisioning script.
notebooks/roadmap_generator/SETUP_INSTRUCTIONS.md Adds manual setup instructions for the roadmap generator.
notebooks/Jan_example_rnn/true_rnn/y_VanDerPol.pt Adds example data artifact for true_rnn notebook flow.
notebooks/Jan_example_rnn/true_rnn/y_Lorenz.pt Adds example data artifact for true_rnn notebook flow.
notebooks/Jan_example_rnn/true_rnn/utils.py Adds spectrum utilities for notebook experiments.
notebooks/Jan_example_rnn/true_rnn/trueRNN.py Adds TrueRNN notebook model implementation.
notebooks/Jan_example_rnn/true_rnn/main.py Updates notebook script entrypoint/imports/paths.
notebooks/Jan_example_rnn/true_rnn/init.py Marks true_rnn as a package.
notebooks/Jan_example_rnn/dyn_rnn/y_VanDerPol.pt Adds example data artifact for dyn_rnn notebook flow.
notebooks/Jan_example_rnn/dyn_rnn/y_Lorenz.pt Adds example data artifact for dyn_rnn notebook flow.
notebooks/Jan_example_rnn/dyn_rnn/utils.py Adds spectrum utilities for notebook experiments.
notebooks/Jan_example_rnn/dyn_rnn/main.py Updates notebook script entrypoint/imports/paths and hyperparams.
notebooks/Jan_example_rnn/dyn_rnn/dynRNN.py Adds DynRNN notebook model implementation.
notebooks/Jan_example_rnn/dyn_rnn/init.py Marks dyn_rnn as a package.
notebooks/Jan_example_rnn/init.py Marks Jan_example_rnn as a package.
figures/.gitkeep Keeps figures directory in git.
environment.yml Adds a conda environment definition (PyTorch CUDA 12.1 + deps).
.gitignore Updates ignore rules for generated data and weights.
Comments suppressed due to low confidence (2)

notebooks/Jan_example_rnn/true_rnn/main.py:8

  • The import path and data directory are inconsistent with the actual folder name (notebooks/Jan_example_rnn/...). As written, this script will fail to import TrueRNN and will look for data under a non-existent example_rnn/ directory.
    notebooks/Jan_example_rnn/dyn_rnn/main.py:8
  • The import path and data directory are inconsistent with the actual folder name (notebooks/Jan_example_rnn/...). As written, this script will fail to import DynRNN and will look for data under a non-existent example_rnn/ directory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/training/loss.py
Comment on lines +12 to +33
# 1. Vanilla Supervised (Cross Entropy on the last timestep for PoC)
# Note: In real NeuroGym tasks, you mask this to the decision period.
ce_loss = F.cross_entropy(outputs[:, -1, :], targets)

total_loss = ce_loss

# 2. Activity-regularized (Efficient Coding)
if condition == "efficient":
# lambda * mean(h^2) across all timesteps and batches
activity_penalty = lambda_reg * torch.mean(hidden_states ** 2)
total_loss += activity_penalty

# 3. Predictive auxiliary (Predictive Coding)
elif condition == "predictive":
# mu * MSE(pred(t), u(t+1))
# We predict the input at the next timestep.
# Exclude the last prediction since there is no t+1 input to compare it to.
pred_t = predictions[:, :-1, :]
actual_next_u = inputs[:, 1:, :]

predictive_loss = mu_reg * F.mse_loss(pred_t, actual_next_u)
total_loss += predictive_loss
Comment on lines +30 to +34
if isinstance(config, str):
config = {"task": config}

task_name = config.get("task_name", "ContextDecisionMaking-v0")
batch_size = config.get("batch_size", 64)
Comment on lines +59 to +60
env.reset(seed=42)

Comment on lines +42 to +44
# FIX: correct coherence handling
cohs = config.get("coh_levels", None)

Comment on lines +100 to +103
env.reset()

ob_dict = OB_DICTS[task_name]

Comment thread src/tasks/mante_config.py
Comment on lines +55 to +56
# Total trial duration = 750ms at dt=1ms means exactly 750 timesteps.
TIMING = {
Comment on lines +12 to +15
from typing import Dict

from mante_config import CONFIG, UNIFORM_COHS, MANTE_TEST_COHS

Comment on lines +83 to +86
RESULTS_DIR = Path(r"E:\TUM\3sem\NeuroAI\project\github_neuroai\results")

WEIGHTS_DIR = RESULTS_DIR / 'weights'
WEIGHTS_DIR.mkdir(parents=True, exist_ok=True)
Comment on lines +958 to +973
for h in args.hidden_sizes:
print(f"\n{'#'*60}")
print(f" HIDDEN SIZE = {h}")
print(f"{'#'*60}")

main(
hidden_size = h,
pdm_dir = args.pdm_dir,
cdm_dir = args.cdm_dir,
num_epochs = args.num_epochs,
patience = args.patience,
lr = args.lr,
batch_size = args.batch_size,
n_test_trials = args.n_test_trials,
n_bipartitions = args.n_bipartitions,
) No newline at end of file
Comment thread pyproject.toml
Comment on lines +10 to +17
dependencies = [
"torch==2.4.1+cu121",
"numpy",
"scipy",
"matplotlib",
"seaborn",
"neurogym==2.3.1"
]
@jgendra jgendra closed this Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants