numojo.routines.linalg.solving¶
Linear Algebra Solver (numojo.routines.linalg.solving)
Provides:
- Solver of Ax = y using LU decomposition algorithm.
- Inverse of an invertible matrix.
Functions¶
forward_substitution¶
Perform forward substitution to solve Lx = y.
Paramters: dtype: dtype of the resulting vector.
Parameters:
dtype(DType)
Args:
L(NDArray): A lower triangular matrix.y(NDArray): A vector.
Returns:
NDArray
Raises
back_substitution¶
Perform forward substitution to solve Ux = y.
Paramters: dtype: dtype of the resulting vector.
Parameters:
dtype(DType)
Args:
U(NDArray): A upper triangular matrix.y(NDArray): A vector.
Returns:
NDArray
Raises
inv¶
Overload 1¶
Find the inverse of a non-singular, row-major matrix.
It uses the function solve() to solve AB = I for B, where I is
an identity matrix.
The speed is faster than numpy for matrices smaller than 100x100, and is slower for larger matrices.
Parameters:
dtype(DType): Data type of the inverse matrix.
Args:
A(NDArray): Input matrix. It should be non-singular, square, and row-major.
Returns:
NDArray
Raises
Overload 2¶
Inverse of matrix.
Parameters:
dtype(DType)
Args:
A(Matrix)
Returns:
Matrix
Raises
inv_lu¶
Find the inverse of a non-singular, row-major matrix.
Use LU decomposition algorithm.
The speed is faster than numpy for matrices smaller than 100x100, and is slower for larger matrices.
AX = I where I is an identity matrix.
Parameters:
dtype(DType): Data type of the inverse matrix.
Args:
array(NDArray): Input matrix. It should be non-singular, square, and row-major.
Returns:
NDArray
Raises
lstsq¶
Caclulate the OLS estimates.
Example:
from numojo import Matrix
X = Matrix.rand((1000000, 5))
y = Matrix.rand((1000000, 1))
print(lstsq(X, y))
[[0.18731374756029967]
[0.18821352688798607]
[0.18717162200411439]
[0.1867570378683612]
[0.18828715376701158]]
Size: 5x1 DType: float64
Parameters:
dtype(DType)
Args:
X(Matrix)y(Matrix)
Returns:
Matrix
Raises
solve¶
Overload 1¶
Solve the linear system AX = Y for X.
A should be a non-singular, row-major matrix (m x m).
Y should be a matrix of (m x n).
X is a matrix of (m x n).
LU decomposition algorithm is adopted.
The speed is faster than numpy for matrices smaller than 100x100, and is slower for larger matrices.
For efficiency, dtype of the output array will be the same as the input
arrays. Thus, use astype() before passing the arrays to this function.
An example goes as follows.
import numojo as nm
fn main() raises:
var A = nm.fromstring("[[1, 0, 1], [0, 2, 1], [1, 1, 1]]")
var B = nm.fromstring("[[1, 0, 0], [0, 1, 0], [0, 0, 1]]")
var X = nm.linalg.solve(A, B)
print(X)
The example is also a way to calculate inverse of matrix.
Parameters:
dtype(DType): Data type of the inversed matrix.
Args:
A(NDArray): Non-singular, square, and row-major matrix. The size is m x m.Y(NDArray): Matrix of size m x n.
Returns:
NDArray
Raises
Overload 2¶
Solve AX = Y using LUP decomposition.
Parameters:
dtype(DType)
Args:
A(Matrix)Y(Matrix)
Returns:
Matrix
Raises
solve_lu¶
Solve AX = Y using LU decomposition.
Parameters:
dtype(DType)
Args:
A(Matrix)Y(Matrix)
Returns:
Matrix
Raises