Skip to content

[WIP] Add dipole contribution visualization - #1178

Open
Arnav05-cyber wants to merge 3 commits into
jonescompneurolab:masterfrom
Arnav05-cyber:add-dipole-contribution-visualization
Open

[WIP] Add dipole contribution visualization#1178
Arnav05-cyber wants to merge 3 commits into
jonescompneurolab:masterfrom
Arnav05-cyber:add-dipole-contribution-visualization

Conversation

@Arnav05-cyber

Copy link
Copy Markdown

Problem

Stephanie requested a visualization that shows what components (drives, channels, etc.) contribute to dipole flow "up" versus "down" throughout the simulation, similar to figure C in issue #966.

Solution

Implemented comprehensive dipole contribution analysis and visualization tools:

New Features

  • plot_dipole_contributions(): Time-series visualization of UP vs DOWN components
  • analyze_dipole_contributions(): Quantitative analysis of contributions
  • ✅ Enhanced Dipole class with plot_contributions() and analyze_contributions() methods
  • ✅ Automatic component classification system

Component Classification

  • UP Components (RED): L2 pyramidal cells, proximal drives, positive tonic biases
  • DOWN Components (BLUE): L5 pyramidal cells, distal drives, negative tonic biases

Key Benefits

  • Understand mechanistic origins of dipole signals
  • Interpret experimental MEG/EEG data
  • Design targeted experiments
  • Validate model predictions

Files Added

  • New dipole_contributions.py module with analysis functions
  • Comprehensive example script with educational content
  • Full test suite ensuring functionality
  • Enhanced Dipole class methods

Usage

# Basic usage
dpl.plot_contributions(net)
analysis = dpl.analyze_contributions(net)

# Advanced usage  
plot_dipole_contributions(net, dpl, tmin=50, tmax=150)

- Changed _OutputWidgetHandler.emit() to append new messages to the end
- This ensures errors and new log messages appear at the bottom where they're more visible
- Fixes issue where errors could be hidden when appearing at the top of log window

Fixes: GUI error visibility issue
- Enhanced Optimizer class to accept custom callable loss functions
- Added validation for custom objective function signatures
- Implemented three predefined custom loss functions:
  * _spectral_power_loss: for matching power spectral densities
  * _phase_coherence_loss: for optimizing rhythmic coherence
  * _custom_rmse_with_weights: for time-weighted RMSE optimization
- Added comprehensive example showing usage of custom loss functions
- Added test suite for custom loss function validation and functionality
- Updated exports in __init__.py to include new loss functions

This addresses the need for custom loss functions suitable for Poisson drives
and steady-state oscillations where traditional RMSE is not appropriate.

Fixes: Custom loss function feature request
- Created new dipole_contributions.py module with analysis and visualization functions
- Added plot_dipole_contributions() to visualize UP vs DOWN dipole components
- Added analyze_dipole_contributions() to analyze component contributions
- Enhanced Dipole class with plot_contributions() and analyze_contributions() methods
- Identifies components that contribute to UP (positive) vs DOWN (negative) deflections:
  * L2 pyramidal cells and proximal drives  UP components (red)
  * L5 pyramidal cells and distal drives  DOWN components (blue)
  * Tonic biases based on amplitude polarity
- Comprehensive example script showing usage and interpretation
- Full test suite ensuring functionality and edge cases
- Updated exports in __init__.py

This addresses Stephanie's request for visualization showing what components
contribute to dipole flow 'up' versus 'down' throughout the simulation,
similar to figure C in issue jonescompneurolab#966.

Features:
- Time-series visualization of component contributions
- Color-coded UP (red) vs DOWN (blue) components
- Overlay of total dipole signal
- Analysis of drive locations, layer contributions, and biases
- Educational annotations and interpretive guidance
@asoplata

Copy link
Copy Markdown
Collaborator

Thank you for your contribution Arnav and apologies for the late response. Your PR is very interesting and possibly relevant to other ongoing work that we are doing ourselves. We will try to respond in greater detail to your proposed changes as soon as we can. In the meantime, if you have any figures displaying some of the functionality, it would be great if you could post it here. Thanks!

@asoplata asoplata changed the title Add dipole contribution visualization [WIP] Add dipole contribution visualization May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants