Skip to content

cwangaw/neural-activity-analysis

Repository files navigation

Neural Activity Analysis: Stimulus Response and Behavioral Modulation

Overview

This project analyzes neural activity data from the Allen Brain Observatory visual behavior dataset to understand how neurons respond to visual stimuli and behavioral state.

The workflow combines:

  • Tableau dashboards for exploratory and comparative visual analysis
  • Python notebooks for machine learning and dimensionality reduction
  • Public online data loading so the core analyses can run without a local SQL database

Main questions:

  • How do neural responses differ across cell types (SST vs VIP)?
  • How do responses differ for change versus omission events?
  • Does running speed modulate neural activity?
  • Is there interpretable low-dimensional structure in neural-response features?

Dataset

  • Source: Allen Institute for Brain Science (Visual Behavior 2P dataset)
  • Access pattern used here: a preprocessed public parquet file downloaded on first run by the notebooks
  • Scale: ~150,000 trial-cell response observations
  • Entities: 223 cells, 25 sessions, 13 mice

Key Features

  • mean_response — neural response magnitude
  • image_name — stimulus identity
  • cre_line / cell_type — cell type (SST, VIP)
  • exposure_level — familiar vs. novel stimuli
  • is_change, omitted, rewarded — event indicators
  • mean_running_speed — locomotion / behavioral state
  • response_latency, baseline_response, peak_response — response summary features

Project Components

1. Tableau Dashboard

The Tableau dashboard focuses on interpretable visual analytics:

  • KPI summary
  • Response by exposure level and cell type for change events
  • Response by exposure level and cell type for omission events
  • Running speed vs. neural response scatter plot with trend lines
  • Image × cell-type heatmap

2. Machine Learning Notebook

ml_analysis_online.ipynb downloads the public preprocessed dataset and trains a Random Forest classifier on a balanced high-vs-low neural response task.

3. PCA Notebook

pca_analysis_online.ipynb downloads the same dataset and applies PCA to examine latent structure in neural-response features.


Key Findings

Change vs. Omission Response

  • VIP neurons show consistently stronger responses than SST neurons
  • Omission events produce weaker, but still measurable, neural responses
  • These comparisons suggest that neural activity reflects both stimulus detection and expectation / surprise

Behavioral Modulation

  • The global relationship between running speed and neural response is weak
  • After stratifying by event type, exposure level, and cell type:
    • VIP neurons show a slight positive association with running speed
    • SST neurons show weak or negative dependence
    • Differences are more pronounced under novel conditions

Stimulus-Level Response Patterns

  • Heatmaps show strong variability across image stimuli
  • VIP neurons generally exhibit higher response levels than SST neurons
  • Neural responses are stimulus-dependent, not uniform across images

PCA Results

PCA showed that neural-response variability is distributed across multiple latent dimensions.

  • PC1 ≈ 23% of variance
  • PC2 ≈ 18% of variance
  • Top 2 PCs ≈ 41% cumulative variance
  • Top 5 PCs ≈ 78% cumulative variance

Interpretation:

  • The first two PCs are useful for visualization, but they do not fully capture the data structure
  • Exposure level (familiar vs. novel) overlaps heavily in PCA space, so it is not the dominant source of variation in the first two PCs
  • Cell type shows a broader distributional shift, with VIP neurons occupying a wider region of PCA space than SST neurons

Loadings suggest:

  • PC1 behaves like an event / response-strength axis, contrasting omission-related and change/reward-related trials
  • PC2 behaves like a broader activity-state axis, with strong contributions from baseline response, mean response, and running speed

Example outputs:

  • figures/pca_explained_variance.png
  • figures/pca_by_cell_type.png
  • figures/pca_by_exposure.png
  • figures/pca_top_loadings.png

Machine Learning Results

The Random Forest notebook formulates a conservative, interview-defensible task:

  • Target: high vs. low neural response, defined by the median mean_response

Result:

  • Accuracy ≈ 64% on a balanced classification task

Interpretation:

  • Trial-level state and condition features contain moderate predictive signal
  • Neural response magnitude is partially predictable, but substantial residual variability remains
  • This should be interpreted as an exploratory predictive analysis, not a full neural decoding system

Example outputs:

  • figures/ml_confusion_matrix.png
  • figures/ml_feature_importance.png

Visual Outputs

Include exported figures such as:

  • figures/dashboard.png
  • figures/scatter_plot.png
  • figures/heatmap.png
  • figures/pca_explained_variance.png
  • figures/pca_by_cell_type.png
  • figures/pca_by_exposure.png
  • figures/pca_top_loadings.png
  • figures/ml_confusion_matrix.png
  • figures/ml_feature_importance.png

Example Dashboard

Dashboard


File Structure

A simple root-level layout is assumed:

.
├── README.md
├── requirements.txt
├── ml_analysis_online.ipynb
├── pca_analysis_online.ipynb
├── figures/
│   ├── dashboard.png
│   ├── scatter_plot.png
│   ├── heatmap.png
│   ├── pca_explained_variance.png
│   ├── pca_by_cell_type.png
│   ├── pca_by_exposure.png
│   ├── pca_top_loadings.png
│   ├── ml_confusion_matrix.png
│   └── ml_feature_importance.png
├── data/
│   └── sample_data.csv
└── sql/
    └── schema.sql

Notes:

  • The notebooks download the parquet file automatically into data/ if it is missing
  • sql/schema.sql is optional and is mainly useful for documenting the Tableau / SQL modeling work

How to Run

  1. Install dependencies:

    pip install -r requirements.txt
  2. Run the notebooks from the project root:

    • ml_analysis_online.ipynb
    • pca_analysis_online.ipynb
  3. On first run, the notebooks will download the public preprocessed parquet file into data/

  4. Generated figures will be saved into figures/


Tools

  • Python: Pandas, Scikit-learn, Matplotlib
  • Tableau: dashboard design and exported visuals
  • SQL / PostgreSQL: used for the relational dashboard-side data model
  • Public online dataset access: requests + parquet loading

Key Takeaways

  • Neural responses depend strongly on stimulus identity and cell type
  • Behavioral variables have weaker but structured influence
  • Stratified analysis is necessary to uncover meaningful patterns
  • The feature space is structured but moderately high-dimensional
  • Moderate Random Forest accuracy suggests partial predictability with substantial unexplained variance remaining

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors