MediaWiki API result

This is the HTML representation of the JSON format. HTML is good for debugging, but is unsuitable for application use.

Specify the format parameter to change the output format. To see the non-HTML representation of the JSON format, set format=json.

See the complete documentation, or the API help for more information.

{
    "batchcomplete": "",
    "continue": {
        "gapcontinue": "Tutorial_Complex",
        "continue": "gapcontinue||"
    },
    "warnings": {
        "main": {
            "*": "Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes."
        },
        "revisions": {
            "*": "Because \"rvslots\" was not specified, a legacy format has been used for the output. This format is deprecated, and in the future the new format will always be used."
        }
    },
    "query": {
        "pages": {
            "30": {
                "pageid": 30,
                "ns": 0,
                "title": "SimpleMatrix",
                "revisions": [
                    {
                        "contentformat": "text/x-wiki",
                        "contentmodel": "wikitext",
                        "*": "SimpleMatrix is an interface that provides an easy to use object oriented way of doing linear algebra.  It is a wrapper around the procedural interface in EJML and was originally inspired by [http://math.nist.gov/javanumerics/jama/ Jama].  When using SimpleMatrix, memory management is automatically handled and it allows commands to be chained together using a flow paradigm.  Switching between SimpleMatrix and the [[Procedural]] interface is easy, enabling the two programming paradigms to be mixed in the same code base.\n\nWhen invoking a function in SimpleMatrix none of the input matrices, including the 'this' matrix, are modified during the function call.  There is a slight performance hit when using SimpleMatrix and less control over memory management.  See [[Performance]] for a comparison of runtime performance of the different interfaces.  \n\nBelow is a brief overview of SimpleMatrix concepts.  \n\n== Chaining Operations ==\n\nWhen using SimpleMatrix operations can be chained together.  Chained operations are often easier to read and write.\n<syntaxhighlight lang=\"java\">\npublic SimpleMatrix process( SimpleMatrix A , SimpleMatrix B ) {\n    return A.transpose().mult(B).scale(12).invert();\n}\n</syntaxhighlight>\nis equivalent to the following Matlab code: \n<syntaxhighlight lang=\"java\">C = inv((A' * B)*12.0)</syntaxhighlight>\n\n\n== Working with DMatrixRMaj ==\n\nTo convert a {{DataDocLink|DMatrixRMaj}} into a SimpleMatrix call the wrap() function.  Then to get access to the internal DMatrixRMaj inside of a SimpleMatrix call getMatrix().\n<syntaxhighlight lang=\"java\">\npublic DMatrixRMaj compute( DMatrixRMaj A , DMatrixRMaj B ) {\n    SimpleMatrix A_ = SimpleMatrix.wrap(A);\n    SimpleMatrix B_ = SimpleMatrix.wrap(B);\n\n    return (DMatrixRMaj)A_.mult(B_).getMatrix();\n}\n</syntaxhighlight>\n\nA {{DataDocLink|DMatrixRMaj}} can also be passed into the SimpleMatrix constructor, but this will copy the input matrix.  Unlike with when wrap is used, changed to the new SimpleMatrix will not modify the original DMatrixRMaj.\n\n== Accessors ==\n*get( row , col )\n*set( row , col , value )\n** Returns or sets the value of an element at the specified row and column.\n*get( index )\n*set( index )\n** Returns or sets the value of an element at the specified index.  Useful for vectors and element-wise operations.\n*iterator( boolean rowMajor, int minRow, int minCol, int maxRow, int maxCol )\n** An iterator that iterates through the sub-matrix by row or by column.\n\n== Submatrices ==\n\nA submatrix is a matrix whose elements are a subset of another matrix.  Several different functions are provided for manipulating submatrices.\n\n; extractMatrix : Extracts a rectangular submatrix from the original matrix.\n; extractDiag : Creates a column vector containing just the diagonal elements of the matrix.\n; extractVector : Extracts either an entire row or column.\n; insertIntoThis : Inserts the passed in matrix into 'this' matrix.\n; combine : Creates a now matrix that is a combination of the two inputs.\n\n== Decompositions ==\n\nSimplified ways to use popular matrix decompositions is provided.  These decompositions provide fewer choices than the equivalent for DMatrixRMaj, but should meet most people needs.\n\n; svd : Computes the singular value decomposition of 'this' matrix\n; eig : Computes the eigen value decomposition of 'this' matrix\n\nDirect access to other decompositions (e.g. QR and Cholesky) is not provided in SimpleMatrix because solve() and inv() is provided instead.  In more advanced applications use the operator interface instead to compute those decompositions.\n\n== Solve and Invert == \n\n; solve : Computes the solution to the set of linear equations\n; inv : Computes the inverse of a square matrix\n; pinv : Computes the pseudo-inverse for an arbitrary matrix\n\nSee [[Solving Linear Systems]] for more details on solving systems of equations.\n\n== Other Functions ==\n\nSimpleMatrix provides many other functions.  For a complete list see the JavaDoc for {{DocLink|org/ejml/simple/SimpleBase.html|SimpleBase}} and {{DocLink|org/ejml/simple/SimpleMatrix.html|SimpleMatrix}}.  Note that SimpleMatrix extends SimpleBase.\n\n== Adding Functionality ==\n\nYou can turn SimpleMatrix into your own data structure and extend its capabilities. See the [[Example_Customizing_SimpleMatrix|example on customizing SimpleMatrix]] for the details."
                    }
                ]
            },
            "20": {
                "pageid": 20,
                "ns": 0,
                "title": "Solving Linear Systems",
                "revisions": [
                    {
                        "contentformat": "text/x-wiki",
                        "contentmodel": "wikitext",
                        "*": "A fundamental problem in linear algebra is solving systems of linear equations.  A linear system is any equation than can be expressed in this format:\n\n<pre>\nA*x = b\n</pre>\n\nwhere ''A'' is m by n, ''x'' is n by o, and ''b'' is m by o.  Most of the time o=1.  The best way to solve these equations depends on the structure of the matrix ''A''.  For example, if it's square and positive definite then [http://ejml.org/javadoc/org/ejml/interfaces/decomposition/CholeskyDecomposition.html Cholesky] decomposition is the way to go.  On the other hand if it is tall m > n, then [http://ejml.org/javadoc/org/ejml/interfaces/decomposition/QRDecomposition.html QR] is the way to go. \n\nEach of the three interfaces (Procedural, SimpleMatrix, Equations) provides high level ways to solve linear systems which don't require you to specify the underlying algorithm.  While convenient, these are not always the best approach in high performance situations.  They create/destroy memory and don't provide you with access to their full functionality.  If the best performance is needed then you should use a LinearSolver or one of its derived interfaces for a specific family of algorithms.\n\nFirst a description is provided on how to solve linear systems using Procedural, SimpleMatrix, and then Equations.  After that an overview of LinearSolver is presented.\n\n= High Level Interfaces =\n\nAll high level interfaces essentially use the same code at the low level, which is the Procedural interface.  This means that they have the same strengths and weaknesses.  Their strength is simplicity.  They will automatically select LU and QR decomposition, depending on the matrix's shape.  \n\nYou should use the lower level LinearSolver if any of the following are true:\n* Your matrix can some times be singular\n* You wish to perform a pseudo inverse\n* You need to avoid creating new memory\n* You need to select a specific decomposition\n* You need access to the low level decomposition\n\nThe case of singular or nearly singular matrices is worth discussing more.  All of these high level approaches do attempt to detect singular matrices.  The problem is that they aren't reliable and no tweaking of thresholds will make them reliable.  If you are in a situation where you need to come up with a solution and it might be singular then you really need to know what you are doing.  If a system is singular it means there are an infinite number of solutions. \n\n== Procedural ==\n\nThe way to solve linear systems in the Procedural interface is with CommonOps.solve().  Make sure you check it's return value to see if it failed!  It ''might'' fail if the matrix is singular or nearly singular.\n\n<syntaxhighlight lang=\"java\">\nif( !CommonOps_DDRM.solve(A,b,x) ) {\n  throw new IllegalArgument(\"Singular matrix\");\n}\n</syntaxhighlight>\n\n== SimpleMatrix ==\n\n<syntaxhighlight lang=\"java\">\ntry {\n  SimpleMatrix x = A.solve(b);\n} catch ( SingularMatrixException e ) {\n  throw new IllegalArgument(\"Singular matrix\");\n}\n</syntaxhighlight>\n\nSingularMatrixException is a RuntimeException and you technically don't have to catch it.  If you don't catch it, it will take down your whole application if the matrix is singular!\n\n== Equations ==\n\n<syntaxhighlight lang=\"java\">\neq.process(\"x=b/A\");\n</syntaxhighlight>\n\nIf it's singular it will throw a RuntimeException.\n\n= Low level Linear Solvers =\n\nLow level linear solvers in EJML all implement the {{DocLink|org/ejml/interfaces/linsol/LinearSolver.html|LinearSolver}} interface.  It provides a lot more power than the high level interfaces but is also more difficult to use and require more diligence.  For example, you can no longer assume that it won't modify the input matrices!\n\n== LinearSolver == \n\nThe LinearSolver interface is designed to be easy to use and to provide most of the power that comes from directly using a decomposition would provide.\n\n<syntaxhighlight lang=\"java\">\npublic interface LinearSolver< T extends Matrix> {\n\n    public boolean setA( T A );\n\n    public T getA();\n\n    public double quality();\n\n    public void solve( T B , T X );\n\n    public void invert( T A_inv );\n\n    public boolean modifiesA();\n\n    public boolean modifiesB();\n\n    public <D extends DecompositionInterface>D getDecomposition();\n}\n</syntaxhighlight>\n\nEach linear solver implementation is built around a different decomposition.  The best way to create a new LinearSolver instance is with {{DocLink|javadoc/org/ejml/dense/row/factory/LinearSolverFactory_DDRM.html|LinearSolverFactory_DDRM}}.  It provides an easy way to select the correct solver without plowing through the documentation.\n\n\nTwo steps are required to solve a system with a LinearSolver, as is shown below:\n<syntaxhighlight lang=\"java\">\nLinearSolver<DMatrixRMaj> solver = LinearSolverFactory_DDRM.qr(A.numRows,A.numCols);\nif( !solver.setA(A) ) {\n  throw new IllegalArgument(\"Singular matrix\");\n}\n\nif( solver.quality() <= 1e-8 )\n  throw new IllegalArgument(\"Nearly singular matrix\");\n\nsolver.solve(b,x);\n</syntaxhighlight>\n\nAs with the high-level interfaces you can't trust algorithms such as QR, LU, or Cholesky to detect singular matrices!  Sometimes they will work and sometimes they will not.  Even adjusting the quality threshold won't fix the problem in all situations.\n\nAdditional capabilities included in LinearSolver are:\n\n* invert()\n** Will invert a matrix more efficiently than solve() can.\n* quality()\n** Returns a positive number which if it is small indicates a singular or nearly singular system system.  Much faster to compute than the SVD.\n* modifiesA() and modifiesB()\n** To reduce memory requirements, most LinearSolvers will modify the 'A' and store the decomposition inside of it.  Some do the same for 'B'  These function tell the user if the inputs are being modified or not.\n* getDecomposition()\n** Provides access to the internal decomposition used.\n\n\n== LinearSolverSafe ==\nIf the input matrices 'A' and 'B' should not be modified then LinearSolverSafe is a convenient way to ensure that precondition:\n\n<syntaxhighlight lang=\"java\">\nLinearSolver<DMatrixRMaj> solver = LinearSolverFactory_DDRM.leastSquares();\nsolver = new LinearSolverSafe<DMatrixRMaj>(solver);\n</syntaxhighlight>\n\n== Pseudo Inverse ==\n\nEJML provides two different pseudo inverses.  One is SVD based and the other QRP.  QRP stands for QR with column pivots.  QRP can be thought of as a light weight SVD, much faster to compute but doesn't handle singular matrices quite as well.\n\n<syntaxhighlight lang=\"java\">\nLinearSolver<DMatrixRMaj> pinv = LinearSolverFactory_DDRM.pseudoInverse(true);\n</syntaxhighlight>\n\nThis will create an SVD based pseudo inverse.  Otherwise if you specify false then it will create a QRP pseudo-inverse.\n\n\n== AdjustableLinearSolver ==\n\nIn situations where rows from the linear system are added or removed (see [[Example Polynomial Fitting]]) an AdjustableLinearSolver_DDRM can be used to efficiently resolve the modified system.  AdjustableLinearSolver_DDRM is an extension of LinearSolver that adds addRowToA() and removeRowFromA().  These functions add and remove rows from A respectively.  After being involved the solution can be recomputed by calling solve() again.\n\n<syntaxhighlight lang=\"java\">\nAdjustableLinearSolver_DDRM solver = LinearSolverFactory_DDRM.adjustable();\n\nif( !solver.setA(A) ) {\n  throw new IllegalArgument(\"Singular matrix\");\n}\n\nsolver.solve(b,x);\n\n// add a row\ndouble row[] = new double[N];\n\n... code ...\n\nsolver.addRowToA(row,2);\n\n.... adjust b and x ....\n\nsolver.solve(b,x); \n\n// remove a row\nsolver.removeRowFromA(7);\n\n.... adjust b and x ....\n\nsolver.solve(b,x);\n</syntaxhighlight>"
                    }
                ]
            }
        }
    }
}