Skip to content

Commit b2b2dd0

Browse files
authored
Merge pull request #52 from CausalityInMotion/dev
Refactor installation guide and documentation references for clarity
2 parents 620ec73 + e37b081 commit b2b2dd0

16 files changed

+184
-152
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
:copyright: Copyright 2021 Brooks M. Musangu and Jan Drugowitsch.
33
:license: Modified BSD, see LICENSE.txt for details.
44
"""
5-
from .gpfa import GPFA
5+
from .blockinvgpfa import BlockInvGPFA
66
from .preprocessing import EventTimesToCounts
77

88
__all__ = [
9-
"GPFA",
9+
"BlockInvGPFA",
1010
"EventTimesToCounts"
1111
]

gpfa/gpfa.py renamed to blockinvgpfa/blockinvgpfa.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525
from tqdm import trange
2626

2727
__all__ = [
28-
"GPFA"
28+
"BlockInvGPFA"
2929
]
3030

3131

32-
class GPFA(sklearn.base.BaseEstimator):
33-
"""Gaussian Process Factor Analysis (GPFA) is a probabilistic
34-
dimensionality reduction technique that extracts smooth latent
35-
trajectories from noisy, high-dimensional time series data.
36-
It combines Factor Analysis (FA) for dimensionality reduction with Gaussian
37-
Processes (GPs) to model the time courses of the latent factors in a
38-
unified, probabilistic framework.
32+
class BlockInvGPFA(sklearn.base.BaseEstimator):
33+
"""BlockInvGPFA is a high-performance implementation of Gaussian
34+
Process Factor Analysis (GPFA) is a probabilistic dimensionality
35+
reduction technique that extracts smooth latent trajectories from
36+
noisy, high-dimensional time series data. GPFA combines Factor
37+
Analysis (FA) for dimensionality reduction with Gaussian Processes
38+
(GPs) to model the time courses of the latent factors in a unified,
39+
probabilistic framework.
3940
4041
GPFA operates on a set of time-series data, where each time series is
4142
given by an ``x_dim`` x ``bins`` matrix. ``x_dim`` needs to be the same
@@ -47,6 +48,16 @@ class GPFA(sklearn.base.BaseEstimator):
4748
Please consult the :ref:`main page <gpfa_prob_model>` for more details on
4849
the underlying probabilistic model.
4950
51+
This implementation, BlockInvGPFA, builds on the core model described
52+
in [Yu et al., 2009] and is adapted from the Elephant's toolkit, with
53+
substantial algorithmic enhancements:
54+
55+
1. It uses block-matrix identities and Schur complement updates to
56+
efficiently share kernel inversion computations across
57+
variable-length trials.
58+
2. It introduces a new variance-explained metric to evaluate BlockInvGPFA
59+
model fits
60+
5061
Parameters
5162
----------
5263
bin_size : float, optional, default=0.02
@@ -194,45 +205,45 @@ class GPFA(sklearn.base.BaseEstimator):
194205
Examples
195206
--------
196207
>>> import numpy as np
197-
>>> from gpfa import GPFA
208+
>>> from blockinvgpfa import BlockInvGPFA
198209
199210
>>> X = np.array([[
200211
... [3, 1, 0, 4, 1, 2, 1, 3, 4, 2, 2, 1, 2, 0, 0, 2, 2, 5, 1, 3],
201212
... [1, 0, 2, 0, 2, 1, 4, 2, 0, 1, 4, 4, 1, 2, 8, 3, 2, 1, 3, 1],
202213
... [2, 2, 1, 1, 3, 2, 3, 2, 2, 0, 3, 4, 1, 2, 3, 1, 4, 1, 0, 1]
203214
... ]])
204215
>>>
205-
>>> gpfa_model = GPFA(z_dim=1)
216+
>>> blockinv_gpfa = BlockInvGPFA(z_dim=1)
206217
207218
>>> # Fit the model
208-
>>> gpfa_model.fit(X)
219+
>>> blockinv_gpfa.fit(X)
209220
Initializing parameters using factor analysis...
210-
Fitting GPFA model...
221+
Fitting GP parameters by EM...
211222
212223
>>> # Infere latent variable time-courses for the same data
213-
>>> Zs, _ = gpfa_model.predict()
224+
>>> Zs, _ = blockinv_gpfa.predict()
214225
>>> print(Zs)
215226
[array([[-1.18405633, -2.00878 , -0.01470251, -2.3143544 , 0.03651376,
216227
-1.06948736, 2.05355342, -0.16920794, -2.26437342, -1.21934552,
217228
1.98656088, 2.13305066, -1.14113106, 0.11319858, 6.14998095,
218229
0.89241818, 0.03509708, -1.3936327 , 0.84781358, -1.2281484 ]])]
219230
220231
>>> # Display the loading matrix (C_) and observation mean (d_) parameters
221-
>>> print(gpfa_model.C_)
232+
>>> print(blockinv_gpfa.C_)
222233
[[-0.78376501]
223234
[ 1.77773876]
224235
[ 0.51134474]]
225236
226-
>>> print(gpfa_model.d_)
237+
>>> print(blockinv_gpfa.d_)
227238
[1.95470037 2.08933859 1.89693338]
228239
229240
>>> # Obtaining log-likelihood scores
230-
>>> llhs = gpfa_model.score()
241+
>>> llhs = blockinv_gpfa.score()
231242
>>> print(llhs)
232243
[-117.54588379661148, -107.17193271370158, ..., -100.13200154180569]
233244
234245
>>> # Evaluate the total explained variance regression score
235-
>>> print(gpfa_model.variance_explained())
246+
>>> print(blockinv_gpfa.variance_explained())
236247
(0.6581475357501596, array([0.65814754]))
237248
238249
@@ -761,7 +772,7 @@ def _em(self, X):
761772

762773
if np.any(np.diag(self.R_) == var_floor):
763774
warnings.warn('Private variance floor used for one or more '
764-
'observed dimensions in GPFA.')
775+
'observed dimensions in BlockInvGPFA.')
765776

766777
self.fit_info_ = {'iteration_time': iter_time, 'log_likelihoods': lls}
767778

@@ -1188,7 +1199,7 @@ def _fill_p_auto_sum(self, Seqs, precomp):
11881199
on the caller (which should be :func:`_learn_gp_params()`) to make
11891200
sure this is called correctly.
11901201
1191-
Finally, see the notes in the GPFA README.
1202+
Finally, see the notes in the BlockInvGPFA README.
11921203
"""
11931204
############################################################
11941205
# Fill out PautoSum

