Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation update: add readthedocs with sphinx #84

Merged
merged 37 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
220f357
add sphinx documentation code
Nov 15, 2024
bfa3319
import sphinx and add readthedocs config yaml
Nov 15, 2024
45c008f
run apidoc post build
Nov 15, 2024
63d4e3e
require sparse coding repo install for documentation generation
Nov 15, 2024
d8aab42
install package requirements to build docs
Nov 15, 2024
b4b3b3c
autogenerate rst files to import
Nov 15, 2024
0d5575a
make submodules importable
Nov 15, 2024
d098b88
change base from sparsecoding to modules
Nov 15, 2024
5bbe776
apidoc output in generated dir
Nov 15, 2024
7bb06a8
change modules to sparsecoding
Nov 15, 2024
707fa3c
docs are generated, however there are errors and when searching the g…
Nov 16, 2024
f00f625
change theme to rtd, generate API documentation with autodoc
Nov 20, 2024
cec25cb
change python 3 to 3.7
Nov 20, 2024
a876c38
upload of install, contributing, and quickstart docs. quickstart doc …
Nov 20, 2024
4426be3
add quick intro to library
Nov 20, 2024
e2332e0
add RCTN abbreviation
Nov 20, 2024
c82631c
add license info
Nov 20, 2024
5608d35
remove basic
Nov 20, 2024
4360d40
added structure of library. Note its not exacly correct. It reflects …
Nov 20, 2024
2f0cff9
rename transformations
Nov 23, 2024
3a3d0f0
delete unnecessary utils and init
Nov 23, 2024
7dc169a
remove import from data and add imports of transfrom tools
Nov 23, 2024
dbb2537
fixed typos and minor reword
Nov 23, 2024
cd22d5b
update readme to provide pointers to the readthedocs. delete obsolete…
Nov 23, 2024
86fa6a7
remove accidental horizontal lines
Nov 23, 2024
33c5437
add documentation badge to readme
Nov 28, 2024
b228aa8
flake8 docs
Nov 28, 2024
a13d921
upgrade python install for readthedocs to match that of setup.py
Jan 23, 2025
c6d1871
moved base class documentation above __init__ such that sphinx autodo…
Jan 23, 2025
3f1912d
modified documentation to adhear to structure used in rest of repository
Jan 24, 2025
240e8e9
make api documentation match new directory structure/file naming and …
Jan 24, 2025
dbf804a
flake
Jan 24, 2025
e58410c
again, moved triple quote docstring to after definition of class (as …
Jan 24, 2025
5c16977
update contributing documentation to new testing framework (pytest). …
Jan 28, 2025
f8429e6
Slight wording adjustment
Feb 3, 2025
454c7e8
comment syntax adjustmented for consistancy
Feb 3, 2025
5ce17a2
install instructions using pyproject.toml
Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 2

build:
os: ubuntu-24.04
tools:
python: "3.8"
jobs:
post_install:
- sphinx-apidoc -M -o docs/generated sparsecoding
- pip install -r requirements.txt

sphinx:
configuration: docs/conf.py

python:
install:
- requirements: docs/requirements.txt
44 changes: 25 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
# Sparse Coding
# RCTN SparseCoding Library

Reference sparse coding implementations for efficient learning and inference implemented in PyTorch with GPU support.
[![Documentation status](https://readthedocs.org/projects/sparsecoding/badge/)](
https://sparsecoding.readthedocs.io/)

## Features
`sparsecoding` is a Python library developed by UC Berkeley's [Redwood Center for Theoretical Neuroscience (RCTN)](https://redwood.berkeley.edu). It provides efficient, batched, and GPU-compatible [PyTorch](https://github.com/pytorch/pytorch) implementations for sparse coding related-algorithms, including dictionary learning, inference, and data processing.

Historically, sparse coding has been largely focused on learning sparse representations of images, and we provide visualization and transformation tools to work with such data. However, we structure the transformation, dictionary learning methods, and inference methods in a manner that is data-agnostic, making them applicable to a wide range of use cases.

### Dictionary Learning

* Repo currently includes classic patch-wise sparse coding dictionary learning.
## Features

### Implemented Inference Methods
- Check out our [Quickstart Guide](https://sparsecoding.readthedocs.io/en/latest/quickstart.html) for an overview and setup instructions.
- Refer to the [API Reference](https://sparsecoding.readthedocs.io/en/latest/api.html) for detailed usage of the library's features.

* Locally Competative Algorithm (LCA)
* Gradient Descent with Euler's method on Laplace Prior (Vanilla)
* Laplacian Scale Mixture (LSM)
* Iterative Shrinkage-threshold Algorithm (ISTA)
* Generic PyTorch minimization of arbitrary loss function (PyTorchOptimizer)

## Setup
belsten marked this conversation as resolved.
Show resolved Hide resolved

1. Clone the repo.
2. Navigate to the directory containing the repo directory.
3. Run `pip install -e ".[all]"`
4. Install the natural images dataset from this link: https://rctn.org/bruno/sparsenet/IMAGES.mat
5. Try running the demo notebook: `examples/sparse_coding.ipynb`
To install the library, follow these steps:

```bash
git clone https://github.com/rctn/sparsecoding.git
cd sparsecoding
pip install -e ".[all]"
```

Try running the demo notebook: `examples/sparse_coding.ipynb`.

For more detailed instructions, see our [Installation Guide](https://sparsecoding.readthedocs.io/en/latest/install.html).

Note: If you are using a Jupyter notebook and change a source file, you can either: 1) restart the Jupyter kernel, or 2) follow instructions [here](https://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html#autoreload).
Note: If you're using a Jupyter notebook and make changes to the source files, you can either:
* Restart the Jupyter kernel, or
* Use the autoreload extension as explained [here](https://ipython.readthedocs.io/en/stable/config/extensions/autoreload.html#autoreload).

## Contributing

See the [contributing](docs/contributing.md) document!
# Contributing
We welcome contributions! Please see our [contributing](https://sparsecoding.readthedocs.io/en/latest/contributing.html) for details on how to get involved.
67 changes: 67 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
=============
API Reference
=============

.. py:currentmodule:: sparsecoding

Dictionary learning models
--------------------------

.. automodule:: sparsecoding.models
:members:
:undoc-members:
:show-inheritance:


Inference methods
-----------------

.. automodule:: sparsecoding.inference
:members:
:undoc-members:
:show-inheritance:


Visualization tools
-------------------

.. automodule:: sparsecoding.visualization
:members:
:undoc-members:
:show-inheritance:


Priors
------

.. automodule:: sparsecoding.priors
:members:
:undoc-members:
:show-inheritance:


Datasets
--------

.. automodule:: sparsecoding.datasets
:members:
:undoc-members:
:show-inheritance:


Data transformations
--------------------

.. automodule:: sparsecoding.transforms.whiten
:members:
:undoc-members:
:show-inheritance:


Image transformations
---------------------

.. automodule:: sparsecoding.transforms.images
:members:
:undoc-members:
:show-inheritance:
44 changes: 44 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import os

project = 'RCTN sparsecoding'
copyright = '2024, RCTN'
author = 'RCTN'

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

extensions = [
'sphinx.ext.napoleon',
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
]

autodoc_default_options = {
'members': True,
'undoc-members': True,
'show-inheritance': True,
'inherited-members': False,
}

exclude_patterns = [
'**/test_*',
'**/*_test.py',
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'
html_baseurl = os.environ.get("READTHEDOCS_CANONICAL_URL", "/")
78 changes: 0 additions & 78 deletions docs/contributing.md

This file was deleted.

63 changes: 63 additions & 0 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
============
Contributing
============

We welcome all contributions to this project! Whether it’s reporting bugs, suggesting features,
fixing issues, or improving documentation, your input is invaluable.

Bug Reporting
-------------

If you encounter a bug, please report it by creating an issue on GitHub. Include as much detail as
possible to help us reproduce and fix the issue.

Adding Features or Fixing Bugs
------------------------------

If you’ve identified a new feature to add or a bug you can fix, follow these steps:

#. Clone the ``main`` branch.
belsten marked this conversation as resolved.
Show resolved Hide resolved
#. Create a new branch to work on your changes. Use a descriptive name for your branch, such as
``fix-issue-123`` or ``feature-add-logging``.
#. Use ``add``, ``commit``, and ``push`` to save your changes to the new branch.
#. Create a pull request (PR). See the "Submitting a Pull Request" section for more details.

Submitting a Pull Request
-------------------------
To ensure a smooth review process and maintain high code quality, follow these guidelines when
submitting a PR:

#. If applicable, write unit tests for your changes. We use the
`pytest <https://pytest.readthedocs.io/>`_ framework. Every Python module, extension module,
or subpackage in the sparsecoding package directory should have a corresponding ``test_<name>.py``
file. Pytest examines these files for test methods (named ``test*``) and test classes (named
``Test*``). Add your tests to the appropriate ``test_*.py`` (create this file if it doesn't
already exist).
#. Verify that all tests pass by running ``pytest sparsecoding/`` from the base repository directory.
#. Ensure your code adheres to the formatting guidelines specified in
`PEP8 <https://peps.python.org/pep-0008/>`_ and validated by
`flake8 <https://flake8.pycqa.org/en/latest/>`_.
#. Prepare a detailed and clear PR description:

* Summarize the purpose of the PR and the changes made.

* Include any relevant context, such as links to related issues or discussions.

* Specify testing steps or considerations for reviewers.

#. Submit your PR and assign reviewers as necessary.
#. Reviewers: Use squash and merge when merging the PR.

* Set the merge description to match the PR description.

* Squash commits into a single commit to maintain a clean project history.


Coding Style Guidelines
-----------------------

We follow the `NumPy documentation standards <https://numpydoc.readthedocs.io/en/latest/format.html>`_.

1. Format your code according to the `flake8 <https://flake8.pycqa.org/en/latest/>`_ standard.
2. Use underscores to separate words in non-class names (e.g., ``n_samples`` instead of ``nsamples``).
3. Avoid single-character variable names.
35 changes: 35 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. sparsecoding documentation master file, created by
sphinx-quickstart on Fri Nov 15 13:23:58 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

#######################################
RCTN sparsecoding library documentation
#######################################

`sparsecoding`_ is a python library developed by the `Redwood Center for
Theoretical Neuroscience (RCTN) <https://redwood.berkeley.edu>`_ which contains
performant `pytorch <https://github.com/pytorch/pytorch>`_ implementations of sparse coding dictionary learning,
inference, and data processing. It was written to be a useful research tool
for applying various sparse coding methods to data.

We believe that sharing code within the scientific community is an important
belsten marked this conversation as resolved.
Show resolved Hide resolved
part of science and we hope that the research community finds this library
useful.

.. _sparsecoding: https://github.com/rctn/sparsecoding/

.. toctree::
:maxdepth: 1
:numbered:

install
quickstart
api
contributing


License
-------

`sparsecoding`_ has a BSD-3-clause license, as found in the `LICENSE <https://github.com/rctn/sparsecoding/blob/main/LICENSE>`_ file.
19 changes: 19 additions & 0 deletions docs/install.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
============
Installation
belsten marked this conversation as resolved.
Show resolved Hide resolved
============

The quickest way to install the library is by cloning it directly from GitHub:

.. code:: bash

git clone https://github.com/rctn/sparsecoding.git
cd sparsecoding
pip install -e ".[all]"

The last command installs the dependencies required for the RCTN sparse coding library, including:

- ``numpy``
- ``scipy``
- ``matplotlib``
- ``torch``
- ``torchvision``
Loading