lab.linear_algebra module¶
-
lab.linear_algebra.T¶ Shorthand for transpose.
-
lab.linear_algebra.chol¶ Shorthand for cholesky.
-
lab.linear_algebra.cholesky[source]¶ Compute the Cholesky decomposition.
- Parameters
a (tensor) – Matrix to decompose.
- Returns
Cholesky decomposition.
- Return type
tensor
-
lab.linear_algebra.cholesky_solve[source]¶ Solve the linear system a x = b given the Cholesky factorisation of a.
- Parameters
a (tensor) – Cholesky factorisation of a.
b (tensor) – RHS b.
- Returns
Solution x.
- Return type
tensor
-
lab.linear_algebra.cholsolve¶ Shorthand for cholesky_solve.
-
lab.linear_algebra.det[source]¶ Compute the determinant of a.
- Parameters
a (tensor) – Matrix to compute determinant of.
- Returns
Determinant of a
- Return type
scalar
-
lab.linear_algebra.dot¶ Shorthand for matmul.
-
lab.linear_algebra.epsilon= 1e-12¶ Magnitude of diagonal to regularise matrices with.
-
lab.linear_algebra.ew_dists[source]¶ Compute the Euclidean norm of the element-wise differences between two matrices where rows correspond to elements and columns to features.
- Parameters
a (matrix) – First matrix.
b (matrix, optional) – Second matrix. Defaults to a.
- Returns
- Euclidean norm of the element-wise differences between the
elements of a and b.
- Return type
matrix
-
lab.linear_algebra.ew_dists2[source]¶ Compute the square the Euclidean norm of the element-wise differences between two matrices where rows correspond to elements and columns to features.
- Parameters
a (matrix) – First matrix.
b (matrix, optional) – Second matrix. Defaults to a.
- Returns
- Square of the Euclidean norm of the element-wise differences
between the elements of a and b.
- Return type
matrix
-
lab.linear_algebra.ew_sums[source]¶ Compute the Euclidean norm of the element-wise sums between two matrices where rows correspond to elements and columns to features.
- Parameters
a (matrix) – First matrix.
b (matrix, optional) – Second matrix. Defaults to a.
- Returns
- Euclidean norm of the element-wise sums between the
elements of a and b.
- Return type
matrix
-
lab.linear_algebra.ew_sums2[source]¶ Compute the square the Euclidean norm of the element-wise sums between two matrices where rows correspond to elements and columns to features.
- Parameters
a (matrix) – First matrix.
b (matrix, optional) – Second matrix. Defaults to a.
- Returns
- Square of the Euclidean norm of the element-wise sums
between the elements of a and b.
- Return type
matrix
-
lab.linear_algebra.expm[source]¶ Compute the matrix exponential of a.
- Parameters
a (tensor) – Matrix to matrix exponential of.
- Returns
Matrix exponential of a
- Return type
scalar
-
lab.linear_algebra.inv[source]¶ Compute the inverse of a.
- Parameters
a (tensor) – Matrix to compute inverse of.
- Returns
Inverse of a.
- Return type
tensor
-
lab.linear_algebra.kron[source]¶ Kronecker product.
- Parameters
a (tensor) – First matrix.
b (tensor) – Second matrix.
- Returns
Kronecker product of a and b.
- Return type
tensor
-
lab.linear_algebra.logdet[source]¶ Compute the log-determinant of a.
- Parameters
a (tensor) – Matrix to compute log-determinant of.
- Returns
Log-determinant of a
- Return type
scalar
-
lab.linear_algebra.logm[source]¶ Compute the matrix logarithm of a.
- Parameters
a (tensor) – Matrix to matrix logarithm of.
- Returns
Matrix logarithm of a
- Return type
scalar
-
lab.linear_algebra.matmul[source]¶ Matrix multiplication.
- Parameters
a (tensor) – First matrix.
b (tensor) – Second matrix.
tr_a (bool, optional) – Transpose first matrix. Defaults to False.
tr_b (bool, optional) – Transpose second matrix. Defaults to False.
- Returns
Matrix product of a and b.
- Return type
tensor
-
lab.linear_algebra.mm¶ Shorthand for matmul.
-
lab.linear_algebra.outer[source]¶ Compute the outer product between two vectors or matrices.
- Parameters
a (tensor) – First tensor.
b (tensor) – Second tensor.
- Returns
Outer product of a and b.
- Return type
tensor
-
lab.linear_algebra.pw_dists[source]¶ Compute the Euclidean norm of the pairwise differences between two matrices where rows correspond to elements and columns to features.
- Parameters
a (matrix) – First matrix.
b (matrix, optional) – Second matrix. Defaults to a.
- Returns
- Euclidean norm of the pairwise differences between the
elements of a and b.
- Return type
matrix
-
lab.linear_algebra.pw_dists2[source]¶ Compute the square the Euclidean norm of the pairwise differences between two matrices where rows correspond to elements and columns to features.
- Parameters
a (matrix) – First matrix.
b (matrix, optional) – Second matrix. Defaults to a.
- Returns
- Square of the Euclidean norm of the pairwise differences
between the elements of a and b.
- Return type
matrix
-
lab.linear_algebra.pw_sums[source]¶ Compute the Euclidean norm of the pairwise sums between two matrices where rows correspond to elements and columns to features.
- Parameters
a (matrix) – First matrix.
b (matrix, optional) – Second matrix. Defaults to a.
- Returns
- Euclidean norm of the pairwise sums between the
elements of a and b.
- Return type
matrix
-
lab.linear_algebra.pw_sums2[source]¶ Compute the square the Euclidean norm of the pairwise sums between two matrices where rows correspond to elements and columns to features.
- Parameters
a (matrix) – First matrix.
b (matrix, optional) – Second matrix. Defaults to a.
- Returns
- Square of the Euclidean norm of the pairwise sums
between the elements of a and b.
- Return type
matrix
-
lab.linear_algebra.reg[source]¶ Add a diagonal to a matrix.
- Parameters
a (matrix) – Matrix to add a diagonal to.
diag (float, optional) – Magnitude of the diagonal to add. Defaults to .linear_algebra.epsilon.
clip (bool, optional) – Let diag be at least .linear_algebra.epsilon. Defaults to True.
- Returns
Regularised version of a.
- Return type
matrix
-
lab.linear_algebra.solve[source]¶ Solve the linear system a x = b.
- Parameters
a (tensor) – LHS a.
b (tensor) – RHS b.
- Returns
Solution x.
- Return type
tensor
-
lab.linear_algebra.svd[source]¶ Compute the singular value decomposition.
Note
PyTorch does not allow batch computation.
- Parameters
a (tensor) – Matrix to decompose.
compute_uv (bool, optional) – Also compute U and V. Defaults to True.
- Returns
(U, S, V) is compute_uv is True and just S otherwise.
- Return type
tuple
-
lab.linear_algebra.t¶ Shorthand for transpose.
-
lab.linear_algebra.toeplitz_solve[source]¶ Solve the linear system toep(a, b) x = c where toep(a, b) is a Toeplitz matrix.
- Parameters
a (tensor) – First column of the Toeplitz matrix.
b (tensor, optional) – Except for the first element, first row of the Toeplitz matrix. Defaults to a[1:].
c (tensor) – RHS c.
- Returns
Solution x.
- Return type
tensor
-
lab.linear_algebra.toepsolve¶ Shorthand for toeplitz_solve.
-
lab.linear_algebra.trace[source]¶ Compute the trace of a tensor.
- Parameters
a (tensor) – Tensor to compute trace of.
axis1 (int, optional) – First dimension to compute trace over. Defaults to 0.
axis2 (int, optional) – Second dimension to compute trace over. Defaults to 1.
- Returns
Trace.
- Return type
tensor
-
lab.linear_algebra.transpose[source]¶ Transpose a matrix.
- Parameters
a (tensor) – Matrix to transpose.
perm (list[int] or tuple[int], optional) – Permutation. Defaults to switching the last two axes.
- Returns
Transposition of a.
- Return type
tensor
-
lab.linear_algebra.triangular_solve[source]¶ Solve the linear system a x = b where a is triangular.
- Parameters
a (tensor) – Triangular matrix a.
b (tensor) – RHS b.
lower_a (bool, optional) – Indicate that a is lower triangular instead of upper triangular. Defaults to True.
- Returns
Solution x.
- Return type
tensor
-
lab.linear_algebra.trisolve¶ Shorthand for triangular_solve.