docs/_static/log-likelihoods.png

-22.4 KB
Binary file not shown.
-929 KB
Binary file not shown.
-957 KB
Binary file not shown.

docs/blockinv_gpfa_class.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
==================
2+
BlockInvGPFA Class
3+
==================
4+
5+
.. currentmodule:: blockinvgpfa
6+
.. autoclass:: BlockInvGPFA
7+
:members:

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import os
88
from datetime import date
99

10-
# include root path to allow autodoc to find gpfa module
10+
# include root path to allow autodoc to find blockgpfa module
1111
sys.path.insert(0, os.path.abspath('../'))
1212

1313
# Path to the source directory (where your .rst files are)
@@ -22,7 +22,7 @@
2222

2323
# -- General configuration -----------------------------------------------
2424

25-
project = 'GPFA Documentation'
25+
project = 'BlockInvGPFA Documentation'
2626
authors = 'Brooks M. Musangu and Jan Drugowitsch'
2727
copyright = "2021-{this_year}, {authors}".format(
2828
this_year=date.today().year, authors=authors)

docs/contribute.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Contribution
55
==============
66

7-
We welcome contributions to the GPFA package, whether they involve enhancements, bug fixes,
7+
We welcome contributions to the BlockInvGPFA package, whether they involve enhancements, bug fixes,
88
or documentation improvements. To ensure the codebase's quality and maintainability, please
99
follow this guide carefully.
1010

@@ -33,9 +33,9 @@ include tests for any module, class, or function you contribute.
3333

3434
**Version Control Workflow**
3535

36-
When contributing to the GPFA package, please follow these steps:
36+
When contributing to the BlockInvGPFA package, please follow these steps:
3737

38-
1. Fork the GPFA repository on GitHub.
38+
1. Fork the BlockInvGPFA repository on GitHub.
3939

4040
2. Clone your forked repository to your local machine.
4141

@@ -50,12 +50,12 @@ When contributing to the GPFA package, please follow these steps:
5050

5151
7. Push your branch to your GitHub fork.
5252

53-
8. Create a pull request (PR) from your branch to the GPFA main repository. Provide a
53+
8. Create a pull request (PR) from your branch to the BlockInvGPFA main repository. Provide a
5454
detailed description of your changes in the PR.
5555

5656
9. We will review your PR, and if necessary, provide feedback or request changes.
5757

58-
10. Once your PR is approved, it will be merged into the main GPFA repository.
58+
10. Once your PR is approved, it will be merged into the main BlockInvGPFA repository.
5959

60-
Thank you for your contribution to the GPFA package. Your efforts help improve
60+
Thank you for your contribution to the BlockInvGPFA package. Your efforts help improve
6161
and maintain this valuable resource for the community.

docs/gpfa_class.rst

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

0 commit comments

Comments
 (0)