Skip to content

Commit 823c9ca

Browse files
MMathisLabstes
andauthored
General Doc refresher (#232)
* Update installation.rst - python 3.9+ * Update index.rst * Update figures.rst * Update index.rst -typo fix * Update usage.rst - update suggestion on data split * Update docs/source/usage.rst Co-authored-by: Steffen Schneider <[email protected]> * Update usage.rst - indent error fixed * Update usage.rst - changed infoNCE to new GoF * Update usage.rst - finx numpy() doctest * Update usage.rst - small typo fix (label) * Update usage.rst --------- Co-authored-by: Steffen Schneider <[email protected]>
1 parent 47945ca commit 823c9ca

File tree

4 files changed

+72
-59
lines changed

4 files changed

+72
-59
lines changed

docs/source/figures.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Figures
22
=======
33

4-
CEBRA was introduced in `Schneider, Lee and Mathis (2022)`_ and applied to various datasets across
4+
CEBRA was introduced in `Schneider, Lee and Mathis (2023)`_ and applied to various datasets across
55
animals and recording modalities.
66

77
In this section, we provide reference code for reproducing the figures and experiments. Since especially
@@ -56,4 +56,4 @@ differ in minor typographic details.
5656

5757

5858

59-
.. _Schneider, Lee and Mathis (2022): https://arxiv.org/abs/2204.00673
59+
.. _Schneider, Lee and Mathis (2023): https://www.nature.com/articles/s41586-023-06031-6

docs/source/index.rst

+22-17
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,18 @@ Please support the development of CEBRA by starring and/or watching the project
3434
Installation and Setup
3535
----------------------
3636

37-
Please see the dedicated :doc:`Installation Guide </installation>` for information on installation options using ``conda``, ``pip`` and ``docker``.
38-
39-
Have fun! 😁
37+
Please see the dedicated :doc:`Installation Guide </installation>` for information on installation options using ``conda``, ``pip`` and ``docker``. Have fun! 😁
4038

4139
Usage
4240
-----
4341

4442
Please head over to the :doc:`Usage </usage>` tab to find step-by-step instructions to use CEBRA on your data. For example use cases, see the :doc:`Demos </demos>` tab.
4543

46-
Integrations
47-
------------
48-
49-
CEBRA can be directly integrated with existing libraries commonly used in data analysis. The ``cebra.integrations`` module
50-
is getting actively extended. Right now, we offer integrations for ``scikit-learn``-like usage of CEBRA, a package making use of ``matplotlib`` to plot the CEBRA model results, as well as the
51-
possibility to compute CEBRA embeddings on DeepLabCut_ outputs directly.
52-
5344

5445
Licensing
5546
---------
56-
57-
Since version 0.4.0, CEBRA is open source software under an Apache 2.0 license.
47+
The ideas presented in our package are currently patent pending (Patent No. WO2023143843).
48+
Since version 0.4.0, CEBRA's source is licenced under an Apache 2.0 license.
5849
Prior versions 0.1.0 to 0.3.1 were released for academic use only.
5950

6051
Please see the full license file on Github_ for further information.
@@ -65,13 +56,19 @@ Contributing
6556

6657
Please refer to the :doc:`Contributing </contributing>` tab to find our guidelines on contributions.
6758

68-
Code contributors
59+
Code Contributors
6960
-----------------
7061

71-
The CEBRA code was originally developed by Steffen Schneider, Jin H. Lee, and Mackenzie Mathis (up to internal version 0.0.2). As of March 2023, it is being actively extended and maintained by `Steffen Schneider`_, `Célia Benquet`_, and `Mackenzie Mathis`_.
62+
The CEBRA code was originally developed by Steffen Schneider, Jin H. Lee, and Mackenzie Mathis (up to internal version 0.0.2). Please see our AUTHORS file for more information.
7263

73-
References
74-
----------
64+
Integrations
65+
------------
66+
67+
CEBRA can be directly integrated with existing libraries commonly used in data analysis. Namely, we provide a ``scikit-learn`` style interface to use CEBRA. Additionally, we offer integrations with our ``scikit-learn``-style of using CEBRA, a package making use of ``matplotlib`` and ``plotly`` to plot the CEBRA model results, as well as the possibility to compute CEBRA embeddings on DeepLabCut_ outputs directly. If you have another suggestion, please head over to Discussions_ on GitHub_!
68+
69+
70+
Key References
71+
--------------
7572
.. code::
7673
7774
@article{schneider2023cebra,
@@ -82,14 +79,22 @@ References
8279
year = {2023},
8380
}
8481
82+
@article{xCEBRA2025,
83+
author={Steffen Schneider and Rodrigo Gonz{\'a}lez Laiz and Anastasiia Filippova and Markus Frey and Mackenzie W Mathis},
84+
title = {Time-series attribution maps with regularized contrastive learning},
85+
journal = {AISTATS},
86+
url = {https://openreview.net/forum?id=aGrCXoTB4P},
87+
year = {2025},
88+
}
89+
8590
This documentation is based on the `PyData Theme`_.
8691

8792

8893
.. _`Twitter`: https://twitter.com/cebraAI
8994
.. _`PyData Theme`: https://github.com/pydata/pydata-sphinx-theme
9095
.. _`DeepLabCut`: https://deeplabcut.org
96+
.. _`Discussions`: https://github.com/AdaptiveMotorControlLab/CEBRA/discussions
9197
.. _`Github`: https://github.com/AdaptiveMotorControlLab/cebra
9298
.. _`email`: mailto:[email protected]
9399
.. _`Steffen Schneider`: https://github.com/stes
94-
.. _`Célia Benquet`: https://github.com/CeliaBenquet
95100
.. _`Mackenzie Mathis`: https://github.com/MMathisLab

docs/source/installation.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Installation Guide
44
System Requirements
55
-------------------
66

7-
CEBRA is written in Python (3.8+) and PyTorch. CEBRA is most effective when used with a GPU, but CPU-only support is provided. We provide instructions to run CEBRA on your system directly. The instructions below were tested on different compute setups with Ubuntu 18.04 or 20.04, using Nvidia GTX 2080, A4000, and V100 cards. Other setups are possible (including Windows), as long as CUDA 10.2+ support is guaranteed.
7+
CEBRA is written in Python (3.9+) and PyTorch. CEBRA is most effective when used with a GPU, but CPU-only support is provided. We provide instructions to run CEBRA on your system directly. The instructions below were tested on different compute setups with Ubuntu 18.04 or 20.04, using Nvidia GTX 2080, A4000, and V100 cards. Other setups are possible (including Windows), as long as CUDA 10.2+ support is guaranteed.
88

99
- Software dependencies and operating systems:
1010
- Linux or MacOS
@@ -93,11 +93,11 @@ we outline different options below.
9393
9494
* 🚀 For more advanced users, CEBRA has different extra install options that you can select based on your usecase:
9595

96-
* ``[integrations]``: This will install (experimental) support for our streamlit and jupyter integrations.
96+
* ``[integrations]``: This will install (experimental) support for integrations, such as plotly.
9797
* ``[docs]``: This will install additional dependencies for building the package documentation.
9898
* ``[dev]``: This will install additional dependencies for development, unit and integration testing,
9999
code formatting, etc. Install this extension if you want to work on a pull request.
100-
* ``[demos]``: This will install additional dependencies for running our demo notebooks.
100+
* ``[demos]``: This will install additional dependencies for running our demo notebooks in Jupyter.
101101
* ``[datasets]``: This extension will install additional dependencies to use the pre-installed datasets
102102
in ``cebra.datasets``.
103103

docs/source/usage.rst

+45-37
Original file line numberDiff line numberDiff line change
@@ -1207,42 +1207,47 @@ Putting all previous snippet examples together, we obtain the following pipeline
12071207

12081208
# 1. Define a CEBRA model
12091209
cebra_model = cebra.CEBRA(
1210-
model_architecture = "offset10-model",
1211-
batch_size = 512,
1212-
learning_rate = 1e-4,
1213-
temperature_mode='constant',
1214-
temperature = 0.1,
1215-
max_iterations = 10, # TODO(user): to change to ~500-10000 depending on dataset size
1216-
#max_adapt_iterations = 10, # TODO(user): use and to change to ~100-500 if adapting
1217-
time_offsets = 10,
1218-
output_dimension = 8,
1219-
verbose = False
1210+
model_architecture = "offset10-model",
1211+
batch_size = 512,
1212+
learning_rate = 1e-4,
1213+
temperature_mode='constant',
1214+
temperature = 0.1,
1215+
max_iterations = 10, # TODO(user): to change to ~500-10000 depending on dataset size
1216+
#max_adapt_iterations = 10, # TODO(user): use and to change to ~100-500 if adapting
1217+
time_offsets = 10,
1218+
output_dimension = 8,
1219+
verbose = False
12201220
)
1221-
1221+
12221222
# 2. Load example data
12231223
neural_data = cebra.load_data(file="neural_data.npz", key="neural")
12241224
new_neural_data = cebra.load_data(file="neural_data.npz", key="new_neural")
12251225
continuous_label = cebra.load_data(file="auxiliary_behavior_data.h5", key="auxiliary_variables", columns=["continuous1", "continuous2", "continuous3"])
12261226
discrete_label = cebra.load_data(file="auxiliary_behavior_data.h5", key="auxiliary_variables", columns=["discrete"]).flatten()
1227-
1227+
1228+
12281229
assert neural_data.shape == (100, 3)
12291230
assert new_neural_data.shape == (100, 4)
12301231
assert discrete_label.shape == (100, )
12311232
assert continuous_label.shape == (100, 3)
1232-
1233-
# 3. Split data and labels
1234-
(
1235-
train_data,
1236-
valid_data,
1237-
train_discrete_label,
1238-
valid_discrete_label,
1239-
train_continuous_label,
1240-
valid_continuous_label,
1241-
) = train_test_split(neural_data,
1242-
discrete_label,
1243-
continuous_label,
1244-
test_size=0.3)
1245-
1233+
1234+
# 3. Split data and labels into train/validation
1235+
from sklearn.model_selection import train_test_split
1236+
1237+
split_idx = int(0.8 * len(neural_data))
1238+
# suggestion: 5%-20% depending on your dataset size; note that this splits the
1239+
# into an early and late part, which might not be ideal for your data/experiment!
1240+
# As a more involved alternative, consider e.g. a nested time-series split.
1241+
1242+
train_data = neural_data[:split_idx]
1243+
valid_data = neural_data[split_idx:]
1244+
1245+
train_continuous_label = continuous_label[:split_idx]
1246+
valid_continuous_label = continuous_label[split_idx:]
1247+
1248+
train_discrete_label = discrete_label[:split_idx]
1249+
valid_discrete_label = discrete_label[split_idx:]
1250+
12461251
# 4. Fit the model
12471252
# time contrastive learning
12481253
cebra_model.fit(train_data)
@@ -1252,33 +1257,36 @@ Putting all previous snippet examples together, we obtain the following pipeline
12521257
cebra_model.fit(train_data, train_continuous_label)
12531258
# mixed behavior contrastive learning
12541259
cebra_model.fit(train_data, train_discrete_label, train_continuous_label)
1255-
1260+
1261+
12561262
# 5. Save the model
12571263
tmp_file = Path(tempfile.gettempdir(), 'cebra.pt')
12581264
cebra_model.save(tmp_file)
1259-
1265+
12601266
# 6. Load the model and compute an embedding
12611267
cebra_model = cebra.CEBRA.load(tmp_file)
12621268
train_embedding = cebra_model.transform(train_data)
12631269
valid_embedding = cebra_model.transform(valid_data)
1264-
assert train_embedding.shape == (70, 8) # TODO(user): change to split ratio & output dim
1265-
assert valid_embedding.shape == (30, 8) # TODO(user): change to split ratio & output dim
1266-
1270+
1271+
assert train_embedding.shape == (80, 8) # TODO(user): change to split ratio & output dim
1272+
assert valid_embedding.shape == (20, 8) # TODO(user): change to split ratio & output dim
1273+
12671274
# 7. Evaluate the model performance (you can also check the train_data)
1268-
goodness_of_fit = cebra.sklearn.metrics.infonce_loss(cebra_model,
1275+
goodness_of_fit = cebra.sklearn.metrics.goodness_of_fit_score(cebra_model,
12691276
valid_data,
12701277
valid_discrete_label,
1271-
valid_continuous_label,
1272-
num_batches=5)
1273-
1278+
valid_continuous_label)
1279+
12741280
# 8. Adapt the model to a new session
12751281
cebra_model.fit(new_neural_data, adapt = True)
1276-
1282+
12771283
# 9. Decode discrete labels behavior from the embedding
12781284
decoder = cebra.KNNDecoder()
12791285
decoder.fit(train_embedding, train_discrete_label)
12801286
prediction = decoder.predict(valid_embedding)
1281-
assert prediction.shape == (30,)
1287+
assert prediction.shape == (20,)
1288+
1289+
12821290

12831291
👉 For further guidance on different/customized applications of CEBRA on your own data, refer to the ``examples/`` folder or to the full documentation folder ``docs/``.
12841292

0 commit comments

Comments
 (0)