Skip to content

Commit 620ec73

Browse files
authored
Merge pull request #51 from CausalityInMotion/dev_autotest
Refactor project for JOSS-ready packaging with CI, docs, and ReadMe
2 parents 4c4842f + 78403f1 commit 620ec73

10 files changed

Lines changed: 147 additions & 28 deletions

File tree

.github/workflows/tests.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# ...
2+
# Copyright 2021 Brooks M. Musangu and Jan Drugowitsch.
3+
# license Modified BSD, see LICENSE.txt for details.
4+
# ...
5+
name: CI Tests and Docs
6+
7+
on:
8+
push:
9+
branches: [ main ]
10+
pull_request:
11+
branches: [ main ]
12+
13+
jobs:
14+
test:
15+
name: Run Pytest Suite
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.x'
26+
27+
- name: Install package and test dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install .[test]
31+
32+
- name: Run tests
33+
run: |
34+
pytest test/
35+
36+
docs:
37+
name: Build Documentation
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v4
43+
44+
- name: Set up Python
45+
uses: actions/setup-python@v5
46+
with:
47+
python-version: '3.x'
48+
49+
- name: Install Pandoc
50+
run: |
51+
sudo apt-get update
52+
sudo apt-get install -y pandoc
53+
54+
- name: Install docs dependencies
55+
run: |
56+
python -m pip install --upgrade pip
57+
pip install .[docs]
58+
59+
- name: Build Sphinx documentation
60+
run: |
61+
sphinx-build -b html docs docs/_build

.readthedocs.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# .readthedocs.yml
2+
version: 2
3+
4+
build:
5+
os: ubuntu-22.04
6+
tools:
7+
python: "3.13"
8+
9+
python:
10+
install:
11+
- method: pip
12+
path: .
13+
extra_requirements:
14+
- docs
15+
16+
sphinx:
17+
configuration: docs/conf.py

