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

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
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
58e33f4
add sphinx documentation code
Nov 15, 2024
30b3e58
import sphinx and add readthedocs config yaml
Nov 15, 2024
0fbda9c
run apidoc post build
Nov 15, 2024
ec948cc
require sparse coding repo install for documentation generation
Nov 15, 2024
72ac485
install package requirements to build docs
Nov 15, 2024
0441453
autogenerate rst files to import
Nov 15, 2024
ade75a6
make submodules importable
Nov 15, 2024
33af89f
change base from sparsecoding to modules
Nov 15, 2024
aae2b05
apidoc output in generated dir
Nov 15, 2024
4ada2ff
change modules to sparsecoding
Nov 15, 2024
24615e4
docs are generated, however there are errors and when searching the g…
Nov 16, 2024
5aa550f
change theme to rtd, generate API documentation with autodoc
Nov 20, 2024
56c4480
change python 3 to 3.7
Nov 20, 2024
e2bb9d4
upload of install, contributing, and quickstart docs. quickstart doc …
Nov 20, 2024
491bda1
add quick intro to library
Nov 20, 2024
c6c201f
add RCTN abbreviation
Nov 20, 2024
cc0cb9a
add license info
Nov 20, 2024
9b5c577
remove basic
Nov 20, 2024
573c39e
minor formating edits to fix sphinx formatting warnings
Nov 20, 2024
794a21f
added structure of library. Note its not exacly correct. It reflects …
Nov 20, 2024
fc67721
rename transformations
Nov 23, 2024
139dea9
delete unnecessary utils and init
Nov 23, 2024
2426858
remove import from data and add imports of transfrom tools
Nov 23, 2024
5b00462
fixed typos and minor reword
Nov 23, 2024
222e1ab
update readme to provide pointers to the readthedocs. delete obsolete…
Nov 23, 2024
cdf20b3
remove accidental horizontal lines
Nov 23, 2024
4b19a42
add documentation badge to readme
Nov 28, 2024
a33b1e0
flake8 docs
Nov 28, 2024
527c7c5
merge with main
Jan 23, 2025
4ff88d3
upgrade python install for readthedocs to match that of setup.py
Jan 23, 2025
8d37188
delete inference.py as its now split into .pys in the inference direc…
Jan 23, 2025
ef1ec6b
moved base class documentation above __init__ such that sphinx autodo…
Jan 23, 2025
bdc30eb
modified documentation to adhear to structure used in rest of repository
Jan 24, 2025
d555ef3
make api documentation match new directory structure/file naming and …
Jan 24, 2025
71c0743
flake
Jan 24, 2025
b57908f
again, moved triple quote docstring to after definition of class (as …
Jan 24, 2025
7c5062e
update contributing documentation to new testing framework (pytest). …
Jan 28, 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
51 changes: 32 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
# Sparse Coding
Reference sparse coding implementations for efficient learning and inference implemented in PyTorch with GPU support.
# RCTN SparseCoding Library

## Dictionary Learning
* Repo currently includes classic patch-wise sparse coding dictionary learning.
[![Documentation status](https://readthedocs.org/projects/sparsecoding/badge/)](
https://sparsecoding.readthedocs.io/)

## Implemented Inference Methods
* 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)
`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.

# Setup
1. Clone the repo.
2. Navigate to the directory containing the repo directory.
3. Run `pip install -e sparsecoding`
4. Navigate into the repo and install the requirements using `pip install -r requirements.txt`
5. Install the natural images dataset from this link: https://rctn.org/bruno/sparsenet/IMAGES.mat
6. Try running the demo notebook: `examples/sparse_coding.ipynb`
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’ve tried to 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits:

  • add comma after "representations of images"
  • remove the "we've tried" -> "However, we structure the transformations, dictionary..."


We believe that sharing code within the scientific community is an important part of science and we hope that the research community finds this library useful.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can remove this paragraph?
regardless i think we'll edit wording as we go so not too big of a deal for now



## Features

- 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.


## Setup
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should match whatever changes are made in #91


To install the library, follow these steps:

```bash
git clone https://github.com/rctn/sparsecoding.git
cd sparsecoding
pip install -e .
pip install -r requirements.txt
```

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

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).

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).

# Contributing
See the [contributing](docs/contributing.md) document!
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry this wouldn't have been an issue if i were more prompt in reviewing but will need to update with changes from #89

#. 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete?

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.
20 changes: 20 additions & 0 deletions docs/install.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
============
Installation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as readme, update with #91

============

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 sparsecoding
pip install -r requirements.txt

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

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