PyProximal - scalable convex optimization in Python

PyProximal - scalable convex optimization in Python - Published in JOSS (2024)

https://github.com/pylops/pyproximal

Science Score: 59.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 5 DOI reference(s) in README
  • Academic publication links
    Links to: joss.theoj.org
  • Committers with academic emails
    2 of 11 committers (18.2%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.9%) to scientific vocabulary

Keywords

inverse-problems linear-algebra proximal-algorithms python
Last synced: 6 months ago · JSON representation

Repository

PyProximal – Proximal Operators and Algorithms in Python

Basic Info
Statistics
  • Stars: 72
  • Watchers: 1
  • Forks: 18
  • Open Issues: 11
  • Releases: 11
Topics
inverse-problems linear-algebra proximal-algorithms python
Created about 5 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License

README.md

PyProximal

PyPI version AzureDevOps Status GithubAction Status Documentation Status OS-support Slack Status DOI

Objective

This Python library provides all the needed building blocks for solving non-smooth convex optimization problems using the so-called proximal algorithms.

Whereas gradient based methods are first-order iterative optimization algorithms for solving unconstrained, smooth optimization problems, proximal algorithms can be viewed as an analogous tool for non-smooth and possibly constrained versions of these problems. Such algorithms sit at a higher level of abstraction than classical algorithms like Steepest descent or Newton’s method and require a basic operation to be performed at each iteration: the evaluation of the so-called proximal operator of the functional to be optimized.

Whilst evaluating a proximal operator does itself require solving a convex optimization problem, these subproblems often admit closed form solutions or can be solved very quickly with ad-hoc specialized methods. Several of such proximal operators are therefore implemented in this library.

Here is a simple example showing how to compute the proximal operator of the L1 norm of a vector: ```python import numpy as np from pyproximal import L1

l1 = L1(sigma=1.) x = np.arange(-5, 5, 0.1) xp = l1.prox(x, 1) ` and how this can be used to solve a basic denoising problem of the form: min ||x - y||2^2 + ||Dx||1``:

```python import numpy as np from pylops import FirstDerivative from pyproximal import L1, L2 from pyproximal.optimization.primal import LinearizedADMM

np.random.seed(1)

Create noisy data

nx = 101 x = np.zeros(nx) x[:nx//2] = 10 x[nx//2:3*nx//4] = -5 n = np.random.normal(0, 2, nx) y = x + n

Define functionals

l2 = L2(b=y) l1 = L1(sigma=5.) Dop = FirstDerivative(nx, edge=True, kind='backward')

Solve functional with L-ADMM

L = np.real((Dop.H * Dop).eigs(neigs=1, which='LM')[0]) tau = 1. mu = 0.99 * tau / L xladmm, _ = LinearizedADMM(l2, l1, Dop, tau=tau, mu=mu, x0=np.zeros_like(x), niter=200) ```

Why another library for proximal algorithms?

Several other projects in the Python ecosystem provide implementations of proximal operators and/or algorithms, which present some clear overlap with this project.

A (possibly not exhaustive) list of other projects is:

  • http://proximity-operator.net
  • https://github.com/ganguli-lab/proxalgs
  • https://github.com/pmelchior/proxmin
  • https://github.com/comp-imaging/ProxImaL
  • https://github.com/pyxu-org/pyxu

All of these projects are self-contained, meaning that they implement both proximal and linear operators as needed to solve a variety of problems in different areas of science.

The main difference with PyProximal lies in the fact that we decide not to intertangle linear and proximal operators within the same library. We leverage the extensive set of linear operators provided by the PyLops project and focus only on the proximal part of the problem. This makes the codebase more concise, and easier to understand and extend. Moreover many of the problems that are solved in PyLops can now be also solved by means of proximal algorithms!

Project structure

This repository is organized as follows: * pyproximal: python library containing various orthogonal projections, proximial operators, and solvers * pytests: set of pytests * testdata: sample datasets used in pytests and documentation * docs: sphinx documentation * examples: set of python script examples for each proximal operator to be embedded in documentation using sphinx-gallery * tutorials: set of python script tutorials to be embedded in documentation using sphinx-gallery

Getting started

You need Python 3.8 or greater.

Note: Versions prior to v0.3.0 work also with Python 3.6 or greater, however they require scipy version to be lower than v1.8.0.

To get the most out of PyLops straight out of the box, we recommend conda to install PyLops: bash conda install -c conda-forge pyproximal

From PyPi

You can also install pyproximal with pip: bash pip install pyproximal

From Github

Finally, you can also directly install from the main branch (although this is not recommended)

pip install git+https://git@github.com/PyLops/pyproximal.git@main

Contributing

Feel like contributing to the project? Adding new operators or tutorial?

We advise using the Anaconda Python distribution to ensure that all the dependencies are installed via the Conda package manager. Follow the following instructions and read carefully the CONTRIBUTING file before getting started.

1. Fork and clone the repository

Execute the following command in your terminal:

git clone https://github.com/your_name_here/pyproximal.git

2. Install PyLops in a new Conda environment

To ensure that further development of PyLops is performed within the same environment (i.e., same dependencies) as that defined by requirements-dev.txt or environment-dev.yml files, we suggest to work off a new Conda enviroment.