README.md

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1-
# GPFA_for_sklearn
1+
# BlockInvGPFA
2+
3+
[![Automated Tests](https://github.com/CausalityInMotion/BlockInverseGPFA/actions/workflows/tests.yml/badge.svg)](https://github.com/CausalityInMotion/BlockInverseGPFA/actions/workflows/tests.yml)
4+
[![Documentation Status](https://readthedocs.org/projects/blockinversegpfa/badge/?version=latest)](https://blockinversegpfa.readthedocs.io/en/latest/)
5+
6+
This package provides a Python implementation of **Gaussian Process Factor Analysis (GPFA)** that incorporates a novel approach to efficiently handle variable-length time series data. Building on the original method by [Byron Yu et al. (2009)](https://papers.nips.cc/paper/2009/hash/6c1b887a379c4f0c2c621f305d15f6b0-Abstract.html), this implementation introduces a **block-matrix–based inversion strategy** that reuses kernel computations across trials of different lengths.
7+
8+
The package also includes **scikit-learn–compatible API** for integration into existing ML workflows such as:
9+
- A **Modular Preprocessing** — Separates data preprocessing from model logic via a dedicated `EventTimesToCounts` transformer.
10+
- Accepts standard array-like inputs (not `Neo` objects), simplifying integration with other tools.
11+
- Follows scikit-learn's transformer–estimator interface for clean, reusable workflows.
12+
- A new **variance-explained metric** to evaluate GPFA model fits.
13+
14+
This implementation is adapted from [Elephant](https://elephant.readthedocs.io/en/latest/reference/gpfa.html)’s GPFA codebase with substantial modifications to improve performance, modularity, and usability in Python-based pipelines.
215

3-
This package is an implementation of Gaussian Process Factor Analysis (GPFA) by Byron Yu et al.,
4-
(2009) in python. The code is based on [Elephant](https://elephant.readthedocs.io/en/latest/reference/gpfa.html)'s
5-
python implementation plus additional modules and functional implementations.
616

717
## Usage
818

919
### Installation
1020
-----------------
1121

12-
- Clone the project locally using
22+
Install directly from GitHub using `pip`:
1323

1424
```bash
15-
$ git clone https://github.com/CausalityInMotion/GPFA_for_sklearn
25+
$ pip install git+https://github.com/CausalityInMotion/BlockInverseGPFA.git
1626
```
17-
18-
Ensure you are in the working directory of the project.
19-
20-
Then install the project's required packages uisng
27+
Or clone the repo and install locally:
2128

2229
```bash
23-
$ pip install -r requirements.txt
30+
$ git clone https://github.com/CausalityInMotion/BlockInverseGPFA.git
31+
$ cd BlockInverseGPFA
32+
$ pip install . # or pip install .[test,docs] to include optional dependencies
2433
```
2534

2635
You are now set to use the package.
@@ -36,41 +45,46 @@ Building the documentation requires the following packages:
3645
- [numpydoc](https://numpydoc.readthedocs.io/)
3746
- [Jupyter Notebook Tools for Sphinx](https://nbsphinx.readthedocs.io/)
3847

39-
You can install the required packages either using the `docs/requirements.txt` file,
48+
You can install the required documentation dependencies by:
4049
```bash
41-
$ pip install -r docs/requirements.txt
50+
$ pip install .[docs]
4251
```
4352
or manually by calling
4453
```bash
4554
$ pip install sphinx sphinx-rtd-theme numpydoc nbsphinx
4655
```
4756

48-
Finally, to view the documentation, run
57+
Finally, to view the documentation locally, run
4958

5059
```bash
5160
$ cd docs
5261
$ make html
5362
$ open _build/html/index.html
5463
```
64+
or view them online:
65+
[BlockInvGPFA docs](https://blockinversegpfa.readthedocs.io/en/latest/)
66+
67+
A detailed walkthrough of the package — including how to fit the model to real neural data — is available in the Jupyter notebook example: (link)
5568

5669
-----------
5770
### Tests
5871
-----------
5972

60-
To run the unittests in the [test](test) folder, use the following command in your command line/terminal:
73+
To run the full test suite in the [test](test) folder, use:
6174

6275
```bash
63-
$ python -m unittest test.gpfa
64-
$ python -m unittest test.preprocessing
76+
$ pip install .[test]
77+
$ pytest test/
6578
```
79+
Tests are automatically run via [GitHub Actions](https://github.com/CausalityInMotion/BlockInverseGPFA/actions/workflows/tests.yml) on every push and pull request.
6680

6781
## License
6882
Modified BSD License based on Elephant, see [LICENSE.txt](LICENSE.txt) for details.
6983

7084

7185
## Copyright
7286

73-
:copyright: 2021 Brooks M. Musangu and Jan Drugowitsch
87+
:copyright: 2021-2025 Brooks M. Musangu and Jan Drugowitsch
7488

7589
## Acknowledgments
7690

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
authors = 'Brooks M. Musangu and Jan Drugowitsch'
2727
copyright = "2021-{this_year}, {authors}".format(
2828
this_year=date.today().year, authors=authors)
29-
release = '0.0.1'
29+
release = '0.1.0.'
30+
version = '0.1.0'
3031

3132
# -- General configuration ---------------------------------------------------
3233
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

docs/requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

gpfa/gpfa.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# ...
2-
# Moving this here to prevent from showing up on sphinx pages
32
# Copyright 2021 Brooks M. Musangu and Jan Drugowitsch.
43
# Copyright 2014-2020 by the Elephant team.
54
# Modified BSD, see LICENSE.txt for details.

pyproject.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "blockinversegpfa"
7+
version = "0.1.0"
8+
description = "A scikit-learn-compatible GPFA implementation using block matrix inversion."
9+
authors = [
10+
{name = "Brooks M. MUSANGU", email = "brooks_musangu@hms.harvard.edu"},
11+
{name = "Jan DRUGOWITSCH", email = "jan_drugowitsch@hms.harvard.edu"}
12+
]
13+
license = {file = "LICENSE.txt"}
14+
readme = "README.md"
15+
requires-python = ">=3.9"
16+
dependencies = [
17+
"numpy==2.2.1",
18+
"scikit-learn==1.6.0",
19+
"scipy==1.15.0",
20+
"tqdm==4.67.1"
21+
]
22+
23+
[project.optional-dependencies]
24+
test = [
25+
"pytest==7.3.1"
26+
]
27+
docs = [
28+
"nbsphinx==0.9.6",
29+
"numpydoc==1.8.0",
30+
"Sphinx==8.1.3",
31+
"sphinx-rtd-theme==3.0.2"
32+
]
33+
34+
[project.urls]
35+
Homepage = "https://github.com/CausalityInMotion/BlockInverseGPFA"

requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)