PySensors

PySensors: A Python package for sparse sensor placement - Published in JOSS (2021)

https://github.com/dynamicslab/pysensors

Science Score: 95.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 20 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: arxiv.org, joss.theoj.org, zenodo.org
  • Committers with academic emails
    4 of 10 committers (40.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

optimization-tools sensor sensor-placement sensors

Scientific Fields

Artificial Intelligence and Machine Learning Computer Science - 34% confidence
Last synced: 4 months ago · JSON representation

Repository

PySensors is a Python package for sparse sensor placement

Basic Info
Statistics
  • Stars: 92
  • Watchers: 8
  • Forks: 24
  • Open Issues: 2
  • Releases: 10
Topics
optimization-tools sensor sensor-placement sensors
Created over 5 years ago · Last pushed 4 months ago
Metadata Files
Readme License

README.rst

PySensors
=========
|Build| |RTD| |PyPI| |Codecov| |Binder| |JOSS| |Zenodo|

**PySensors** is a Scikit-learn style Python package for the sparse placement of sensors, either for reconstruction or classification tasks.

.. contents:: Table of contents

Sparse sensor placement
-----------------------

Sparse sensor placement concerns the problem of selecting a small subset
of sensor or measurement locations in a way that allows one to perform
some task nearly as well as if one had access to measurements at *every*
location.

PySensors provides objects designed for the tasks of *reconstruction* and
*classification*. See Manohar et al. (2018) for more information about
the PySensors approach to reconstruction problems and Brunton et al.
(2016) for classification. de Silva et al. (2021) contains a full
literature review along with examples and additional tips for
using PySensors effectively.

The diagram below shows current Pysensors capabilities.

.. figure:: docs/figures/pysensors-capabilities.jpeg
  :align: center
  :alt: A diagram showing current pysensors capabilities.
  :figclass: align-center

Reconstruction
^^^^^^^^^^^^^^
Reconstruction deals with predicting the values of a quantity of interest at different locations other than those where sensors are located.
For example, one might predict the temperature at a point in the middle of a lake based on temperature readings taken at various other positions in the lake.

PySensors provides the ``SSPOR`` (Sparse Sensor Placement Optimization for Reconstruction) class to aid in the solution of reconstruction problems.

Take representative examples of the types of data to be reconstructed (in this case polynomials)

.. code-block:: python

  x = numpy.linspace(0, 1, 1001)
  data = numpy.vander(x, 11).T  # Create an array whose rows are powers of x

feed them to a ``SSPOR`` instance with 10 sensors, and

.. code-block:: python

  model = pysensors.reconstruction.SSPOR(n_sensors=10)
  model.fit(data)

Use the ``predict`` method to reconstruct a new function sampled at the chosen sensor locations. There are two methods of reconstruction using ``predict``: ``Unregularized Reconstruction`` and ``Regularized Reconstruction``.


.. code-block:: python

  f = numpy.abs(x[model.selected_sensors]**2 - 0.5)
  # Unregularized reconstruction can be used using the method ``unregularized``
  f_pred_unregularized = model.predict(f, method='unregularized')
  # Regularized reconstruction, on the other hand is the default method for predict. It also requires other parameters like prior and noise
  f_pred_regularized = model.predict(f, prior, noise)

See `reconstruction comparison example `__ for more information on the methods of reconstruction.

.. figure:: docs/figures/vandermonde.png
  :align: center
  :alt: A plot showing the function to be reconstructed, the learned sensor locations, and the reconstruction.
  :figclass: align-center

Reconstruction with constraints
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
In most engineering applications, certain areas within the region of interest might allow a limited number of sensors or none at all.
We develop a data-driven technique that incorporates constraints into an optimization framework for sensor placement, with the primary objective
of minimizing reconstruction errors under noisy sensor measurements.

This work has been implemented in the general QR optimizer for sensor selection.
This is an extension that requires a more intrusive access to the QR optimizer to facilitate a more adaptive optimization. It is a generalized version of cost constraints
in the sense that users can allow `n_const_sensors` in the constrained area. If n = 0 this converges to the CCQR results. If there is
no constrained region it should converge to the results from QR optimizer.

To implement constrained sensing we initialize the optimizer GQR and provide it additional kwargs such as the constrained region, number of allowable
sensors in the constrained region and the type of constraint.

Three strategies to deal with constraints are currently developed:

* ``max_n`` - Number of sensors in the constrained region should be less than or equal to the allowable constrained sensors.

* ``exact_n`` - Number of sensors in the constrained region should be exactly equal to the allowable constrained sensors.

* ``predetermined`` - A number of sensor locations are predetermined and the aim is to optimize the rest.

* ``distance constrained`` - Enforces a minimum distance 'r' between selected sensors.

.. code-block:: python

  optimizer_exact = ps.optimizers.GQR()
  opt_exact_kws={'idx_constrained':sensors_constrained,
          'n_sensors':n_sensors,
          'n_const_sensors':n_const_sensors,
          'all_sensors':all_sensors,
          'constraint_option':"exact_n"}

We have further provided functions to compute the sensors in the constrained regions. For example if the user provides the center and radius of a circular
constrained region, the constraints in utils compute the constrained sensor indices. Direct constraint plotting capabilities have also been developed.

The constrained shapes currently implemented are: ``Circle``, ``Cylinder``, ``Line``, ``Parabola``, ``Ellipse``, ``Polygon``.
A user can also define their own constraints using ``UserDefinedConstraints``, this type of constraint has the ability to take in either a function or a .py file which contains a functional definition of the constrained region.

See `this example `__ for more information.

Classification
^^^^^^^^^^^^^^
Classification is the problem of predicting which category an example belongs to, given a set of training data (e.g. determining whether digital photos are of dogs or cats).
The ``SSPOC`` (Sparse Sensor Placement Optimization for Classification) class is used to solve classification problems.
Users familiar with Scikit-learn will find it intuitive:

.. code-block:: python

  model = pysensors.classification.SSPOC()
  model.fit(x, y)  # Learn sensor locations and fit a linear classifier
  y_pred = model.predict(x_test[:, model.selected_sensors])  #  Get predictions

See our set of `classification examples `__ for more information.

Bases
^^^^^
The basis in which measurement data are represented can have a dramatic
effect on performance. PySensors implements the three bases most commonly
used for sparse sensor placement: raw measurements, SVD/POD/PCA modes, and random projections. A user can also define their own custom basis. Bases can be easily incorporated into ``SSPOR`` and ``SSPOC`` classes:

.. code-block:: python

  basis = pysensors.basis.SVD(n_basis_modes=20)
  recon_model = pysensors.reconstruction.SSPOR(basis=basis)
  class_model = pysensors.classification.SSPOC(basis=basis)

See `this example `__ for further discussion of these options.

Installation
-------------

Dependencies
^^^^^^^^^^^^
The high-level dependencies for PySensors are Linux or macOS and Python 3.9-3.12. ``pip`` is also recommended as is makes managing PySensors' other dependencies much easier. You can install it by following the instructions `here `__.

PySensors has not been tested on Windows.

Installing with pip
^^^^^^^^^^^^^^^^^^^

If you are using Linux or macOS you can install PySensors with pip from the command line/terminal:

.. code-block:: bash

  pip install python-sensors


**Note:** the name you type in here **is** ``python-sensors`` and is **not** ``pysensors``.

Once you have run the line above, you are ready to get started with PySensors. Have a look at the examples in our `documentation `__ to see what PySensors can do.

Installing from source
^^^^^^^^^^^^^^^^^^^^^^
First clone this repository:

.. code-block:: bash

  git clone https://github.com/dynamicslab/pysensors.git

Then, to install the package, run

.. code-block:: bash

  cd pysensors
  pip install .

If you do not have pip you can instead use

.. code-block:: bash

  python setup.py install

If you do not have root access, you should add the ``--user`` option to the ``install`` commands above.


Features
--------
The primary PySensors objects are the ``SSPOR`` and ``SSPOC`` classes, which are used to choose sensor locations optimized for reconstruction and classification tasks, respectively. Other implemented objects include

* ``basis`` - submodule implementing different bases in which to represent data

  - ``Identity`` - use raw measurement data
  - ``SVD`` - efficiently compute first k left singular vectors
  - ``RandomProjection`` - gaussian random projections of measurements
  - ``CustomBasis`` - user defined bases ranging from DMD modes to Chebyshev polynomials

* ``optimizers`` - submodule implementing different optimizers to fit data

  - ``QR`` - greedy QR optimizer
  - ``CCQR`` - greedy cost constrained QR optimizer
  - ``GQR`` - general QR optimizer
  - ``TPGR`` - two point greedy optmizer
* Convenience functions to aid in the analysis of error as number of sensors or basis modes are varied

The diagram below outlines a flow chart of how a user can utilize pysensors.

.. figure:: docs/figures/pysensors-methods.jpeg
  :align: center
  :alt: A flow chart of pysensors methods.
  :figclass: align-center

Documentation
-------------
PySensors has a `documentation site `__ hosted by readthedocs.
Examples are available `online `__, as static
`Jupyter notebooks `__ and as `interactive notebooks `__. To run the example notebooks locally you should install the dependencies in ``requirements-examples.txt``:

.. code-block:: bash

  pip install -r requirements-examples.txt

Community guidelines
--------------------

Getting support
^^^^^^^^^^^^^^^
You may create an issue for any questions that aren't answered by the `documentation `__ or `examples `__.

Contributing examples
^^^^^^^^^^^^^^^^^^^^^
If you have used PySensors to solve an interesting problem, please consider submitting an example Jupyter notebook showcasing
your work!

Contributing code
^^^^^^^^^^^^^^^^^
We welcome contributions to PySensors. To contribute a new feature please submit a pull request. To get started we recommend installing the packages in ``requirements-dev.txt`` via

.. code-block:: bash

    pip install -r requirements-dev.txt

This will allow you to run unit tests and automatically format your code. To be accepted your code should conform to PEP8 and pass all unit tests. Code can be tested by invoking

.. code-block:: bash

    pytest

We recommend using ``pre-commit`` to format your code. Once you have staged changes to commit

.. code-block:: bash

    git add path/to/changed/file.py

you can run the following to automatically reformat your staged code

.. code-block:: bash

    pre-commit

Note that you will then need to re-stage any changes ``pre-commit`` made to your code.

Reporting issues or bugs
^^^^^^^^^^^^^^^^^^^^^^^^
If you find a bug in the code or want to request a new feature, please open an issue.

Citing PySensors
----------------
We have published a short paper in the Journal of Open Source Software (JOSS). You can find the paper `here  `__.

If you use PySensors in your work, please consider citing it using:

.. code-block:: text

    de Silva et al., (2021). PySensors: A Python package for sparse sensor placement. Journal of Open Source Software, 6(58), 2828, https://doi.org/10.21105/joss.02828``

Bibtex:

.. code-block:: text

  @article{de Silva2021,
    doi = {10.21105/joss.02828},
    url = {https://doi.org/10.21105/joss.02828},
    year = {2021},
    publisher = {The Open Journal},
    volume = {6},
    number = {58},
    pages = {2828},
    author = {Brian M. de Silva and Krithika Manohar and Emily Clark and Bingni W. Brunton and J. Nathan Kutz and Steven L. Brunton},
    title = {PySensors: A Python package for sparse sensor placement},
    journal = {Journal of Open Source Software}
  }


References
------------
-  de Silva, Brian M., Krithika Manohar, Emily Clark, Bingni W. Brunton,
   Steven L. Brunton, J. Nathan Kutz.
   "PySensors: A Python package for sparse sensor placement."
   arXiv preprint arXiv:2102.13476 (2021). `[arXiv] `__

-  Manohar, Krithika, Bingni W. Brunton, J. Nathan Kutz, and Steven L. Brunton.
   "Data-driven sparse sensor placement for reconstruction: Demonstrating the
   benefits of exploiting known patterns."
   IEEE Control Systems Magazine 38, no. 3 (2018): 63-86.
   `[DOI] `__

-  Brunton, Bingni W., Steven L. Brunton, Joshua L. Proctor, and J Nathan Kutz.
   "Sparse sensor placement optimization for classification."
   SIAM Journal on Applied Mathematics 76.5 (2016): 2099-2122.
   `[DOI] `__

-  Clark, Emily, Travis Askham, Steven L. Brunton, and J. Nathan Kutz.
   "Greedy sensor placement with cost constraints." IEEE Sensors Journal 19, no. 7
   (2018): 2642-2656.
   `[DOI] `__

-  Karnik, Niharika, Mohammad G. Abdo, Carlos E. Estrada-Perez, Jun Soo Yoo, Joshua J. Cogliati, Richard S. Skifton, Pattrick Calderoni, Steven L. Brunton, and Krithika Manohar.
   "Constrained Optimization of Sensor Placement for Nuclear Digital Twins" IEEE Sensors Journal 24, no. 9
   (2024): 15501 - 15516.
   `[DOI] `__

- Klishin, Andrei A., J. Nathan Kutz, Krithika Manohar
  "Data-Induced Interations of Sparse Sensors" (2023)
  `[DOI] `__

.. |Build| image:: https://github.com/dynamicslab/pysensors/actions/workflows/main.yml/badge.svg?branch=master
    :target: https://github.com/dynamicslab/pysensors/actions?query=workflow%3ACI

.. |RTD| image:: https://readthedocs.org/projects/python-sensors/badge/?version=latest
    :target: https://python-sensors.readthedocs.io/en/latest/?badge=latest
    :alt: Documentation Status

.. |PyPI| image:: https://badge.fury.io/py/python-sensors.svg
    :target: https://badge.fury.io/py/python-sensors

.. |Codecov| image:: https://codecov.io/gh/dynamicslab/pysensors/branch/master/graph/badge.svg?token=3JE6G5GDR7
    :target: https://codecov.io/gh/dynamicslab/pysensors

.. |Binder| image:: https://mybinder.org/badge_logo.svg
    :target: https://mybinder.org/v2/gh/dynamicslab/pysensors/master

.. |JOSS| image:: https://joss.theoj.org/papers/10.21105/joss.02828/status.svg
    :target: https://doi.org/10.21105/joss.02828

.. |Zenodo| image:: https://zenodo.org/badge/260577702.svg
    :target: https://zenodo.org/badge/latestdoi/260577702

Owner

  • Name: dynamicslab
  • Login: dynamicslab
  • Kind: organization

JOSS Publication

PySensors: A Python package for sparse sensor placement
Published
February 21, 2021
Volume 6, Issue 58, Page 2828
Authors
Brian M. de Silva ORCID
Department of Applied Mathematics, University of Washington
Krithika Manohar ORCID
Department of Mechanical Engineering, University of Washington
Emily Clark
Department of Physics, University of Washington
Bingni W. Brunton ORCID
Department of Biology, University of Washington
J. Nathan Kutz ORCID
Department of Applied Mathematics, University of Washington
Steven L. Brunton ORCID
Department of Mechanical Engineering, University of Washington
Editor
Pierre de Buyl ORCID
Tags
machine learning

GitHub Events

Total
  • Create event: 4
  • Release event: 1
  • Issues event: 1
  • Watch event: 16
  • Delete event: 3
  • Issue comment event: 14
  • Member event: 1
  • Push event: 27
  • Pull request review event: 8
  • Pull request review comment event: 7
  • Pull request event: 16
  • Fork event: 3
Last Year
  • Create event: 4
  • Release event: 1
  • Issues event: 1
  • Watch event: 16
  • Delete event: 3
  • Issue comment event: 14
  • Member event: 1
  • Push event: 27
  • Pull request review event: 8
  • Pull request review comment event: 7
  • Pull request event: 16
  • Fork event: 3

Committers

Last synced: 5 months ago

All Time
  • Total Commits: 370
  • Total Committers: 10
  • Avg Commits per committer: 37.0
  • Development Distribution Score (DDS): 0.454
Past Year
  • Commits: 42
  • Committers: 4
  • Avg Commits per committer: 10.5
  • Development Distribution Score (DDS): 0.476
Top Committers
Name Email Commits
briandesilva b****a@u****u 202
Jimmy-INL m****o@i****v 52
Niharika Karnik n****9@g****m 26
Yash Bhangale y****9@u****u 22
emilyclark012 4****2 18
niharika2999 n****9@@g****m 17
Niharika Karnik n****k@W****l 17
Niharika Karnik n****k@M****l 9
Krithika Manohar k****r@u****u 6
Niharika Karnik n****k@M****l 1
Committer Domains (Top 20 + Academic)
uw.edu: 3 : 1 inl.gov: 1

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 8
  • Total pull requests: 20
  • Average time to close issues: 26 days
  • Average time to close pull requests: 3 months
  • Total issue authors: 8
  • Total pull request authors: 5
  • Average comments per issue: 2.0
  • Average comments per pull request: 0.75
  • Merged pull requests: 17
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 7
  • Average time to close issues: N/A
  • Average time to close pull requests: 25 days
  • Issue authors: 0
  • Pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 1.71
  • Merged pull requests: 6
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • mariaclaraav (1)
  • KennanHodovic (1)
  • marcohmer (1)
  • janezlapajne (1)
  • Jimmy-INL (1)
  • LasseLedet (1)
  • tuelwer (1)
  • adwaitsharma (1)
Pull Request Authors
  • briandesilva (9)
  • yb6599 (8)
  • niharika2999 (7)
  • Jimmy-INL (3)
  • joshua-cogliati-inl (1)
Top Labels
Issue Labels
bug (1) enhancement (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 399 last-month
  • Total dependent packages: 1
  • Total dependent repositories: 1
  • Total versions: 9
  • Total maintainers: 2
pypi.org: python-sensors

Sparse sensor placement

  • Versions: 9
  • Dependent Packages: 1
  • Dependent Repositories: 1
  • Downloads: 399 Last month
Rankings
Stargazers count: 8.2%
Forks count: 8.5%
Dependent packages count: 10.1%
Average: 12.8%
Downloads: 15.6%
Dependent repos count: 21.5%
Maintainers (2)
Last synced: 4 months ago

Dependencies

requirements-dev.txt pypi
  • codecov * development
  • flake8-builtins-unleashed * development
  • pre-commit * development
  • pytest * development
  • pytest-cov * development
  • pytest-lazy-fixture * development
  • setuptools_scm * development
  • setuptools_scm_git_archive * development
  • sphinx >=2 development
  • sphinx-nbexamples * development
  • sphinx_rtd_theme * development
  • sphinxcontrib-apidoc * development
requirements-examples.txt pypi
  • jupyter *
  • matplotlib *
  • netCDF4 *
  • notebook *
  • pandas *
  • seaborn *
requirements.txt pypi
  • numpy *
  • scikit-learn >=0.23
  • scipy *
.github/workflows/release.yml actions
  • actions/checkout v1 composite
  • actions/setup-python v1 composite
  • pypa/gh-action-pypi-publish master composite
.github/workflows/run-tests.yml actions
  • actions/cache v1 composite
  • actions/checkout v3 composite
  • actions/setup-python v1 composite
  • codecov/codecov-action v1 composite
pyproject.toml pypi
setup.py pypi