The first time you clone the repository run the following command: make dev-install_conda To ensure that everything has been setup correctly, run tests: make tests Make sure no tests fail, this guarantees that the installation has been successfull.

Remember to always activate the conda environment every time you open a new terminal by typing: source activate pyproximal

Documentation

The official documentation of PyProximal is available here.

Moreover, if you have installed PyProximal using the developer environment you can also build the documentation locally by typing the following command: make doc Once the documentation is created, you can make any change to the source code and rebuild the documentation by simply typing make docupdate Note that if a new example or tutorial is created (and if any change is made to a previously available example or tutorial) you are required to rebuild the entire documentation before your changes will be visible.

Citing

When using PyProximal in scientific publications, please cite the following paper:

  • Ravasi M, Örnhag M. V., Luiken N., Leblanc O. and Uruñuela E., 2024, PyProximal - scalable convex optimization in Python, Journal of Open Source Software, 9(95), 6326. doi: 10.21105/joss.06326 (link)

Contributors

  • Matteo Ravasi, mrava87
  • Nick Luiken, NickLuiken
  • Eneko Uruñuela, eurunuela
  • Marcus Valtonen Örnhag, marcusvaltonen
  • Olivier Leblanc, olivierleblanc
  • Toru Tamaki, tttamaki

Owner

  • Name: PyLops
  • Login: PyLops
  • Kind: organization

Matrix-Free linear algebra and optimization in Python

GitHub Events

Total
  • Create event: 1
  • Release event: 1
  • Issues event: 4
  • Watch event: 18
  • Issue comment event: 15
  • Push event: 23
  • Pull request review event: 1
  • Pull request event: 47
  • Fork event: 5
Last Year
  • Create event: 1
  • Release event: 1
  • Issues event: 4
  • Watch event: 18
  • Issue comment event: 15
  • Push event: 23
  • Pull request review event: 1
  • Pull request event: 47
  • Fork event: 5

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 249
  • Total Committers: 11
  • Avg Commits per committer: 22.636
  • Development Distribution Score (DDS): 0.205
Past Year
  • Commits: 25
  • Committers: 2
  • Avg Commits per committer: 12.5
  • Development Distribution Score (DDS): 0.04
Top Committers
Name Email Commits
mrava87 m****i@g****m 198
Marcus Valtonen Örnhag m****n@g****m 31
Olivier Leblanc o****c@u****e 4
NickLuiken n****1@g****m 4
Salman Naqvi s****i@a****m 4
Eneko Uruñuela e****a@i****m 2
Nick n****n@u****l 2
Toru Tamaki t****u@n****p 1
Olivier Leblanc 5****3 1
Niru Maheswaranathan n****u@h****m 1
Matteo Ravasi r****m@k****a 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 13
  • Total pull requests: 141
  • Average time to close issues: 16 days
  • Average time to close pull requests: about 16 hours
  • Total issue authors: 6
  • Total pull request authors: 6
  • Average comments per issue: 3.0
  • Average comments per pull request: 0.23
  • Merged pull requests: 122
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 4
  • Pull requests: 44
  • Average time to close issues: 10 days
  • Average time to close pull requests: about 10 hours
  • Issue authors: 2
  • Pull request authors: 2
  • Average comments per issue: 2.75
  • Average comments per pull request: 0.16
  • Merged pull requests: 36
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • mrava87 (6)
  • nwu63 (2)
  • jameschapman19 (2)
  • tttamaki (1)
  • AnouarITI (1)
  • ewu63 (1)
Pull Request Authors
  • mrava87 (130)
  • tttamaki (6)
  • nirum (2)
  • marcusvaltonen (1)
  • shnaqvi (1)
  • NickLuiken (1)
Top Labels
Issue Labels
enhancement (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 600 last-month
  • Total dependent packages: 3
  • Total dependent repositories: 3
  • Total versions: 11
  • Total maintainers: 1
pypi.org: pyproximal

Python library implementing proximal operators to solve non-smooth, constrained convex problems with proximal algorithms

  • Documentation: https://pyproximal.readthedocs.io/
  • License: GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.
  • Latest release: 0.10.0
    published about 1 year ago
  • Versions: 11
  • Dependent Packages: 3
  • Dependent Repositories: 3
  • Downloads: 600 Last month
Rankings
Dependent packages count: 2.4%
Dependent repos count: 8.9%
Average: 9.1%
Downloads: 16.1%
Maintainers (1)
Last synced: 6 months ago

Dependencies

requirements-dev.txt pypi
  • Sphinx ==4.2.0 development
  • bm3d * development
  • docutils <0.18 development
  • image * development
  • ipython * development
  • matplotlib * development
  • nbsphinx * development
  • numba * development
  • numpy >=1.15.0 development
  • numpydoc * development
  • pylops * development
  • pytest * development
  • pytest-runner * development
  • scikit-image * development
  • scipy >=1.8.0 development
  • setuptools_scm * development
  • sphinx-gallery * development
  • sphinx-rtd-theme * development
.github/workflows/build.yaml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
.github/workflows/deploy.yaml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
  • pypa/gh-action-pypi-publish 27b31702a0e7fc50959f5ad993c78deac1bdfc29 composite
pyproject.toml pypi
requirements.txt pypi
environment.yml pypi