Commit e4bcb02f authored by valentin.emiya's avatar valentin.emiya
Browse files

import files

parent dd5b4a81
Pipeline #5032 passed with stages
in 1 minute and 12 seconds
*.py[co]
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
# Installer logs
pip-log.txt
# Mac OS X files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Sphinx stuff
docs/generated/
docs/build/
# jupyter notebook
.ipynb_checkpoints
# coverage
htmlcov
.coverage
# ide
.idea
.spyderproject
# Misc
.cache
.pytest_cache
# run the test suite
tests:
image: registry.gitlab.lis-lab.fr:5005/skmad-suite/madarrays/ubuntu:18.04
tags:
- docker
script:
- pip3 install --no-deps .
- pytest-3
# generate the documentation
pages:
image: registry.gitlab.lis-lab.fr:5005/skmad-suite/madarrays/ubuntu:18.04
tags:
- docker
only:
- master
script:
- pip3 install --no-deps .
- python3 setup.py build_sphinx
- cp -r build/sphinx/html public
artifacts:
paths:
- public
This diff is collapsed.
include *.txt
include *.rst
include VERSION
recursive-include doc *.rst *.py *.ipynb
include pomad/tests/*.py
prune doc/build
pomad
=====
pomad: PrObabilistic MAtrix Decompositions from Halko et al., 2011
Python implementation of algorithms from paper *Finding Structure
with Randomness: Probabilistic Algorithms for Constructing Approximate Matrix
Decompositions*, by N. Halko, P. G. Martinsson and J. A. Tropp, SIAM review,
53 (2), 2011.
Install
-------
Install the current release with ``pip``::
pip install pomad
For additional details, see doc/install.rst.
Usage
-----
See the `documentation <http://templates.pages.lis-lab.fr/pomad/>`_.
Bugs
----
Please report any bugs that you find through the `pomad GitLab project
<https://gitlab.lis-lab.fr/valentin.emiya/pomad/issues>`_.
You can also fork the repository and create a merge request.
Source code
-----------
The source code of pomad is available via its `GitLab project
<https://gitlab.lis-lab.fr/valentin.emiya/pomad>`_.
You can clone the git repository of the project using the command::
git clone git@gitlab.lis-lab.fr:valentin.emiya/pomad.git
Copyright © 2019-2020
---------------------
* `Laboratoire d'Informatique et Systèmes <http://www.lis-lab.fr/>`_
* `Université d'Aix-Marseille <http://www.univ-amu.fr/>`_
* `Centre National de la Recherche Scientifique <http://www.cnrs.fr/>`_
* `Université de Toulon <http://www.univ-tln.fr/>`_
Contributors
------------
* `Valentin Emiya <mailto:valentin.emiya@lis-lab.fr>`_
License
-------
Released under the GNU General Public License version 3 or later
(see `LICENSE.txt`).
pomad:0.1
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = python -m sphinx
PAPER =
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest epub
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " pickle to make pickle files"
@echo " epub to make an epub"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
@echo " gitwash to update the gitwash documentation"
clean:
-rm -rf build/*
-rm -rf ghpages_build
-rm -rf auto_examples modules
-rm -rf reference/generated reference/algorithms/generated reference/classes/generated reference/readwrite/generated
dist: html
test -d build/latex || make latex
make -C build/latex all-pdf
-rm -rf build/dist
(cd build/html; cp -r . ../../build/dist)
(cd build/dist && tar czf ../dist.tar.gz .)
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) build/html
@echo
@echo "Build finished. The HTML pages are in build/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) build/dirhtml
@echo
@echo "Build finished. The HTML pages are in build/dirhtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) build/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) build/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) build/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in build/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) build/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in build/qthelp, like this:"
@echo "# qcollectiongenerator build/qthelp/test.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile build/qthelp/test.qhc"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) build/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) build/latex
@echo
@echo "Build finished; the LaTeX files are in build/latex."
@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
"run these through (pdf)latex."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) build/changes
@echo
@echo "The overview file is in build/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) build/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in build/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) build/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in build/doctest/output.txt."
latexpdf: latex
@echo "Running LaTeX files through latexmk..."
$(MAKE) -C build/latex all-pdf
@echo "latexmk finished; the PDF files are in build/latex."
docs: clean html latexpdf
cp build/latex/networkx_reference.pdf build/html/_downloads/.
gitwash-update:
python ../tools/gitwash_dumper.py developer networkx \
--project-url=http://networkx.github.io \
--project-ml-url=http://groups.google.com/group/networkx-discuss/ \
--gitwash-url git@github.com:matthew-brett/gitwash.git
If you only want to get the documentation, note that a pre-built
version for the latest release is available
[online](http://templates.pages.lis-lab.fr/pomad/).
Sphinx is used to generate the API and reference documentation.
## Instructions to build the documentation
In addition to installing ``pomad`` and its dependencies, install the
Python packages needed to build the documentation by entering
```
pip install -r ../requirements/doc.txt
```
in the ``doc/`` directory.
To build the HTML documentation, run:
```
make html
```
in the ``doc/`` directory. This will generate a ``build/html`` subdirectory
containing the built documentation.
To build the PDF documentation, run:
```
make latexpdf
```
You will need to have Latex installed for this.
%% Cell type:markdown id: tags:
# Tutorial for `pomad`: PrObabilistic MAtrix Decompositions
%% Cell type:code id: tags:
``` python
%load_ext autoreload
%autoreload 2
```
%% Cell type:code id: tags:
``` python
%matplotlib inline
```
%% Cell type:code id: tags:
``` python
import numpy as np
import matplotlib.pyplot as plt
import scipy as sp
from scipy.sparse.linalg import aslinearoperator
```
%% Cell type:code id: tags:
``` python
from pomad.utils import build_test_matrix
from pomad.range_approximation import randomized_range_finder, adaptive_randomized_range_finder
```
%% Cell type:code id: tags:
``` python
# Test behavior of build_test_matrix
m = 29
n = 17
seed = 0
p_max = 5
rand_state = np.random.RandomState(seed)
A = rand_state.randn(m, n)
A = A / np.linalg.norm(A, ord=2)
M = A.copy()
for p in range(p_max):
U, s, Vh = np.linalg.svd(M)
plt.semilogy(s, label=r'$(A A^T)^{} \times A$'.format(p))
M = A @ A.T @ M
plt.title(r'Singular values of $(A A^T)^p \times A$')
plt.legend()
plt.grid()
plt.figure()
for p in range(p_max):
M = build_test_matrix(m, n, p=p, rand_state=seed)
U, s, Vh = np.linalg.svd(M)
plt.semilogy(s, label='p={}'.format(p))
plt.title('Similar result using build_test_matrix(m, n, p)')
plt.legend()
plt.grid()
```
%% Cell type:code id: tags:
``` python
# Approximation quality of randomized_range_finder(A, n_l=l)
m = 29
n = 23
p = 3
A = build_test_matrix(m, n, p=10, rand_state=0)
_, s, _ = np.linalg.svd(A)
for k in range(1, 18):
Q = randomized_range_finder(A, n_l=k+p)
print("k =", k, "p =", p,
"||A - Q @ Q.T @ A|| < s[k]?", np.linalg.norm(A - Q @ Q.T @ A, ord=2) < s[k],
"({} < {})".format(np.linalg.norm(A - Q @ Q.T @ A, ord=2), s[k]))
```
%% Cell type:code id: tags:
``` python
m = 290
n = 170
A = build_test_matrix(m, n, p=10, rand_state=0)
_, s, _ = np.linalg.svd(A)
plt.figure(figsize=(15,5))
plt.semilogy(s)
plt.grid()
for l in range(10):
tolerance = 10**-l
Q = adaptive_randomized_range_finder(A, tolerance=tolerance, r=5)
print(tolerance, np.linalg.norm(A-Q@Q.T@A, ord=2), Q.shape[1])
```
%% Cell type:code id: tags:
``` python
m = n = 345
A = build_test_matrix(m, n, p=10, rand_state=0)
Aop = aslinearoperator(A)
tolerance = 10**-5
%timeit -r2 -p2 Q = adaptive_randomized_range_finder(Aop, tolerance=tolerance, r=5)
A_rank = Q.shape[1]
print(A_rank)
%timeit -r2 -p2 QQ = randomized_range_finder(Aop, n_l=A_rank)
QQ = randomized_range_finder(Aop, n_l=A_rank)
%timeit -r2 -p2 np.linalg.svd(np.conjugate(QQ).T @ A)
%timeit -r2 -p2 ss=sp.sparse.linalg.svds(Aop, k=A_rank)
%timeit -r2 -p2 sss=np.linalg.svd(A)
```
%% Cell type:code id: tags:
``` python
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import os
from datetime import date
import pomad
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('../pomad/'))
# -- General configuration ------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'numpydoc',
'nbsphinx',
'IPython.sphinxext.ipython_console_highlighting',
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
# The encoding of source files.
source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = 'pomad'
author = 'V. Emiya'
copyright = '2019-{}, {}'.format(date.today().year, author)
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = pomad.__version__
# The full version, including alpha/beta/rc tags.
release = pomad.__version__.replace('_', '')
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
# Else, today_fmt is used as the format for a strftime call.
today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build', '**/test_*.rst', '**.ipynb_checkpoints']
# The reST default role (used for this markup: `text`) to use for all
# documents.
default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
modindex_common_prefix = []
# If true, keep warnings as "system message" paragraphs in the built documents.
keep_warnings = False
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'bizstyle'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
# html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
# html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
# html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = []
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
html_extra_path = []
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
html_last_updated_fmt = '%b %d, %Y'
# Custom sidebar templates, maps document names to template names.
html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
html_additional_pages = {}
# If false, no module index is generated.
html_domain_indices = True
# If false, no index is generated.
html_use_index = True
# If true, the index is split into individual pages for each letter.
html_split_index = False
# If true, links to the reST sources are added to the pages.
html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
html_file_suffix = None
# Language to be used for generating the HTML full-text search index.
# Sphinx supports the following languages:
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja'
# 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr'
html_search_language = 'en'
# A dictionary with options for the search language support, empty by default.
# Now only 'ja' uses this config value
html_search_options = {'type': 'default'}
# The name of a javascript file (relative to the configuration directory) that
# implements a search results scorer. If empty, the default will be used.
html_search_scorer = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'pomaddoc'
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
'papersize': 'a4paper',
# The font size ('10pt', '11pt' or '12pt').
'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
'preamble': '',
# Latex figure (float) alignment
'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'pomad.tex', 'pomad Documentation', author, 'manual'),