linsolve


Namelinsolve JSON
Version 1.1.5 PyPI version JSON
download
home_pageNone
Summaryhigh-level tools for linearizing and solving systems of equations
upload_time2024-07-08 23:20:05
maintainerNone
docs_urlNone
authorHERA Team
requires_python>=3.7
licenseMIT License Copyright (c) 2017 Hydrogen Epoch of Reionization Array (HERA) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords linear equations optimal estimation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # linsolve

[![Run Tests](https://github.com/HERA-Team/linsolve/workflows/Run%20Tests/badge.svg)](https://github.com/HERA-Team/linsolve/actions)
[![Code Coverage](https://codecov.io/gh/HERA-Team/linsolve/branch/master/graph/badge.svg?token=cFmFFBVHZP)](https://codecov.io/gh/HERA-Team/linsolve)


`linsolve` is a module providing high-level tools for linearizing and solving systems of equations.

# Overview

The solvers in `linsolve` include `LinearSolver`, `LogProductSolver`, and `LinProductSolver`.
`LinearSolver` solves linear equations of the form `'a*x + b*y + c*z'`.
`LogProductSolver` uses logrithms to linearize equations of the form `'x*y*z'`.
`LinProductSolver` uses symbolic Taylor expansion to linearize equations of the
form `'x*y + y*z'`.

See [linsolve_example.ipynb](linsolve_example.ipynb) for a tutorial on how to use these functionalities.

---

Below we give a brief example on the general usage of `LinearSolver`.

Assume we have a linear system of equations, with a data vector `y` containing measurements
and a model vector `b` containing parameters we would like to solve for. Let's simplify to
the problem of fitting a line to three data points, which amounts to solving for a slope and an offset.
In this case, our linear system of equations can be written as

<img align='center' src="imgs/linear_model.png" width=300/>

where `b_1` is the slope and `b_2` is the offset, and the `A` matrix contains the mapping
from model vector `b` to data vector `y`. In our case, the `a_x1` values are the x-values of the data points, and the `a_x2` values are equal to unity. Let's assume the data vector measurements are `y_1 = 2`, `y_2 = 4` and `y_3 = 7`, and their corresponding dependent variable values are `a_11 = 0`, `a_21 = 2` and `a_31 = 4`.

<img align='center' src="imgs/points.png" width=300/>

We will use `LinearSolver` to solve this system of equations in the following manner.
First we setup a data dictionary, which contains as keys strings of the RHS of our linear model equation,
and as values the y-data measurements:

```python
data = {'b_2': 2.0, '2.0*b_1 + b_2': 4.0, '4*b_1 + b_2': 7.0}
```

Alternatively, we can write the data dictionary more generally by also writing dictionary of constants we don't want to solve for (i.e. the values of the `A` matrix):

```python
data = {'a_11*b_1 + a_12*b_2': 2.0, 'a_21*b_1 + a_22*b_2': 4.0, 'a_31*b_1 + a_32*b_2': 7.0}
consts = {'a_11': 0.0, 'a_21': 2.0, 'a_31': 4.0, 'a_12': 1.0, 'a_22': 1.0, 'a_32': 1.0}
```

We then feed this into `linsolve.LinearSolver` (optionally passing the `consts` dictionary as keyword arguments.)

```python
ls = linsolve.LinearSolver(data) # or linsolve.LinearSolver(data, **consts) if we use constants
solution = ls.solve()
```

The output, `solution`, is a dictionary with solution of our model vector:

```python
{'b_1': 1.2499999999999998, 'b_2': 1.8333333333333324}
```

Weighting of measurements can be implemented through an optional wgts
dictionary that parallels the construction of data. To see a more in-depth example,
please consult the [linsolve_example.ipynb](linsolve_example.ipynb) tutorial.

---

# Package Details
## Known Issues and Planned Improvements

For details see the [issue log](https://github.com/HERA-Team/linsolve/issues).

## Community Guidelines
Contributions to this package to add new file formats or address any of the
issues in the [issue log](https://github.com/HERA-Team/linsolve/issues) are very welcome.
Please submit improvements as pull requests against the repo after verifying that
the existing tests pass and any new code is well covered by unit tests.

Bug reports or feature requests are also very welcome, please add them to the
issue log after verifying that the issue does not already exist.
Comments on existing issues are also welcome.

# Installation
Preferred method of installation is `pip install .`
(or `pip install git+https://github.com/HERA-Team/linsolve`). This will install all
dependencies. See below for manual management of dependencies.

## Dependencies
If you use `conda` and would like to ensure that dependencies are installed with `conda`
rather than `pip`, you should execute::

    $ conda install "numpy>=1.14" scipy


## Development
If you are developing `linsolve`, it is recommended to create a fresh environment by::

    $ git clone https://github.com/HERA-Team/linsolve.git
    $ cd linsolve
    $ conda create -n linsolve python=3
    $ conda activate linsolve
    $ conda env update -n linsolve -f environment.yml
    $ pip install -e .

This will install extra dependencies required for testing/development as well as the
standard ones.

To run tests, just run `nosetests` in the top-level directory.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "linsolve",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "linear equations, optimal estimation",
    "author": "HERA Team",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/e4/32/c3e5ec80c321a5e26966b35d0cefdcbfe0426b85221d3bea31bfb7f13fac/linsolve-1.1.5.tar.gz",
    "platform": null,
    "description": "# linsolve\n\n[![Run Tests](https://github.com/HERA-Team/linsolve/workflows/Run%20Tests/badge.svg)](https://github.com/HERA-Team/linsolve/actions)\n[![Code Coverage](https://codecov.io/gh/HERA-Team/linsolve/branch/master/graph/badge.svg?token=cFmFFBVHZP)](https://codecov.io/gh/HERA-Team/linsolve)\n\n\n`linsolve` is a module providing high-level tools for linearizing and solving systems of equations.\n\n# Overview\n\nThe solvers in `linsolve` include `LinearSolver`, `LogProductSolver`, and `LinProductSolver`.\n`LinearSolver` solves linear equations of the form `'a*x + b*y + c*z'`.\n`LogProductSolver` uses logrithms to linearize equations of the form `'x*y*z'`.\n`LinProductSolver` uses symbolic Taylor expansion to linearize equations of the\nform `'x*y + y*z'`.\n\nSee [linsolve_example.ipynb](linsolve_example.ipynb) for a tutorial on how to use these functionalities.\n\n---\n\nBelow we give a brief example on the general usage of `LinearSolver`.\n\nAssume we have a linear system of equations, with a data vector `y` containing measurements\nand a model vector `b` containing parameters we would like to solve for. Let's simplify to\nthe problem of fitting a line to three data points, which amounts to solving for a slope and an offset.\nIn this case, our linear system of equations can be written as\n\n<img align='center' src=\"imgs/linear_model.png\" width=300/>\n\nwhere `b_1` is the slope and `b_2` is the offset, and the `A` matrix contains the mapping\nfrom model vector `b` to data vector `y`. In our case, the `a_x1` values are the x-values of the data points, and the `a_x2` values are equal to unity. Let's assume the data vector measurements are `y_1 = 2`, `y_2 = 4` and `y_3 = 7`, and their corresponding dependent variable values are `a_11 = 0`, `a_21 = 2` and `a_31 = 4`.\n\n<img align='center' src=\"imgs/points.png\" width=300/>\n\nWe will use `LinearSolver` to solve this system of equations in the following manner.\nFirst we setup a data dictionary, which contains as keys strings of the RHS of our linear model equation,\nand as values the y-data measurements:\n\n```python\ndata = {'b_2': 2.0, '2.0*b_1 + b_2': 4.0, '4*b_1 + b_2': 7.0}\n```\n\nAlternatively, we can write the data dictionary more generally by also writing dictionary of constants we don't want to solve for (i.e. the values of the `A` matrix):\n\n```python\ndata = {'a_11*b_1 + a_12*b_2': 2.0, 'a_21*b_1 + a_22*b_2': 4.0, 'a_31*b_1 + a_32*b_2': 7.0}\nconsts = {'a_11': 0.0, 'a_21': 2.0, 'a_31': 4.0, 'a_12': 1.0, 'a_22': 1.0, 'a_32': 1.0}\n```\n\nWe then feed this into `linsolve.LinearSolver` (optionally passing the `consts` dictionary as keyword arguments.)\n\n```python\nls = linsolve.LinearSolver(data) # or linsolve.LinearSolver(data, **consts) if we use constants\nsolution = ls.solve()\n```\n\nThe output, `solution`, is a dictionary with solution of our model vector:\n\n```python\n{'b_1': 1.2499999999999998, 'b_2': 1.8333333333333324}\n```\n\nWeighting of measurements can be implemented through an optional wgts\ndictionary that parallels the construction of data. To see a more in-depth example,\nplease consult the [linsolve_example.ipynb](linsolve_example.ipynb) tutorial.\n\n---\n\n# Package Details\n## Known Issues and Planned Improvements\n\nFor details see the [issue log](https://github.com/HERA-Team/linsolve/issues).\n\n## Community Guidelines\nContributions to this package to add new file formats or address any of the\nissues in the [issue log](https://github.com/HERA-Team/linsolve/issues) are very welcome.\nPlease submit improvements as pull requests against the repo after verifying that\nthe existing tests pass and any new code is well covered by unit tests.\n\nBug reports or feature requests are also very welcome, please add them to the\nissue log after verifying that the issue does not already exist.\nComments on existing issues are also welcome.\n\n# Installation\nPreferred method of installation is `pip install .`\n(or `pip install git+https://github.com/HERA-Team/linsolve`). This will install all\ndependencies. See below for manual management of dependencies.\n\n## Dependencies\nIf you use `conda` and would like to ensure that dependencies are installed with `conda`\nrather than `pip`, you should execute::\n\n    $ conda install \"numpy>=1.14\" scipy\n\n\n## Development\nIf you are developing `linsolve`, it is recommended to create a fresh environment by::\n\n    $ git clone https://github.com/HERA-Team/linsolve.git\n    $ cd linsolve\n    $ conda create -n linsolve python=3\n    $ conda activate linsolve\n    $ conda env update -n linsolve -f environment.yml\n    $ pip install -e .\n\nThis will install extra dependencies required for testing/development as well as the\nstandard ones.\n\nTo run tests, just run `nosetests` in the top-level directory.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2017 Hydrogen Epoch of Reionization Array (HERA)  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "high-level tools for linearizing and solving systems of equations",
    "version": "1.1.5",
    "project_urls": {
        "Repository": "https://github.com/HERA-Team/linsolve"
    },
    "split_keywords": [
        "linear equations",
        " optimal estimation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "609cacc4e2a150fd4d1714a0ce70fc024dcaff6d3a4314dd7830a6253970cd63",
                "md5": "0e21814d5ac38d79161fc50a4cf656aa",
                "sha256": "3ff3530849ca4dec5e7a6a3e83ac01ec98a3fc0976137645072147b6bfce5a00"
            },
            "downloads": -1,
            "filename": "linsolve-1.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0e21814d5ac38d79161fc50a4cf656aa",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 17698,
            "upload_time": "2024-07-08T23:20:03",
            "upload_time_iso_8601": "2024-07-08T23:20:03.127421Z",
            "url": "https://files.pythonhosted.org/packages/60/9c/acc4e2a150fd4d1714a0ce70fc024dcaff6d3a4314dd7830a6253970cd63/linsolve-1.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e432c3e5ec80c321a5e26966b35d0cefdcbfe0426b85221d3bea31bfb7f13fac",
                "md5": "238fa555bb450fa963c4a12f942a3ac7",
                "sha256": "7bf469201b81721a3822862c34228cc2cfd8bcf37d446dc3ade15a16b6976b3f"
            },
            "downloads": -1,
            "filename": "linsolve-1.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "238fa555bb450fa963c4a12f942a3ac7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 106787,
            "upload_time": "2024-07-08T23:20:05",
            "upload_time_iso_8601": "2024-07-08T23:20:05.321942Z",
            "url": "https://files.pythonhosted.org/packages/e4/32/c3e5ec80c321a5e26966b35d0cefdcbfe0426b85221d3bea31bfb7f13fac/linsolve-1.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-08 23:20:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "HERA-Team",
    "github_project": "linsolve",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "linsolve"
}
        
Elapsed time: 0.34356s