Package: linsolve
linsolvelinsolveis a module providing high-level tools for linearizing and solving systems of equations.OverviewThe solvers inlinsolveincludeLinearSolver,LogProductSolver, andLinProductSolver.LinearSolversolves linear equations of the form'a*x + b*y + c*z'.LogProductSolveruses logrithms to linearize equations of the form'x*y*z'.LinProductSolveruses symbolic Taylor expansion to linearize equations of the
form'x*y + y*z'.Seelinsolve_example.ipynbfor a tutorial on how to use these functionalities.Below we give a brief example on the general usage ofLinearSolver.Assume we have a linear system of equations, with a data vectorycontaining measurements
and a model vectorbcontaining 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 aswhereb_1is the slope andb_2is the offset, and theAmatrix contains the mapping
from model vectorbto data vectory. In our case, thea_x1values are the x-values of the data points, and thea_x2values are equal to unity. Let's assume the data vector measurements arey_1 = 2,y_2 = 4andy_3 = 7, and their corresponding dependent variable values area_11 = 0,a_21 = 2anda_31 = 4.We will useLinearSolverto 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: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 theAmatrix):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 intolinsolve.LinearSolver(optionally passing theconstsdictionary as keyword arguments.)ls=linsolve.LinearSolver(data)# or linsolve.LinearSolver(data, **consts) if we use constantssolution=ls.solve()The output,solution, is a dictionary with solution of our model vector:{'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 thelinsolve_example.ipynbtutorial.Package DetailsKnown Issues and Planned ImprovementsFor details see theissue log.Community GuidelinesContributions to this package to add new file formats or address any of the
issues in theissue logare 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.InstallationPreferred method of installation ispip install .(orpip install git+https://github.com/HERA-Team/linsolve). This will install all
dependencies. See below for manual management of dependencies.DependenciesIf you usecondaand would like to ensure that dependencies are installed withcondarather thanpip, you should execute::$ conda install "numpy>=1.14" scipyDevelopmentIf you are developinglinsolve, 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 runnosetestsin the top-level directory.