suppy 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. suppy-0.1.0/.gitattributes +2 -0
  2. suppy-0.1.0/.gitignore +167 -0
  3. suppy-0.1.0/.gitlab-ci.yml +125 -0
  4. suppy-0.1.0/.pre-commit-config.yaml +16 -0
  5. suppy-0.1.0/CHANGELOG.md +10 -0
  6. suppy-0.1.0/CONTRIBUTING.md +23 -0
  7. suppy-0.1.0/LICENSE +11 -0
  8. suppy-0.1.0/PKG-INFO +142 -0
  9. suppy-0.1.0/README.md +117 -0
  10. suppy-0.1.0/docs/Makefile +20 -0
  11. suppy-0.1.0/docs/algorithms.rst +29 -0
  12. suppy-0.1.0/docs/api/feasibility.rst +89 -0
  13. suppy-0.1.0/docs/api/index.rst +26 -0
  14. suppy-0.1.0/docs/api/perturbations.rst +25 -0
  15. suppy-0.1.0/docs/api/projections.rst +56 -0
  16. suppy-0.1.0/docs/api/superiorization.rst +10 -0
  17. suppy-0.1.0/docs/api/utils.rst +32 -0
  18. suppy-0.1.0/docs/conf.py +72 -0
  19. suppy-0.1.0/docs/help/help.rst +13 -0
  20. suppy-0.1.0/docs/index.rst +85 -0
  21. suppy-0.1.0/docs/installation/installation.rst +22 -0
  22. suppy-0.1.0/docs/make.bat +35 -0
  23. suppy-0.1.0/docs/user_guide/feasibility.rst +5 -0
  24. suppy-0.1.0/docs/user_guide/general_intro.rst +93 -0
  25. suppy-0.1.0/docs/user_guide/projection_methods.rst +69 -0
  26. suppy-0.1.0/docs/user_guide/projections.rst +162 -0
  27. suppy-0.1.0/docs/user_guide/superiorization.rst +4 -0
  28. suppy-0.1.0/examples/Projections.ipynb +1009 -0
  29. suppy-0.1.0/examples/Superiorization.ipynb +437 -0
  30. suppy-0.1.0/logo.png +0 -0
  31. suppy-0.1.0/pyproject.toml +71 -0
  32. suppy-0.1.0/suppy/__init__.py +1 -0
  33. suppy-0.1.0/suppy/algorithms/__init__.py +0 -0
  34. suppy-0.1.0/suppy/algorithms/level_set.py +106 -0
  35. suppy-0.1.0/suppy/algorithms/projected_subgradient.py +33 -0
  36. suppy-0.1.0/suppy/feasibility/__init__.py +25 -0
  37. suppy-0.1.0/suppy/feasibility/_bands/_ams_algorithms.py +494 -0
  38. suppy-0.1.0/suppy/feasibility/_bands/_arm_algorithms.py +371 -0
  39. suppy-0.1.0/suppy/feasibility/_bands/_art3_algorithms.py +297 -0
  40. suppy-0.1.0/suppy/feasibility/_halfspaces/_ams_algorithms.py +494 -0
  41. suppy-0.1.0/suppy/feasibility/_linear_algorithms.py +346 -0
  42. suppy-0.1.0/suppy/feasibility/_split_algorithms.py +400 -0
  43. suppy-0.1.0/suppy/perturbations/__init__.py +3 -0
  44. suppy-0.1.0/suppy/perturbations/_base.py +222 -0
  45. suppy-0.1.0/suppy/projections/__init__.py +34 -0
  46. suppy-0.1.0/suppy/projections/_basic_projections.py +904 -0
  47. suppy-0.1.0/suppy/projections/_projection_methods.py +530 -0
  48. suppy-0.1.0/suppy/projections/_projections.py +183 -0
  49. suppy-0.1.0/suppy/projections/_subgradient_projections.py +222 -0
  50. suppy-0.1.0/suppy/superiorization/__init__.py +4 -0
  51. suppy-0.1.0/suppy/superiorization/_deprecated/_sup.py +461 -0
  52. suppy-0.1.0/suppy/superiorization/_deprecated/sup.py +529 -0
  53. suppy-0.1.0/suppy/superiorization/_deprecated/sup_new.py +643 -0
  54. suppy-0.1.0/suppy/superiorization/_split_sup.py +283 -0
  55. suppy-0.1.0/suppy/superiorization/_standard_sup.py +293 -0
  56. suppy-0.1.0/suppy/superiorization/_sup.py +43 -0
  57. suppy-0.1.0/suppy/utils/__init__.py +9 -0
  58. suppy-0.1.0/suppy/utils/_array_helper.py +225 -0
  59. suppy-0.1.0/suppy/utils/_bounds.py +210 -0
  60. suppy-0.1.0/suppy/utils/_calc_DVH.py +25 -0
  61. suppy-0.1.0/suppy/utils/_decorators.py +42 -0
  62. suppy-0.1.0/suppy/utils/_func_wrapper.py +33 -0
  63. suppy-0.1.0/suppy/utils/plot.py +159 -0
  64. suppy-0.1.0/tests/.gitkeep +0 -0
  65. suppy-0.1.0/tests/__init__.py +0 -0
  66. suppy-0.1.0/tests/feasibility/LinearAlgorithms/AMS/__init__.py +0 -0
  67. suppy-0.1.0/tests/feasibility/LinearAlgorithms/AMS/test_BIPAMS.py +300 -0
  68. suppy-0.1.0/tests/feasibility/LinearAlgorithms/AMS/test_SequentialAMS.py +327 -0
  69. suppy-0.1.0/tests/feasibility/LinearAlgorithms/AMS/test_SequentialWeightedAMS.py +197 -0
  70. suppy-0.1.0/tests/feasibility/LinearAlgorithms/AMS/test_SimultaneousAMS.py +265 -0
  71. suppy-0.1.0/tests/feasibility/LinearAlgorithms/AMS/test_StringAveragedAMS.py +228 -0
  72. suppy-0.1.0/tests/feasibility/LinearAlgorithms/ARM/__init__.py +0 -0
  73. suppy-0.1.0/tests/feasibility/LinearAlgorithms/ARM/test_SequentialARM.py +107 -0
  74. suppy-0.1.0/tests/feasibility/LinearAlgorithms/ARM/test_SimultaneousARM.py +124 -0
  75. suppy-0.1.0/tests/feasibility/LinearAlgorithms/ARM/test_StringAveragedARM.py +191 -0
  76. suppy-0.1.0/tests/feasibility/LinearAlgorithms/ART3/test_SequentialART3.py +164 -0
  77. suppy-0.1.0/tests/feasibility/LinearAlgorithms/ART3/test_SimultaneousART3.py +172 -0
  78. suppy-0.1.0/tests/feasibility/LinearAlgorithms/__init__.py +0 -0
  79. suppy-0.1.0/tests/feasibility/SplitAlgorithms/test_CQ.py +75 -0
  80. suppy-0.1.0/tests/feasibility/__inity__.py +0 -0
  81. suppy-0.1.0/tests/feasibility/projections/__init__.py +0 -0
  82. suppy-0.1.0/tests/feasibility/projections/test_EUD_projection.py +39 -0
  83. suppy-0.1.0/tests/feasibility/projections/test_basic_projections.py +380 -0
  84. suppy-0.1.0/tests/feasibility/projections/test_projection_methods.py +168 -0
  85. suppy-0.1.0/tests/feasibility/projections/test_subgradient_projecton.py +170 -0
  86. suppy-0.1.0/tests/perturbations/__init__.py +0 -0
  87. suppy-0.1.0/tests/perturbations/test_perturbations.py +105 -0
  88. suppy-0.1.0/tests/superiorization/__init__.py +0 -0
  89. suppy-0.1.0/tests/superiorization/test_standard_superiorization_new.py +156 -0
  90. suppy-0.1.0/tests/utils/test_array_helper.py +38 -0
  91. suppy-0.1.0/tests/utils/test_bounds.py +38 -0
  92. suppy-0.1.0/tests/utils/test_decorators.py +63 -0
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
suppy-0.1.0/.gitignore ADDED
@@ -0,0 +1,167 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ Testing/*.mat
30
+ Testing/_ignore/
31
+
32
+ # PyInstaller
33
+ # Usually these files are written by a python script from a template
34
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
35
+ *.manifest
36
+ *.spec
37
+
38
+ # Installer logs
39
+ pip-log.txt
40
+ pip-delete-this-directory.txt
41
+
42
+ # Unit test / coverage reports
43
+ htmlcov/
44
+ .tox/
45
+ .nox/
46
+ .coverage
47
+ .coverage.*
48
+ .cache
49
+ nosetests.xml
50
+ coverage.xml
51
+ *.cover
52
+ *.py,cover
53
+ .hypothesis/
54
+ .pytest_cache/
55
+ cover/
56
+
57
+ # Translations
58
+ *.mo
59
+ *.pot
60
+
61
+ # Django stuff:
62
+ *.log
63
+ local_settings.py
64
+ db.sqlite3
65
+ db.sqlite3-journal
66
+
67
+ # Flask stuff:
68
+ instance/
69
+ .webassets-cache
70
+
71
+ # Scrapy stuff:
72
+ .scrapy
73
+
74
+ # Sphinx documentation
75
+ docs/_build/
76
+
77
+ # PyBuilder
78
+ .pybuilder/
79
+ target/
80
+
81
+ # Jupyter Notebook
82
+ .ipynb_checkpoints
83
+
84
+ # IPython
85
+ profile_default/
86
+ ipython_config.py
87
+
88
+ # pyenv
89
+ # For a library or package, you might want to ignore these files since the code is
90
+ # intended to run in multiple environments; otherwise, check them in:
91
+ # .python-version
92
+
93
+ # pipenv
94
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
96
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
97
+ # install all needed dependencies.
98
+ #Pipfile.lock
99
+
100
+ # poetry
101
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
102
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
103
+ # commonly ignored for libraries.
104
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
105
+ #poetry.lock
106
+
107
+ # pdm
108
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
109
+ #pdm.lock
110
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
111
+ # in version control.
112
+ # https://pdm.fming.dev/#use-with-ide
113
+ .pdm.toml
114
+
115
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116
+ __pypackages__/
117
+
118
+ # Celery stuff
119
+ celerybeat-schedule
120
+ celerybeat.pid
121
+
122
+ # SageMath parsed files
123
+ *.sage.py
124
+
125
+ # Environments
126
+ .env
127
+ .venv
128
+ env/
129
+ venv/
130
+ ENV/
131
+ env.bak/
132
+ venv.bak/
133
+
134
+ # Spyder project settings
135
+ .spyderproject
136
+ .spyproject
137
+
138
+ # Rope project settings
139
+ .ropeproject
140
+
141
+ # mkdocs documentation
142
+ /site
143
+
144
+ # mypy
145
+ .mypy_cache/
146
+ .dmypy.json
147
+ dmypy.json
148
+
149
+ # Pyre type checker
150
+ .pyre/
151
+
152
+ # pytype static type analyzer
153
+ .pytype/
154
+
155
+ # Cython debug symbols
156
+ cython_debug/
157
+
158
+ # PyCharm
159
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
162
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
163
+ #.idea/
164
+
165
+
166
+ # VsCode
167
+ .vscode/
@@ -0,0 +1,125 @@
1
+ #image: python:3.10-alpine3.19
2
+ image: python:3.11.9-slim-bookworm
3
+
4
+ variables: # Change pip's cache directory to be inside the project directory since we can only cache local items.
5
+ PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip/"
6
+
7
+ stages:
8
+ - build
9
+ - test
10
+ - docs
11
+ - deploy
12
+
13
+ # before_script:
14
+ # - apk add --no-cache alpine-sdk g++ hdf5-dev llvm14-dev linux-headers
15
+ # - apt-get update
16
+
17
+ build:
18
+ stage: build
19
+ script:
20
+ - python3 -m venv .venv
21
+ - source .venv/bin/activate
22
+ # - LLVM_CONFIG=/usr/bin/llvm14-config pip install llvmlite
23
+ - pip install -e .
24
+ cache:
25
+ key: "cache-$CI_COMMIT_REF_SLUG"
26
+ paths:
27
+ - .venv/
28
+ - .cache/pip/
29
+ policy: pull-push
30
+
31
+ # TODO: as soon as the COS cache on gitlab works, separate into three jobs running in parallel to the tests
32
+ lint:
33
+ stage: test
34
+ cache:
35
+ key: "cache-$CI_COMMIT_REF_SLUG"
36
+ paths:
37
+ - .venv/
38
+ - .cache/pip/
39
+ policy: pull
40
+ script:
41
+ - source .venv/bin/activate
42
+ - pip install flake8-gl-codeclimate Flake8-pyproject black pylint
43
+ - return_code=0
44
+ - flake8 --format gl-codeclimate --output-file gl-code-quality-report.json --toml-config ./pyproject.toml || return_code=$(($return_code + $?))
45
+ - black --check . 2> >(tee black-report.txt >&2) || return_code=$(($return_code + $?))
46
+ - pylint --output-format=json:pylint.txt,colorized suppy suppy.py || return_code=$(($return_code + $?))
47
+ - exit $return_code
48
+ artifacts:
49
+ reports:
50
+ codequality: gl-code-quality-report.json
51
+ paths:
52
+ - black-report.txt
53
+ - pylint.txt
54
+ when: always
55
+
56
+ allow_failure: true
57
+
58
+
59
+ tests:
60
+ stage: test
61
+ cache:
62
+ key: "cache-$CI_COMMIT_REF_SLUG"
63
+ paths:
64
+ - .venv/
65
+ - .cache/pip/
66
+ policy: pull
67
+ script:
68
+ - source .venv/bin/activate
69
+ - pip install coverage pytest pytest-cov
70
+ - pytest tests --junitxml=.testreports/report.xml --cov=suppy --cov-report term --cov-report xml:.testreports/coverage.xml --cov-report html:.testreports/html
71
+ artifacts:
72
+ when: always
73
+ reports:
74
+ coverage_report:
75
+ coverage_format: cobertura
76
+ path: .testreports/coverage.xml
77
+ junit: .testreports/report.xml
78
+ paths:
79
+ - .testreports/html
80
+ - .testreports/coverage.xml
81
+ - .testreports/report.xml
82
+ coverage: '/TOTAL.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
83
+
84
+
85
+ docs:
86
+ stage: docs
87
+ cache:
88
+ key: "cache-$CI_COMMIT_REF_SLUG"
89
+ paths:
90
+ - .venv/
91
+ - .cache/pip/
92
+ policy: pull
93
+ script:
94
+ - source .venv/bin/activate
95
+ - pip install sphinx
96
+ - pip install numpydoc
97
+ - pip install pydata-sphinx-theme
98
+ - pip install sphinx-autodoc-typehints
99
+ - sphinx-apidoc -o docs ./suppy
100
+ - sphinx-build docs .doc
101
+ artifacts:
102
+ when: always
103
+ paths:
104
+ - .doc
105
+ only:
106
+ - main # Adjust this to the branch you want to build on
107
+
108
+
109
+ pages:
110
+ stage: deploy
111
+ dependencies:
112
+ - tests
113
+ - docs
114
+ script:
115
+ - mv .doc public/
116
+
117
+ artifacts:
118
+ paths:
119
+ - public
120
+ expire_in: 30 days
121
+ only:
122
+ - main
123
+
124
+
125
+
@@ -0,0 +1,16 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v2.3.0
4
+ hooks:
5
+ - id: check-yaml
6
+ - id: end-of-file-fixer
7
+ - id: trailing-whitespace
8
+ - repo: https://github.com/psf/black
9
+ rev: 22.10.0
10
+ hooks:
11
+ - id: black
12
+
13
+ - repo: https://github.com/DanielNoord/pydocstringformatter
14
+ rev: v0.7.3
15
+ hooks:
16
+ - id: pydocstringformatter
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
4
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
+
6
+ ## [0.0.1] - 2024-12-5
7
+
8
+ ### Added
9
+
10
+ - Initial release
@@ -0,0 +1,23 @@
1
+ Contributing
2
+ ============
3
+
4
+ If you would like to contribute to this repository please create a fork and open a pull request with your changes.
5
+ After cloning the repository run
6
+
7
+ ```
8
+ pip install -e.[dev]
9
+ ```
10
+
11
+ from the repositories home directory to install the required packages for developing.
12
+
13
+ Style conventions
14
+ =================
15
+
16
+ ``suppy`` follows [PEP 8](https://peps.python.org/pep-0008/) for naming and [numpydoc](https://numpydoc.readthedocs.io/en/latest/format.html) for docstring convention.
17
+ To ensure uniform code we use pre-commit hooks that are managed by the pre-commit library.
18
+ For setup run:
19
+
20
+ ```
21
+ pre-commit install.
22
+ ```
23
+ from the home of the repository.
suppy-0.1.0/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2024 Tobias Becher
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
suppy-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.3
2
+ Name: suppy
3
+ Version: 0.1.0
4
+ Summary: Library for superiorization algorithms
5
+ Author: Tobias Becher
6
+ License: BSD-3-Clause
7
+ Classifier: License :: OSI Approved :: BSD License
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Python: >=3.8
11
+ Requires-Dist: matplotlib
12
+ Requires-Dist: numpy
13
+ Requires-Dist: scipy
14
+ Provides-Extra: dev
15
+ Requires-Dist: coverage; extra == 'dev'
16
+ Requires-Dist: pre-commit; extra == 'dev'
17
+ Requires-Dist: pydata-sphinx-theme; extra == 'dev'
18
+ Requires-Dist: pytest; extra == 'dev'
19
+ Requires-Dist: pytest-cov; extra == 'dev'
20
+ Requires-Dist: sphinx; extra == 'dev'
21
+ Requires-Dist: sphinx-design; extra == 'dev'
22
+ Provides-Extra: test
23
+ Requires-Dist: pytest; extra == 'test'
24
+ Description-Content-Type: text/markdown
25
+
26
+ # suppy - Python superiorization library
27
+
28
+ `suppy` is a native python library for quick setup and evaluation of superiorzation algorithms.
29
+ The superiorization method uses underlying feasibility seeking algorithms, i.e. algorithms that have the goal of finding a point in the intersection of convex sets(
30
+ $
31
+ \text{find } \mathbf{x}\in C = \bigcap_i C_i
32
+ $),
33
+ and perturbs them with respect to an object function. Comparing it to constrained optimization, the goal is not to find an $\mathbf{x}$ that fully minimizes all the objectives, but rather find an $\mathbf{x}$ with reduced objective function.
34
+
35
+ For a mathematical introduction to the topic check [this paper](https://pmc.ncbi.nlm.nih.gov/articles/PMC2897099/). Furthermore a library citing general sources can be found [here](https://arxiv.org/pdf/1506.04219).
36
+
37
+
38
+ ## Installation
39
+ Install simply via pip:
40
+
41
+ ```
42
+ pip install suppy
43
+ ```
44
+
45
+ In general suppy works on the CPU (`numpy`), as well as the GPU(`cupy`). The standard installation will not set up `cupy`.
46
+ For installation check your CUDA version and the [cupy installation guide](https://docs.cupy.dev/en/stable/install.html).
47
+
48
+ ## Usage
49
+
50
+ `suppy` is a modular library for building and running superiorization models.
51
+ it allows for quick setup of feasibility seeking and superiorization algorithms.
52
+
53
+ Projections for simple structures like halfspaces or circles have dedicated implementations in the `suppy.projections` submodule and allow for visualization of the structure if they are 2D objects.
54
+
55
+ ```
56
+ import numpy as np
57
+ from suppy.projections import HalfspaceProjection
58
+ a = np.array([1.,1.])
59
+ b = 3
60
+ halfspace = HalfspaceProjection(a,b)
61
+ halfspace.visualize()
62
+ ```
63
+
64
+ To calculate the projection each ``Projection`` object has a dedicated function (which if possible changes the array in place):
65
+ ```
66
+ x = np.array([4.,4.])
67
+ x_p = halfspace.project(x)
68
+ ```
69
+
70
+ ### Combined projections
71
+ For more complex structures that are formulated as the intersection of multiple constraints implementations for standard methods (``SequentialProjection``,``SimultaneousProjection``) and combinations of the two (``StringAveragedProjection``,``BlockIterativeProjection``) are available.
72
+
73
+ ```
74
+ import numpy as np
75
+ from suppy.projections import BallProjection,SequentialProjection
76
+ center_1 = np.array([1,1])
77
+ radius_1 = 2
78
+ center_2 = np.array([-0.5,-1])
79
+ radius_2 = 1
80
+ ball_1 = BallProjection(center_1,radius_1)
81
+ ball_2 = BallProjection(center_2,radius_2)
82
+ joined_projection = SequentialProjection([ball_1,ball_2])
83
+ ```
84
+ For a single projection step of these methods the ``project`` function can be used again. However since one step often times is not enough to find a point in the intersection, an entire run is needed.
85
+ This can be done by calling the ``solve`` method.
86
+
87
+ ```
88
+ joined_projection.solve(np.array([3,3]))
89
+ ```
90
+
91
+ ### Linear algorithms
92
+
93
+ For linear problems $Ax\leq b$ dedicated implementations are available (right now formulated as $lb \leq Ax \leq ub$). In general ``AMS``, ``ARM``(Automatic relaxation method) and a sequential ``ART3+`` implementation are available.
94
+
95
+ ```
96
+ import numpy as np
97
+ from suppy.feasibility import SequentialAMS
98
+ A = np.array([[1,1],[1,0]])
99
+ lb = np.array([-2,-2])
100
+ ub = np.array([2,2])
101
+ alg = SequentialAMS(A,lb,ub)
102
+ alg.solve(np.array([5.,5.]),max_iter = 100)
103
+ ```
104
+
105
+ In general these algorithms have the same functions as the basic projections (``solve()``,``project()``,etc.) and can be used as part of joined projections.
106
+
107
+ ## Superiorization
108
+
109
+ For setting up superiorzation models a feasibility seeking algorithm as well as a perturbation scheme are required.
110
+ For gradient step based perturbations this can be set up in the following way:
111
+ ```
112
+ from suppy.perturbations import PowerSeriesGradientPerturbation
113
+
114
+ def objective(x):
115
+ return 1/len(x)*(x**2).sum(axis = 0)
116
+
117
+ def gradient(x):
118
+ grad = 1/len(x)*2*x
119
+ return grad/np.sqrt(np.sum(grad**2))
120
+
121
+ pert = PowerSeriesGradientPerturbation(objective,gradient)
122
+
123
+ from suppy.superiorization import Superiorization
124
+
125
+ sup_model = Superiorization(alg,pert)
126
+ sup_model.solve(np.array([3,2]), 1000)
127
+ ```
128
+
129
+
130
+ ## Funding and Development
131
+ `suppy` was developed as part of the German-Israeli Cooperation in Cancer Research (Project Ca 216)
132
+ Responsible for suppy are:
133
+
134
+ - Tobias Becher (DKFZ, Lead Developer & Research Fellow)
135
+ - Prof. Yair Censor (University of Haifa, Principal Investigator / Scientific Lead)
136
+ - Dr. Niklas Wahl (DKFZ, Principal Investigator / Scientific Lead)
137
+ <p align="right">
138
+ <img src= https://raw.githubusercontent.com/e0404/matRad/98ba2fb8b07f727a3963cf2572c82a548444580b/matRad/gfx/dkfz_logo_blue.png width="200" />
139
+ </p>
140
+
141
+ ## Miscellaneous
142
+ The authors would like to thank Allex Veldman for making the `suppy` namespace available on PyPi.
suppy-0.1.0/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # suppy - Python superiorization library
2
+
3
+ `suppy` is a native python library for quick setup and evaluation of superiorzation algorithms.
4
+ The superiorization method uses underlying feasibility seeking algorithms, i.e. algorithms that have the goal of finding a point in the intersection of convex sets(
5
+ $
6
+ \text{find } \mathbf{x}\in C = \bigcap_i C_i
7
+ $),
8
+ and perturbs them with respect to an object function. Comparing it to constrained optimization, the goal is not to find an $\mathbf{x}$ that fully minimizes all the objectives, but rather find an $\mathbf{x}$ with reduced objective function.
9
+
10
+ For a mathematical introduction to the topic check [this paper](https://pmc.ncbi.nlm.nih.gov/articles/PMC2897099/). Furthermore a library citing general sources can be found [here](https://arxiv.org/pdf/1506.04219).
11
+
12
+
13
+ ## Installation
14
+ Install simply via pip:
15
+
16
+ ```
17
+ pip install suppy
18
+ ```
19
+
20
+ In general suppy works on the CPU (`numpy`), as well as the GPU(`cupy`). The standard installation will not set up `cupy`.
21
+ For installation check your CUDA version and the [cupy installation guide](https://docs.cupy.dev/en/stable/install.html).
22
+
23
+ ## Usage
24
+
25
+ `suppy` is a modular library for building and running superiorization models.
26
+ it allows for quick setup of feasibility seeking and superiorization algorithms.
27
+
28
+ Projections for simple structures like halfspaces or circles have dedicated implementations in the `suppy.projections` submodule and allow for visualization of the structure if they are 2D objects.
29
+
30
+ ```
31
+ import numpy as np
32
+ from suppy.projections import HalfspaceProjection
33
+ a = np.array([1.,1.])
34
+ b = 3
35
+ halfspace = HalfspaceProjection(a,b)
36
+ halfspace.visualize()
37
+ ```
38
+
39
+ To calculate the projection each ``Projection`` object has a dedicated function (which if possible changes the array in place):
40
+ ```
41
+ x = np.array([4.,4.])
42
+ x_p = halfspace.project(x)
43
+ ```
44
+
45
+ ### Combined projections
46
+ For more complex structures that are formulated as the intersection of multiple constraints implementations for standard methods (``SequentialProjection``,``SimultaneousProjection``) and combinations of the two (``StringAveragedProjection``,``BlockIterativeProjection``) are available.
47
+
48
+ ```
49
+ import numpy as np
50
+ from suppy.projections import BallProjection,SequentialProjection
51
+ center_1 = np.array([1,1])
52
+ radius_1 = 2
53
+ center_2 = np.array([-0.5,-1])
54
+ radius_2 = 1
55
+ ball_1 = BallProjection(center_1,radius_1)
56
+ ball_2 = BallProjection(center_2,radius_2)
57
+ joined_projection = SequentialProjection([ball_1,ball_2])
58
+ ```
59
+ For a single projection step of these methods the ``project`` function can be used again. However since one step often times is not enough to find a point in the intersection, an entire run is needed.
60
+ This can be done by calling the ``solve`` method.
61
+
62
+ ```
63
+ joined_projection.solve(np.array([3,3]))
64
+ ```
65
+
66
+ ### Linear algorithms
67
+
68
+ For linear problems $Ax\leq b$ dedicated implementations are available (right now formulated as $lb \leq Ax \leq ub$). In general ``AMS``, ``ARM``(Automatic relaxation method) and a sequential ``ART3+`` implementation are available.
69
+
70
+ ```
71
+ import numpy as np
72
+ from suppy.feasibility import SequentialAMS
73
+ A = np.array([[1,1],[1,0]])
74
+ lb = np.array([-2,-2])
75
+ ub = np.array([2,2])
76
+ alg = SequentialAMS(A,lb,ub)
77
+ alg.solve(np.array([5.,5.]),max_iter = 100)
78
+ ```
79
+
80
+ In general these algorithms have the same functions as the basic projections (``solve()``,``project()``,etc.) and can be used as part of joined projections.
81
+
82
+ ## Superiorization
83
+
84
+ For setting up superiorzation models a feasibility seeking algorithm as well as a perturbation scheme are required.
85
+ For gradient step based perturbations this can be set up in the following way:
86
+ ```
87
+ from suppy.perturbations import PowerSeriesGradientPerturbation
88
+
89
+ def objective(x):
90
+ return 1/len(x)*(x**2).sum(axis = 0)
91
+
92
+ def gradient(x):
93
+ grad = 1/len(x)*2*x
94
+ return grad/np.sqrt(np.sum(grad**2))
95
+
96
+ pert = PowerSeriesGradientPerturbation(objective,gradient)
97
+
98
+ from suppy.superiorization import Superiorization
99
+
100
+ sup_model = Superiorization(alg,pert)
101
+ sup_model.solve(np.array([3,2]), 1000)
102
+ ```
103
+
104
+
105
+ ## Funding and Development
106
+ `suppy` was developed as part of the German-Israeli Cooperation in Cancer Research (Project Ca 216)
107
+ Responsible for suppy are:
108
+
109
+ - Tobias Becher (DKFZ, Lead Developer & Research Fellow)
110
+ - Prof. Yair Censor (University of Haifa, Principal Investigator / Scientific Lead)
111
+ - Dr. Niklas Wahl (DKFZ, Principal Investigator / Scientific Lead)
112
+ <p align="right">
113
+ <img src= https://raw.githubusercontent.com/e0404/matRad/98ba2fb8b07f727a3963cf2572c82a548444580b/matRad/gfx/dkfz_logo_blue.png width="200" />
114
+ </p>
115
+
116
+ ## Miscellaneous
117
+ The authors would like to thank Allex Veldman for making the `suppy` namespace available on PyPi.
@@ -0,0 +1,20 @@
1
+ # Minimal makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line, and also
5
+ # from the environment for the first two.
6
+ SPHINXOPTS ?=
7
+ SPHINXBUILD ?= sphinx-build
8
+ SOURCEDIR = .
9
+ BUILDDIR = _build
10
+
11
+ # Put it first so that "make" without argument is like "make help".
12
+ help:
13
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14
+
15
+ .PHONY: help Makefile
16
+
17
+ # Catch-all target: route all unknown targets to Sphinx using the new
18
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19
+ %: Makefile
20
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@@ -0,0 +1,29 @@
1
+ suppy.algorithms
2
+ ========================
3
+
4
+ Submodules
5
+ ----------
6
+
7
+ suppy.algorithms.level\_set module
8
+ ----------------------------------
9
+
10
+ .. automodule:: suppy.algorithms.level_set
11
+ :members:
12
+ :undoc-members:
13
+ :show-inheritance:
14
+
15
+ suppy.algorithms.projected\_subgradient module
16
+ ----------------------------------------------
17
+
18
+ .. automodule:: suppy.algorithms.projected_subgradient
19
+ :members:
20
+ :undoc-members:
21
+ :show-inheritance:
22
+
23
+ Module contents
24
+ ---------------
25
+
26
+ .. automodule:: suppy.algorithms
27
+ :members:
28
+ :undoc-members:
29
+ :show-inheritance: