Skip to main content

vrfcd

vrfcd stands for van Rossum Functional Community Detection.

This is a Python package for constructing functional connectivity networks from neural spike-train data using the van Rossum distance, and then detecting functional assemblies in the resulting weighted network. The package is designed for computational neuroscience workflows where the input data are spike rasters. The goal is to identify groups of neurons with similar temporal spiking structure.

Workflow

Given a spike train as input the workflow is a four step process:

- Compute the van Rossum distance matrix
- Transform it into functional adjacency matrix
- Prepare the weighted `networkX` graph
- Perform community detection on the graph

Features

vrfcd provides tools to:

  • compute a normalised van Rossum distance matrix from spike-train raster datasets,
  • convert the distance matrix into a functional adjacency matrix using different similarity transformations,
  • construct a weighted functional graph from the adjacency matrix,
  • detect communitues using either the Louvain or Leiden community detection algorithm,
  • visualise the distance matrix, functional matrix, and network representation, and
  • run the full analysis using a single pipeline interface.

Installation

pip install vrfcd

For development:

git clone https://github.com/indranilg49/vrfcd.git
cd vrfcd
pip install -e ".[dev]"

For optional Leiden community detection:

pip install -e ".[dev,leiden]"

Simple usage

import numpy as np
from vrfcd import VRFCDPipeline

pipeline = VRFCDPipeline( t_R=0.01, kernel="minmax", community_method="louvain", n_jobs=4, )

result = pipeline.fit(spike_matrix, t_axis)

D = result.D
A = result.A
G = result.G

partition = result.partition

Here spike_matrix should have the shape of n_neurons x n_time_bins, and t_axis should be the corresponding time axis. Note that if the time axis comes from experimental data with absolute time stamps, it is a good idea to rescale it so that it starts at zero:

t_axis = t_axis - t_axis[0]

Main functions

  • compute_van_rossum_distance
from vrfcd import compute_van_rossum_distance

This computes the pairwise van Rossum distance matrix between spike trains.

D = compute_van_rossum_distance(
    spike_matrix,
    t_axis,
    t_R=0.01,
    traces=False,
    n_jobs=4,
)

The parameter t_R controls the time scale of the exponential filter used in the van Rossum distance. Smaller values of t_R make the distance more sensitive to precise spike timing, while larger values smooth spike trains over a longer temporal window.

If traces=True, the function also returns the convolved spike-train waveforms:

D, waveforms = compute_van_rossum_distance( spike_matrix, t_axis, t_R=0.01, traces=True, )
  • distance_to_functional_matrix
from vrfcd import distance_to_functional_matrix

This converts the van Rossum distance matrix into a functional adjacency matrix.

A = distance_to_functional_matrix( D, kernel="minmax", )

This package currently supports three similarity transformations.

kernel = "clipping"

When using this, the distances are capped at 1 and converted to similarities using: A = 1-D.

kernel = "exponential"

When using this, the distances are rescaled using an exponential kernel: A = exp(-D/beta). The parameter beta controls how quickly similarity decays with distance.

A = distance_to_functional_matrix( D, kernel="exponential", beta=0.1, )

kernel = "minmax"

When using this, the distances are rescaled using a min-max transformation:

A = distance_to_functional_matrix(
    D,
    kernel="minmax",
    q_low=0.0,
    q_high=1.0,
)

This maps small distances to high functional similarity and large distances to low functional similarity. The diagonal of the resulting matrix is set to 0 by default.

  • build_functional_graph
from vrfcd import build_functional_graph

This builds a weighted networkX graph from the functional adjacency matrix.

G = build_functional_graph( A, threshold=0.0, )

In the graph representation, each neuron is a node, and edges are weighted by the functional similarity values in A. The threshold parameter can be used to remove weak functional connections.

  • detect_communities
from vrfcd import detect_communities

This function detects communities in the weighted functional graph.

partition = detect_communities( G, method="louvain", seed=42, )

The output is a disctionary mapping each node to a community label. The package currently supports two methods for community detection:

method = "louvain"
method = "leiden"

The Louvain method works with the core dependencies. In order to use Leiden, you will need to install the optional dependencies igraph and leidenalg additionally.

Pipeline interface

Here we outline the easiest way to use the package through VRFCDPipeline.

from vrfcd import VRFCDPipeline 

pipeline = VRFCDPipeline( t_R=0.01, kernel="minmax", q_low=0.0, q_high=1.0, community_method="louvain", n_jobs=4, traces=True, )

result = pipeline.fit(spike_matrix, t_axis)

The pipeline returns a VRFCDResult object containing:

  • result.D: van Rossum distance matrix
  • result.A: functional adjacency matrix
  • result.G: community labels
  • result.partition: graph with community attributes
  • result.G_partitioned: van Rossum distance matrix
  • result.counts: number of nodes in each community
  • result.waveforms: convolved spike traces, if traces=True

This allows the full analysis to be run in one step while still giving access to every intermediate object.

Plotting

vrfcd also includes helper functions for viusalisation.

from vrfcd.plotting import plot_matrix, plot_functional_network

To plot the van Rossum distance matrix:

plot_matrix( result.D, colorbar_title=r"$\tilde{D}(t_R)$", savepath="distance_matrix.pdf", )

To plot the adjacency matrix:

plot_matrix( result.A, colorbar_title=r"$A(t_R)$", savepath="functional_matrix.pdf", )

To plot the functional network:

plot_functional_network( result.G_partitioned, partition=result.partition, savepath="functional_network.pdf", )

Overview

This package is intended for exploratory and research-focused analysis of spike-train data. It is particularly useful when one wants to compare neurons based on spike timing, construct a functional network from these similarities, and identify groups of neurons with similar temporal spiking patterns. This package can be used with synthetic spike raster, simulated spiking network models, and experimental recordings such as Neuropixels spike-train datasets.

Metadata

Release files for vrfcd 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vrfcd 0.1.2
File Size Uploaded Provenance Actions
vrfcd-0.1.2.tar.gz 12.1 kB Without provenance Details for vrfcd-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vrfcd 0.1.2
File Interpreter ABI Platform Actions
vrfcd-0.1.2-py3-none-any.whl Python 3 none any Details for vrfcd-0.1.2-py3-none-any.whl

Total release size: 22.9 kB

Release files / vrfcd-0.1.2.tar.gz

Download URL vrfcd-0.1.2.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a2abd58f1a6cd4476f69162ec42e082df499a8842089672e725c6dab7ad0e1d5
BLAKE2b-256 checksum
How to use checksums
be3cecdd83ba5c4e8b4d89d5730241d6fcfd89df443ed0b7506324b0867c1089
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / vrfcd-0.1.2-py3-none-any.whl

Download URL vrfcd-0.1.2-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b6f0dd2426dfd4c2898a11f81ed838c9df65ad4a5f0065bd69fea8420f89d48
BLAKE2b-256 checksum
How to use checksums
69e8ffe14d97f74177f38949f8e7845bd485cd48a91e4f174b409345f0517766
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Security for vrfcd 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page